From a5a54a86b8ce582921c8392c28750a1ac898d460 Mon Sep 17 00:00:00 2001 From: Trevor Vallender Date: Sat, 10 Jun 2023 12:57:11 +0100 Subject: [PATCH] Refactor for multiple systems First step in refactoring my Nix setup to work better for configuring multiple machines. Broken things apart into more manageable chunks. --- flake.nix | 26 +++++- system/filesystem.nix | 29 +++++++ ...configuration.nix => ritchie-hardware.nix} | 42 +++------- system/ritchie.nix | 32 ++++++++ ...iguration.nix => shared-configuration.nix} | 36 -------- users/tsv/home.nix | 82 ++----------------- users/tsv/packages.nix | 69 ++++++++++++++++ users/tsv/ritchie.nix | 9 ++ users/tsv/work-packages.nix | 15 ++++ 9 files changed, 194 insertions(+), 146 deletions(-) create mode 100644 system/filesystem.nix rename system/{hardware-configuration.nix => ritchie-hardware.nix} (58%) create mode 100644 system/ritchie.nix rename system/{configuration.nix => shared-configuration.nix} (72%) create mode 100644 users/tsv/packages.nix create mode 100644 users/tsv/ritchie.nix create mode 100644 users/tsv/work-packages.nix diff --git a/flake.nix b/flake.nix index 050c5c8..4c7176c 100644 --- a/flake.nix +++ b/flake.nix @@ -19,13 +19,13 @@ outputs = inputs@{ nixpkgs, home-manager, devenv, hyprland, hyprcontrib, codeium, ... }: { nixosConfigurations = { - ritchie = nixpkgs.lib.nixosSystem { + ritchie = nixpkgs.lib.nixosSystem { # My work machine system = "x86_64-linux"; specialArgs.inputs = inputs; modules = [ - ./system/configuration.nix + ./system/ritchie.nix hyprland.nixosModules.default { programs.hyprland.enable = true; } @@ -34,12 +34,32 @@ home-manager = { useGlobalPkgs = true; useUserPackages = true; - users.tsv = import users/tsv/home.nix; + users.tsv = import users/tsv/ritchie.nix; users.foxsoft = import users/foxsoft/home.nix; }; } ]; }; + thompson = nixpkgs.lib.nixosSystem { # My personal laptop + system = "x86_64-linux"; + + specialArgs.inputs = inputs; + + modules = [ + ./system/thompson.nix + + hyprland.nixosModules.default + { programs.hyprland.enable = true; } + + home-manager.nixosModules.home-manager { + home-manager = { + useGlobalPkgs = true; + useUserPackages = true; + users.tsv = import users/tsv/thompson.nix; + }; + } + ]; + }; }; }; } diff --git a/system/filesystem.nix b/system/filesystem.nix new file mode 100644 index 0000000..ff89020 --- /dev/null +++ b/system/filesystem.nix @@ -0,0 +1,29 @@ +# General filesystem setup used by my main machines. + +{ config, ... }: + +{ + boot.initrd.luks.devices = { + root = { + device = "/dev/disk/by-label/CRYPT"; + preLVM = true; + allowDiscards = true; + }; + }; + + fileSystems."/" = + { device = "/dev/disk/by-label/ROOT"; + fsType = "btrfs"; + }; + + fileSystems."/boot" = + { device = "/dev/disk/by-label/BOOT"; + fsType = "vfat"; + }; + + swapDevices = [ + { + device = "/dev/mapper/vg-swap"; + } + ]; +} diff --git a/system/hardware-configuration.nix b/system/ritchie-hardware.nix similarity index 58% rename from system/hardware-configuration.nix rename to system/ritchie-hardware.nix index 897e942..b5116b3 100644 --- a/system/hardware-configuration.nix +++ b/system/ritchie-hardware.nix @@ -1,6 +1,3 @@ -# Do not modify this file! It was generated by ‘nixos-generate-config’ -# and may be overwritten by future invocations. Please make changes -# to /etc/nixos/configuration.nix instead. { config, lib, pkgs, modulesPath, ... }: { @@ -12,40 +9,25 @@ boot.initrd.kernelModules = [ "dm-snapshot" ]; boot.kernelModules = [ "kvm-intel" ]; boot.extraModulePackages = [ ]; - - boot.initrd.luks.devices = { - root = { - device = "/dev/disk/by-label/CRYPT"; - preLVM = true; - allowDiscards = true; - }; - }; - - fileSystems."/" = - { device = "/dev/disk/by-label/ROOT"; - fsType = "btrfs"; - }; - - fileSystems."/boot" = - { device = "/dev/disk/by-label/BOOT"; - fsType = "vfat"; - }; - - swapDevices = [ - { - device = "/dev/mapper/vg-swap"; - } - ]; - # Enables DHCP on each ethernet and wireless interface. In case of scripted networking # (the default) this is the recommended approach. When using systemd-networkd it's # still possible to use this option, but it's recommended to use it in conjunction # with explicit per-interface declarations with `networking.interfaces..useDHCP`. networking.useDHCP = lib.mkDefault true; - # networking.interfaces.enp3s0.useDHCP = lib.mkDefault true; - # networking.interfaces.wlo1.useDHCP = lib.mkDefault true; nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; powerManagement.cpuFreqGovernor = lib.mkDefault "powersave"; hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + + # NVidia stuff + hardware.nvidia.modesetting.enable = true; + services.xserver.videoDrivers = ["nvidia" ]; + + hardware.opengl.enable = true; + hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.stable; + hardware.nvidia.prime = { + sync.enable = true; + nvidiaBusId = "PCI:1:0:0"; + intelBusId = "PCI:0:2:0"; + }; } diff --git a/system/ritchie.nix b/system/ritchie.nix new file mode 100644 index 0000000..238496c --- /dev/null +++ b/system/ritchie.nix @@ -0,0 +1,32 @@ + +{ config, pkgs, inputs, ... }: + +let + nvidia-offload = pkgs.writeShellScriptBin "nvidia-offload" '' + export __NV_PRIME_RENDER_OFFLOAD=1 + export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0 + export __GLX_VENDOR_LIBRARY_NAME=nvidia + export __VK_LAYER_NV_optimus=NVIDIA_only + exec "$@" + ''; +in +{ + imports = + [ + ./shared-configuration.nix + ./ritchie-hardware.nix + ./filesystem.nix + ]; + + networking.hostName = "ritchie"; + + users.users.foxsoft = { + isNormalUser = true; + extraGroups = [ + "tmux" + ]; + openssh.authorizedKeys.keyFiles = [ + ../users/foxsoft/authorized_keys + ]; + }; +} diff --git a/system/configuration.nix b/system/shared-configuration.nix similarity index 72% rename from system/configuration.nix rename to system/shared-configuration.nix index c736659..250296b 100644 --- a/system/configuration.nix +++ b/system/shared-configuration.nix @@ -1,26 +1,11 @@ { config, pkgs, inputs, ... }: -let - nvidia-offload = pkgs.writeShellScriptBin "nvidia-offload" '' - export __NV_PRIME_RENDER_OFFLOAD=1 - export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0 - export __GLX_VENDOR_LIBRARY_NAME=nvidia - export __VK_LAYER_NV_optimus=NVIDIA_only - exec "$@" - ''; -in { - imports = - [ - ./hardware-configuration.nix - ]; - # Use the systemd-boot EFI boot loader. boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; boot.supportedFilesystems = [ "ntfs" ]; - networking.hostName = "ritchie"; networking.networkmanager.enable = true; i18n.defaultLocale = "en_GB.UTF-8"; @@ -51,16 +36,6 @@ in initialPassword = "password"; }; - users.users.foxsoft = { - isNormalUser = true; - extraGroups = [ - "tmux" - ]; - openssh.authorizedKeys.keyFiles = [ - ../users/foxsoft/authorized_keys - ]; - }; - nix.settings.trusted-users = [ "root" "tsv" ]; nix = { @@ -76,16 +51,6 @@ in services.xserver.enable = true; services.xserver.displayManager.sddm.enable = true; services.xserver.desktopManager.plasma5.enable = true; - hardware.nvidia.modesetting.enable = true; - services.xserver.videoDrivers = ["nvidia" ]; - - hardware.opengl.enable = true; - hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.stable; - hardware.nvidia.prime = { - sync.enable = true; - nvidiaBusId = "PCI:1:0:0"; - intelBusId = "PCI:0:2:0"; - }; hardware.bluetooth.enable = true; @@ -109,7 +74,6 @@ in environment.variables.LC_ALL = "en_GB.UTF-8"; - nixpkgs.config.allowUnfree = true; nixpkgs.overlays = [ diff --git a/users/tsv/home.nix b/users/tsv/home.nix index 03f11ef..73901f9 100644 --- a/users/tsv/home.nix +++ b/users/tsv/home.nix @@ -1,6 +1,11 @@ { config, pkgs, ... }: { + imports = + [ + ./packages.nix + ]; + home.username = "tsv"; home.homeDirectory = "/home/tsv"; @@ -14,83 +19,6 @@ MOZ_ENABLE_WAYLAND = 1; }; - home.packages = with pkgs; [ - _1password-gui - aaxtomp3 - aerc - anki - audible-cli - awscli2 - awsebcli - bitwarden - bitwarden-cli - cachix - calibre - chromium - delta # Nice diffing pager for Git - docker-compose - dunst - feh - firefox - fzf - gcc - git-crypt - gitflow - gnumake - gnupg - gimp - grimblast - gtk4.dev - heroku - htop - hyprland-protocols - hyprland-share-picker - xdg-desktop-portal-hyprland - hyprpaper - imagemagick - kde-gruvbox - kitty - kitty-themes - libreoffice - lshw - microsoft-edge - nerdfonts - pandoc - (pass.withExtensions (exts: [ - exts.pass-import - exts.pass-otp - ])) - pavucontrol - pkg-config - polkit-kde-agent - progress - pspg - quodlibet - qutebrowser - ripgrep - ruby_3_1 - rubyPackages_3_1.dip - rubyPackages_3_1.solargraph - rofi-wayland - slack - spotify - termpdfpy - thunderbird - timg - toot - unzip - usbutils - w3m - waybar - wev - wine - winetricks - wireplumber - wl-clipboard - wlr-randr - zoom-us - ]; - programs.tmux = { enable = true; plugins = with pkgs.tmuxPlugins; [ diff --git a/users/tsv/packages.nix b/users/tsv/packages.nix new file mode 100644 index 0000000..81f52e8 --- /dev/null +++ b/users/tsv/packages.nix @@ -0,0 +1,69 @@ +{ config, pkgs, ... }: + +{ + home.packages = with pkgs; [ + aaxtomp3 + aerc + anki + audible-cli + bitwarden + bitwarden-cli + cachix + calibre + chromium + delta # Nice diffing pager for Git + docker-compose + dunst + feh + firefox + fzf + gcc + git-crypt + gnumake + gnupg + gimp + grimblast + gtk4.dev + htop + hyprland-protocols + hyprland-share-picker + xdg-desktop-portal-hyprland + hyprpaper + imagemagick + kde-gruvbox + kitty + kitty-themes + lshw + nerdfonts + pandoc + (pass.withExtensions (exts: [ + exts.pass-import + exts.pass-otp + ])) + pavucontrol + pkg-config + polkit-kde-agent + progress + pspg + quodlibet + qutebrowser + ripgrep + ruby_3_1 + rubyPackages_3_1.dip + rubyPackages_3_1.solargraph + rofi-wayland + spotify + termpdfpy + thunderbird + timg + toot + unzip + usbutils + w3m + waybar + wev + wireplumber + wl-clipboard + wlr-randr + ]; +} diff --git a/users/tsv/ritchie.nix b/users/tsv/ritchie.nix new file mode 100644 index 0000000..7847649 --- /dev/null +++ b/users/tsv/ritchie.nix @@ -0,0 +1,9 @@ +{ config, pkgs, ... }: + +{ + imports = + [ + ./home.nix + ./work-packages.nix + ]; +} diff --git a/users/tsv/work-packages.nix b/users/tsv/work-packages.nix new file mode 100644 index 0000000..4db883d --- /dev/null +++ b/users/tsv/work-packages.nix @@ -0,0 +1,15 @@ +{ config, pkgs, ... }: + +{ + home.packages = with pkgs; [ + _1password-gui + awscli2 + awsebcli + gitflow + heroku + libreoffice + microsoft-edge + slack + zoom-us + ]; +}