|
| 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 |
| 3 | +# and in the NixOS manual (accessible by running `nixos-help`). |
| 4 | + |
| 5 | +{ config, pkgs, ... }: |
| 6 | + |
| 7 | +{ |
| 8 | + |
| 9 | + ############################################################################## |
| 10 | + # Nix |
| 11 | + ############################################################################## |
| 12 | + |
| 13 | + imports = |
| 14 | + [ # Include the results of the hardware scan. |
| 15 | + ./hardware-configuration.nix |
| 16 | + ]; |
| 17 | + |
| 18 | + nix = { |
| 19 | + settings = { |
| 20 | + # Enable flakes and new 'nix' command |
| 21 | + experimental-features = "nix-command flakes"; |
| 22 | + # Deduplicate and optimize nix store |
| 23 | + auto-optimise-store = true; |
| 24 | + }; |
| 25 | + # nix-collect-garbage daily |
| 26 | + gc.automatic = true; |
| 27 | + }; |
| 28 | + |
| 29 | + nixpkgs.config.allowUnfree = true; |
| 30 | + |
| 31 | + # Copy the NixOS configuration file and link it from the resulting system |
| 32 | + # (/run/current-system/configuration.nix). This is useful in case you |
| 33 | + # accidentally delete configuration.nix. |
| 34 | + system.copySystemConfiguration = true; |
| 35 | + |
| 36 | + # Select internationalisation properties. |
| 37 | + i18n = { |
| 38 | + defaultLocale = "en_US.UTF-8"; |
| 39 | + extraLocaleSettings = { |
| 40 | + LC_MESSAGES = "en_US.UTF-8"; |
| 41 | + LC_MEASUREMENT = "en_DK.UTF-8"; |
| 42 | + LC_TIME = "en_CA.UTF-8"; |
| 43 | + }; |
| 44 | + }; |
| 45 | + console = { |
| 46 | + font = "Lat2-Terminus16"; |
| 47 | + keyMap = "colemak"; |
| 48 | + # useXkbConfig = true; # use xkbOptions in tty. |
| 49 | + }; |
| 50 | + |
| 51 | + time.timeZone = "America/New_York"; |
| 52 | + services.chrony.enable = true; |
| 53 | + |
| 54 | + |
| 55 | + # This value determines the NixOS release from which the default |
| 56 | + # settings for stateful data, like file locations and database versions |
| 57 | + # on your system were taken. It's perfectly fine and recommended to leave |
| 58 | + # this value at the release version of the first install of this system. |
| 59 | + # Before changing this value read the documentation for this option |
| 60 | + # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). |
| 61 | + system.stateVersion = "23.05"; # Did you read the comment? |
| 62 | + |
| 63 | + ############################################################################## |
| 64 | + # Boot |
| 65 | + ############################################################################## |
| 66 | + |
| 67 | + # Use EFI boot loader with Grub. |
| 68 | + # https://nixos.org/manual/nixos/stable/index.html#sec-installation-partitioning-UEFI |
| 69 | + boot = { |
| 70 | + supportedFilesystems = [ "vfat" "zfs" ]; |
| 71 | + # zfs.forceImportRoot = true; |
| 72 | + loader = { |
| 73 | + systemd-boot = { |
| 74 | + enable = true; |
| 75 | + # generationsDir.copyKernels = true; |
| 76 | + }; # systemd-boot |
| 77 | + efi = { |
| 78 | + canTouchEfiVariables = true; # must be disabled if efiInstallAsRemovable=true |
| 79 | + #efiSysMountPoint = "/boot/efi"; # using the default /boot for this config |
| 80 | + }; # efi |
| 81 | + }; # loader |
| 82 | + kernelPackages = config.boot.zfs.package.latestCompatibleLinuxPackages; |
| 83 | + initrd = { |
| 84 | + kernelModules = [ "zfs" ]; |
| 85 | + postDeviceCommands = '' |
| 86 | + zpool import -lf rpool |
| 87 | + ''; # postDeviceCommands |
| 88 | + }; # initrd |
| 89 | + }; # boot |
| 90 | + |
| 91 | + |
| 92 | +################################################################################ |
| 93 | +# ZFS |
| 94 | +################################################################################ |
| 95 | + |
| 96 | + # Set the disk’s scheduler to none. ZFS takes this step automatically |
| 97 | + # if it controls the entire disk, but since it doesn't control the /boot |
| 98 | + # partition we must set this explicitly. |
| 99 | + # source: https://grahamc.com/blog/nixos-on-zfs |
| 100 | + boot.kernelParams = [ "elevator=none" ]; |
| 101 | + |
| 102 | + boot.zfs = { |
| 103 | + requestEncryptionCredentials = true; # enable if using ZFS encryption, ZFS will prompt for password during boot |
| 104 | + }; |
| 105 | + |
| 106 | + services.zfs = { |
| 107 | + autoScrub.enable = true; |
| 108 | + autoSnapshot.enable = true; |
| 109 | + }; |
| 110 | + |
| 111 | +################################################################################ |
| 112 | +# Networking |
| 113 | +################################################################################ |
| 114 | + |
| 115 | + networking = { |
| 116 | + hostName = "nix-win-dual-test"; # Any arbitrary hostname. |
| 117 | + networkmanager.enable = true; |
| 118 | + }; |
| 119 | + |
| 120 | +################################################################################ |
| 121 | +# Persisted Artifacts |
| 122 | +################################################################################ |
| 123 | + |
| 124 | + #Erase Your Darlings & Tmpfs as Root: |
| 125 | + # config/secrets/etc to be persisted across tmpfs reboots and rebuilds. setup |
| 126 | + # soft-links from /persist/<loc on root> to their expected location on /<loc on root> |
| 127 | + # https://github.com/barrucadu/nixfiles/blob/master/hosts/nyarlathotep/configuration.nix |
| 128 | + # https://grahamc.com/blog/erase-your-darlings |
| 129 | + # https://elis.nu/blog/2020/05/nixos-tmpfs-as-root/ |
| 130 | + |
| 131 | + environment.etc = { |
| 132 | + |
| 133 | + # /etc/nixos: requires /persist/etc/nixos |
| 134 | + "nixos".source = "/persist/etc/nixos"; |
| 135 | + |
| 136 | + #NetworkManager/system-connections: requires /persist/etc/NetworkManager/system-connections |
| 137 | + "NetworkManager/system-connections".source = "/persist/etc/NetworkManager/system-connections/"; |
| 138 | + |
| 139 | + # machine-id is used by systemd for the journal, if you don't persist this |
| 140 | + # file you won't be able to easily use journalctl to look at journals for |
| 141 | + # previous boots. |
| 142 | + "machine-id".source = "/persist/etc/machine-id"; |
| 143 | + |
| 144 | + # if you want to run an openssh daemon, you may want to store the host keys |
| 145 | + # across reboots. |
| 146 | + "ssh/ssh_host_rsa_key".source = "/persist/etc/ssh/ssh_host_rsa_key"; |
| 147 | + "ssh/ssh_host_rsa_key.pub".source = "/persist/etc/ssh/ssh_host_rsa_key.pub"; |
| 148 | + "ssh/ssh_host_ed25519_key".source = "/persist/etc/ssh/ssh_host_ed25519_key"; |
| 149 | + "ssh/ssh_host_ed25519_key.pub".source = "/persist/etc/ssh/ssh_host_ed25519_key.pub"; |
| 150 | + |
| 151 | + }; |
| 152 | + |
| 153 | + #2. Wireguard: requires /persist/etc/wireguard/ |
| 154 | + networking.wireguard.interfaces.wg0 = { |
| 155 | + generatePrivateKeyFile = true; |
| 156 | + privateKeyFile = "/persist/etc/wireguard/wg0"; |
| 157 | + }; |
| 158 | + |
| 159 | + #3. Bluetooth: requires /persist/var/lib/bluetooth |
| 160 | + #4. ACME certificates: requires /persist/var/lib/acme |
| 161 | + systemd.tmpfiles.rules = [ |
| 162 | + "L /var/lib/bluetooth - - - - /persist/var/lib/bluetooth" |
| 163 | + ]; |
| 164 | + |
| 165 | +################################################################################ |
| 166 | +# GnuPG & SSH |
| 167 | +################################################################################ |
| 168 | + |
| 169 | + # Enable the OpenSSH daemon. |
| 170 | + services.openssh = { |
| 171 | + enable = true; |
| 172 | + settings = { |
| 173 | + PermitRootLogin = "no"; |
| 174 | + PasswordAuthentication = true; |
| 175 | + }; |
| 176 | + hostKeys = |
| 177 | + [ |
| 178 | + { |
| 179 | + path = "/persist/etc/ssh/ssh_host_ed25519_key"; |
| 180 | + type = "ed25519"; |
| 181 | + } |
| 182 | + { |
| 183 | + path = "/persist/etc/ssh/ssh_host_rsa_key"; |
| 184 | + type = "rsa"; |
| 185 | + bits = 4096; |
| 186 | + } |
| 187 | + ]; |
| 188 | + }; |
| 189 | + |
| 190 | + # Enable GnuPG Agent |
| 191 | + programs.gnupg.agent = { |
| 192 | + enable = true; |
| 193 | + enableSSHSupport = true; |
| 194 | + }; |
| 195 | + |
| 196 | +################################################################################ |
| 197 | +# Drivers |
| 198 | +################################################################################ |
| 199 | + |
| 200 | + hardware.opengl = { |
| 201 | + driSupport = true; # install and enable Vulkan: https://nixos.org/manual/nixos/unstable/index.html#sec-gpu-accel |
| 202 | + #extraPackages = [ vaapiIntel libvdpau-va-gl vaapiVdpau intel-ocl ]; # only if using Intel graphics |
| 203 | + }; |
| 204 | + |
| 205 | +################################################################################ |
| 206 | +# Window Managers & Desktop Environment |
| 207 | +################################################################################ |
| 208 | + |
| 209 | + # Enable the X11 windowing system. |
| 210 | + services.xserver = { |
| 211 | + enable = true; |
| 212 | + # Enable the Plasma 5 Desktop Environment. |
| 213 | + displayManager.sddm.enable = true; |
| 214 | + desktopManager.plasma5.enable = true; |
| 215 | + # Configure keymap in X11 |
| 216 | + layout = "us"; |
| 217 | + xkbVariant = "colemak"; |
| 218 | + xkbOptions = "caps:escape"; # map caps to escape. |
| 219 | + # Enable touchpad support (enabled default in most desktopManager). |
| 220 | + libinput.enable = true; |
| 221 | + }; |
| 222 | + |
| 223 | +################################################################################ |
| 224 | +# Print |
| 225 | +################################################################################ |
| 226 | + |
| 227 | + # Enable CUPS to print documents. |
| 228 | + services.printing.enable = true; |
| 229 | + |
| 230 | +################################################################################ |
| 231 | +# Sound |
| 232 | +################################################################################ |
| 233 | + |
| 234 | + # Enable sound. |
| 235 | + sound.enable = true; |
| 236 | + services.pipewire = { |
| 237 | + enable = true; |
| 238 | + pulse.enable = true; |
| 239 | + }; |
| 240 | + |
| 241 | +################################################################################ |
| 242 | +# Users |
| 243 | +################################################################################ |
| 244 | + |
| 245 | + # When using a password file via users.users.<name>.passwordFile, put the |
| 246 | + # passwordFile in the specified location *before* rebooting, or you will be |
| 247 | + # locked out of the system. To create this file, make a single file with only |
| 248 | + # a password hash in it, compatible with `chpasswd -e`. Or you can copy-paste |
| 249 | + # your password hash from `/etc/shadow` if you first built the system with |
| 250 | + # `password=`, `hashedPassword=`, initialPassword-, or initialHashedPassword=. |
| 251 | + # `sudo cat /etc/shadow` will show all hashed user passwords. |
| 252 | + # More info: https://search.nixos.org/options?channel=21.05&show=users.users.%3Cname%3E.passwordFile&query=users.users.%3Cname%3E.passwordFile |
| 253 | + |
| 254 | + users = { |
| 255 | + mutableUsers = false; |
| 256 | + defaultUserShell = "/var/run/current-system/sw/bin/zsh"; |
| 257 | + users = { |
| 258 | + root = { |
| 259 | + # disable root login here, and also when installing nix by running nixos-install --no-root-passwd |
| 260 | + # https://discourse.nixos.org/t/how-to-disable-root-user-account-in-configuration-nix/13235/3 |
| 261 | + hashedPassword = "!"; # disable root logins, nothing hashes to ! |
| 262 | + }; |
| 263 | + test = { |
| 264 | + isNormalUser = true; |
| 265 | + description = "Non-sudo account for testing new config options that could break login. If need sudo for testing, add 'wheel' to extraGroups and rebuild."; |
| 266 | + initialPassword = "password"; |
| 267 | + #passwordFile = "/persist/etc/users/test"; |
| 268 | + extraGroups = [ "networkmanager" ]; |
| 269 | + #openssh.authorizedKeys.keys = [ "${AUTHORIZED_SSH_KEY}" ]; |
| 270 | + }; |
| 271 | + carl = { |
| 272 | + isNormalUser = true; |
| 273 | + description = "Carl"; |
| 274 | + passwordFile = "/persist/etc/users/carl"; |
| 275 | + extraGroups = [ "wheel" "networkmanager" "audio" "dialout" "docker" "dumpcap" ]; |
| 276 | + #openssh.authorizedKeys.keys = [ "${AUTHORIZED_SSH_KEY}" ]; |
| 277 | + }; |
| 278 | + }; |
| 279 | + }; |
| 280 | + |
| 281 | +################################################################################ |
| 282 | +# Applications |
| 283 | +################################################################################ |
| 284 | + |
| 285 | + # List packages installed in system profile. To search, run: |
| 286 | + # $ nix search <packagename> |
| 287 | + environment.systemPackages = with pkgs; [ |
| 288 | + |
| 289 | + # system core (useful for a minimal first install) |
| 290 | + nix-index |
| 291 | + efibootmgr |
| 292 | + parted gparted gptfdisk |
| 293 | + pciutils uutils-coreutils wget |
| 294 | + openssh ssh-copy-id ssh-import-id fail2ban sshguard |
| 295 | + git git-extras |
| 296 | + zsh oh-my-zsh |
| 297 | + firefox irssi |
| 298 | + screen tmux |
| 299 | + vim nano |
| 300 | + htop ncdu |
| 301 | + qdirstat |
| 302 | + ]; |
| 303 | + |
| 304 | +################################################################################ |
| 305 | +# Program Config |
| 306 | +################################################################################ |
| 307 | + |
| 308 | + programs.zsh = { |
| 309 | + enable = true; |
| 310 | + ohMyZsh = { |
| 311 | + enable = true; |
| 312 | + plugins = [ "colored-man-pages" "colorize" "command-not-found" "emacs" "git" "git-extras" "history" "man" "rsync" "safe-paste" "scd" "screen" "systemd" "tmux" "urltools" "vi-mode" "z" "zsh-interactive-cd" ]; |
| 313 | + theme = "juanghurtado"; |
| 314 | + #theme = "jonathan"; |
| 315 | + # themes displaying commit hash: jonathan juanghurtado peepcode simonoff smt sunrise sunaku theunraveler |
| 316 | + # cool themes: linuxonly agnoster blinks crcandy crunch essembeh flazz frisk gozilla itchy gallois eastwood dst clean bureau bira avit nanotech nicoulaj rkj-repos ys darkblood fox |
| 317 | + }; |
| 318 | + }; |
| 319 | + |
| 320 | + programs.kdeconnect.enable = true; |
| 321 | +} |
0 commit comments