|
| 1 | +# Edit this configuration file to define what should be installed on |
| 2 | +# your system. Help is available in the configuration.nix(5) man page, on |
| 3 | +# https://search.nixos.org/options and in the NixOS manual (`nixos-help`). |
| 4 | + |
| 5 | +{ |
| 6 | + config, |
| 7 | + inputs, |
| 8 | + pkgs, |
| 9 | + meta, |
| 10 | + ... |
| 11 | +}: |
| 12 | + |
| 13 | +{ |
| 14 | + imports = [ |
| 15 | + ./hardware-configuration.nix |
| 16 | + inputs.sops-nix.nixosModules.sops |
| 17 | + ]; |
| 18 | + |
| 19 | + nix = { |
| 20 | + optimise.automatic = true; |
| 21 | + settings = { |
| 22 | + experimental-features = "nix-command flakes"; |
| 23 | + }; |
| 24 | + gc = { |
| 25 | + automatic = true; |
| 26 | + options = "--delete-older-than 14d"; |
| 27 | + }; |
| 28 | + nixPath = [ "nixpkgs=${inputs.nixpkgs}" ]; # for nix.nix |
| 29 | + }; |
| 30 | + |
| 31 | + nixpkgs = { |
| 32 | + hostPlatform = "x86_64-linux"; |
| 33 | + config.allowUnfree = true; |
| 34 | + }; |
| 35 | + |
| 36 | + # Use the systemd-boot EFI boot loader. |
| 37 | + boot.loader = { |
| 38 | + grub.enable = true; |
| 39 | + grub.device = "/dev/sda"; # Install GRUB to the MBR |
| 40 | + efi.canTouchEfiVariables = false; # Disable EFI settings since you're using legacy boot. |
| 41 | + }; |
| 42 | + |
| 43 | + # Set your time zone. |
| 44 | + time.timeZone = "America/Vancouver"; |
| 45 | + |
| 46 | + # Select internationalisation properties. |
| 47 | + i18n.defaultLocale = "en_US.UTF-8"; |
| 48 | + console = { |
| 49 | + font = "Lat2-Terminus16"; |
| 50 | + keyMap = "us"; |
| 51 | + #useXkbConfig = true; # use xkb.options in tty. |
| 52 | + }; |
| 53 | + |
| 54 | + users.users.${meta.username} = { |
| 55 | + isNormalUser = true; |
| 56 | + extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user. |
| 57 | + packages = with pkgs; [ |
| 58 | + tree |
| 59 | + ]; |
| 60 | + # Created using mkpasswd |
| 61 | + hashedPassword = "$6$NQrAUhx13piyrmgZ$GFNEe2v/1tbRO5M3806EWcsoHifN1GIIzhLz.hsVv8Ug3nKgLzP/PMm6MzAS.XRJwzfpdK28LdMLG9uIRtibn/"; |
| 62 | + openssh.authorizedKeys.keys = [ |
| 63 | + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMCpHZBybBTCsCyW6/Q4OZ07SvUpRUvclc10u25j0B+Q hvandersleyen@gmail.com" |
| 64 | + ]; |
| 65 | + }; |
| 66 | + |
| 67 | + environment.systemPackages = with pkgs; [ |
| 68 | + sops |
| 69 | + git |
| 70 | + vim |
| 71 | + factorio-headless |
| 72 | + iptables |
| 73 | + ]; |
| 74 | + |
| 75 | + sops = { |
| 76 | + defaultSopsFile = ./secrets/secrets.yaml; |
| 77 | + defaultSopsFormat = "yaml"; |
| 78 | + |
| 79 | + age.keyFile = "/home/${meta.username}/.config/sops/age/keys.txt"; |
| 80 | + secrets = { |
| 81 | + "game-password" = { |
| 82 | + owner = meta.username; |
| 83 | + }; |
| 84 | + "token" = { |
| 85 | + owner = meta.username; |
| 86 | + }; |
| 87 | + "admin" = { |
| 88 | + owner = meta.username; |
| 89 | + }; |
| 90 | + }; |
| 91 | + }; |
| 92 | + |
| 93 | + # Enable the OpenSSH daemon. |
| 94 | + services.openssh.enable = true; |
| 95 | + systemd.tmpfiles.rules = [ |
| 96 | + # Copy/Link the save file (use either C or L) |
| 97 | + "C /var/lib/factorio/saves/save1.zip - - - - ${builtins.path { path = ./save1.zip; }}" |
| 98 | + ]; |
| 99 | + services.factorio = { |
| 100 | + bind = "192.168.4.129"; |
| 101 | + enable = true; |
| 102 | + public = true; |
| 103 | + username = builtins.readFile config.sops.secrets."admin".path; |
| 104 | + token = builtins.readFile config.sops.secrets."token".path; |
| 105 | + openFirewall = true; |
| 106 | + stateDirName = "factorio"; |
| 107 | + extraSettingsFile = pkgs.writeText "server-settings.json" ( |
| 108 | + builtins.toJSON { |
| 109 | + game-password = builtins.readFile config.sops.secrets."game-password".path; |
| 110 | + } |
| 111 | + ); |
| 112 | + extraSettings = { |
| 113 | + max_players = 16; |
| 114 | + }; |
| 115 | + autosave-interval = 20; |
| 116 | + # When not present in /var/lib/${config.services.factorio.stateDirName}/saves, a new map with default settings will be generated before starting the service. |
| 117 | + saveName = "save1"; |
| 118 | + game-name = "[NixOs] factorio"; |
| 119 | + description = "Factorio on nixos"; |
| 120 | + admins = [ |
| 121 | + (builtins.readFile config.sops.secrets."admin".path) |
| 122 | + ]; |
| 123 | + }; |
| 124 | + |
| 125 | + # networking |
| 126 | + networking = { |
| 127 | + defaultGateway = "192.168.4.1"; # Point to Proxmox |
| 128 | + nameservers = [ "192.168.1.1" ]; # Ensure DNS resolution |
| 129 | + hostName = meta.hostname; # Define your hostname. |
| 130 | + networkmanager.enable = true; # Easiest to use and most distros use this by default. |
| 131 | + firewall = { |
| 132 | + enable = false; |
| 133 | + allowedUDPPorts = [ 34197 ]; # Explicitly open Factorio port |
| 134 | + allowedTCPPorts = [ 27015 ]; |
| 135 | + }; |
| 136 | + }; |
| 137 | + # Configure network proxy if necessary |
| 138 | + # networking.proxy.default = "http://user:password@proxy:port/"; |
| 139 | + # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain"; |
| 140 | + |
| 141 | + # Copy the NixOS configuration file and link it from the resulting system |
| 142 | + # (/run/current-system/configuration.nix). This is useful in case you |
| 143 | + # accidentally delete configuration.nix. |
| 144 | + # system.copySystemConfiguration = true; |
| 145 | + |
| 146 | + # This option defines the first version of NixOS you have installed on this particular machine, |
| 147 | + # and is used to maintain compatibility with application data (e.g. databases) created on older NixOS versions. |
| 148 | + # |
| 149 | + # Most users should NEVER change this value after the initial install, for any reason, |
| 150 | + # even if you've upgraded your system to a new NixOS release. |
| 151 | + # |
| 152 | + # This value does NOT affect the Nixpkgs version your packages and OS are pulled from, |
| 153 | + # so changing it will NOT upgrade your system. |
| 154 | + # |
| 155 | + # This value being lower than the current NixOS release does NOT mean your system is |
| 156 | + # out of date, out of support, or vulnerable. |
| 157 | + # |
| 158 | + # Do NOT change this value unless you have manually inspected all the changes it would make to your configuration, |
| 159 | + # and migrated your data accordingly. |
| 160 | + # |
| 161 | + # For more information, see `man configuration.nix` or https://nixos.org/manual/nixos/stable/options#opt-system.stateVersion . |
| 162 | + system.stateVersion = "25.05"; # Did you read the comment? |
| 163 | + |
| 164 | +} |
0 commit comments