From ba35b789b876e136c7c03a10e8bf31e9a6603d3f Mon Sep 17 00:00:00 2001 From: Sean Buckley Date: Sat, 10 Apr 2021 12:55:17 -0400 Subject: [PATCH] refactor nixos hosts --- flake.nix | 5 +++ hosts/default.nix | 67 ++++++++++++++++++++--------------- hosts/hp/configuration.nix | 30 ++++++++++++++++ hosts/hp/default.nix | 31 ++-------------- hosts/manta/configuration.nix | 29 +++++++++++++++ hosts/manta/default.nix | 30 ++-------------- hosts/neo/configuration.nix | 34 ++++++++++++++++++ hosts/neo/default.nix | 35 ++---------------- hosts/vm/configuration.nix | 7 ++++ hosts/vm/default.nix | 8 ++--- 10 files changed, 156 insertions(+), 120 deletions(-) create mode 100644 hosts/hp/configuration.nix create mode 100644 hosts/manta/configuration.nix create mode 100644 hosts/neo/configuration.nix create mode 100644 hosts/vm/configuration.nix diff --git a/flake.nix b/flake.nix index 25a008c..2216a19 100644 --- a/flake.nix +++ b/flake.nix @@ -8,5 +8,10 @@ config = { sconfig.flakes.enable = true; }; }; nixosConfigurations = import ./hosts { inherit unstable stable2009; }; + + defaultPackage."x86_64-linux" = + with (import unstable { system = "x86_64-linux"; }); + (writeShellScriptBin "x" "cat ${writeText "x" self.nixosConfigurations.test}"); + }; } diff --git a/hosts/default.nix b/hosts/default.nix index e9b5e15..4aed7d9 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -1,34 +1,45 @@ { unstable, stable2009 }: let - commonModules = name: [ - (../.) - (./. + "/${name}") - ({ ... }: { - networking.hostName = name; - sconfig.flakes.enable = true; - sconfig.flakes.rebuildPath = "github:buckley310/nixos-config"; - }) - ]; + hostMetadata = + let + inherit (builtins) readDir concatMap attrNames; + fs = readDir ./.; + hostNames = concatMap (x: if fs.${x} == "directory" then [ x ] else [ ]) (attrNames fs); + in + map + (hn: { name = hn; inherit (import (./. + "/${hn}")) hardware pkgs system; }) + hostNames; - mkStandardSystem = { name, pkgs, system }: pkgs.lib.nixosSystem { - inherit system; - modules = (commonModules name) ++ [ - pkgs.nixosModules.notDetected - ]; - }; - - mkQemuSystem = { name, pkgs, system }: pkgs.lib.nixosSystem { - inherit system; - modules = (commonModules name) ++ [ - (x: { imports = [ "${x.modulesPath}/profiles/qemu-guest.nix" ]; }) - ]; - }; + hardwareModule = { pkgs, hardware }: ( + { + qemu = (x: { imports = [ "${x.modulesPath}/profiles/qemu-guest.nix" ]; }); + physical = pkgs.nixosModules.notDetected; + } + ).${hardware}; in -{ - vm = mkQemuSystem { name = "vm"; system = "x86_64-linux"; pkgs = unstable; }; - hp = mkStandardSystem { name = "hp"; system = "x86_64-linux"; pkgs = unstable; }; - manta = mkStandardSystem { name = "manta"; system = "x86_64-linux"; pkgs = unstable; }; - neo = mkStandardSystem { name = "neo"; system = "x86_64-linux"; pkgs = unstable; }; -} +builtins.listToAttrs ( + map + (h: + let pkgs = { inherit unstable stable2009; }.${h.pkgs}; + in + { + name = h.name; + value = pkgs.lib.nixosSystem { + system = h.system; + modules = [ + (./..) + (./. + "/${h.name}/configuration.nix") + (hardwareModule { inherit pkgs; inherit (h) hardware; }) + ({ ... }: { + networking.hostName = h.name; + sconfig.flakes.enable = true; + sconfig.flakes.rebuildPath = "github:buckley310/nixos-config"; + }) + ]; + }; + } + ) + hostMetadata +) diff --git a/hosts/hp/configuration.nix b/hosts/hp/configuration.nix new file mode 100644 index 0000000..e90dfa1 --- /dev/null +++ b/hosts/hp/configuration.nix @@ -0,0 +1,30 @@ +{ ... }: +{ + services = { + tlp.enable = true; + openssh.enable = true; + }; + + sconfig = { + gnome = true; + profile = "desktop"; + security-tools = true; + }; + + networking = { + search = [ "bck.me" ]; + }; + + boot = { + loader.systemd-boot.enable = true; + loader.efi.canTouchEfiVariables = false; + }; + + fileSystems = { + "/" = { device = "zroot/locker/os"; fsType = "zfs"; }; + "/home" = { device = "zroot/locker/home"; fsType = "zfs"; }; + "/boot" = { device = "/dev/disk/by-partlabel/EFI\\x20system\\x20partition"; fsType = "vfat"; }; + }; + + system.stateVersion = "20.09"; +} diff --git a/hosts/hp/default.nix b/hosts/hp/default.nix index e90dfa1..d00154b 100644 --- a/hosts/hp/default.nix +++ b/hosts/hp/default.nix @@ -1,30 +1,5 @@ -{ ... }: { - services = { - tlp.enable = true; - openssh.enable = true; - }; - - sconfig = { - gnome = true; - profile = "desktop"; - security-tools = true; - }; - - networking = { - search = [ "bck.me" ]; - }; - - boot = { - loader.systemd-boot.enable = true; - loader.efi.canTouchEfiVariables = false; - }; - - fileSystems = { - "/" = { device = "zroot/locker/os"; fsType = "zfs"; }; - "/home" = { device = "zroot/locker/home"; fsType = "zfs"; }; - "/boot" = { device = "/dev/disk/by-partlabel/EFI\\x20system\\x20partition"; fsType = "vfat"; }; - }; - - system.stateVersion = "20.09"; + pkgs = "unstable"; + system = "x86_64-linux"; + hardware = "physical"; } diff --git a/hosts/manta/configuration.nix b/hosts/manta/configuration.nix new file mode 100644 index 0000000..02ff02d --- /dev/null +++ b/hosts/manta/configuration.nix @@ -0,0 +1,29 @@ +{ pkgs, ... }: +{ + environment.systemPackages = [ pkgs.vmware-horizon-client ]; + + services.tlp.enable = true; + services.openssh.enable = true; + + networking.search = [ "bck.me" ]; + + sconfig = { + profile = "desktop"; + gnome = true; + security-tools = true; + }; + + boot = { + loader.systemd-boot.enable = true; + loader.efi.canTouchEfiVariables = true; + initrd.luks.devices.cryptroot = { device = "/dev/disk/by-partlabel/_root"; allowDiscards = true; }; + }; + + fileSystems = { + "/" = { device = "/dev/mapper/cryptroot"; fsType = "btrfs"; options = [ "subvol=/os" "compress=zstd" "discard" ]; }; + "/home" = { device = "/dev/mapper/cryptroot"; fsType = "btrfs"; options = [ "subvol=/home" "compress=zstd" "discard" ]; }; + "/boot" = { device = "/dev/disk/by-partlabel/_esp"; fsType = "vfat"; }; + }; + + system.stateVersion = "20.09"; +} diff --git a/hosts/manta/default.nix b/hosts/manta/default.nix index 02ff02d..d00154b 100644 --- a/hosts/manta/default.nix +++ b/hosts/manta/default.nix @@ -1,29 +1,5 @@ -{ pkgs, ... }: { - environment.systemPackages = [ pkgs.vmware-horizon-client ]; - - services.tlp.enable = true; - services.openssh.enable = true; - - networking.search = [ "bck.me" ]; - - sconfig = { - profile = "desktop"; - gnome = true; - security-tools = true; - }; - - boot = { - loader.systemd-boot.enable = true; - loader.efi.canTouchEfiVariables = true; - initrd.luks.devices.cryptroot = { device = "/dev/disk/by-partlabel/_root"; allowDiscards = true; }; - }; - - fileSystems = { - "/" = { device = "/dev/mapper/cryptroot"; fsType = "btrfs"; options = [ "subvol=/os" "compress=zstd" "discard" ]; }; - "/home" = { device = "/dev/mapper/cryptroot"; fsType = "btrfs"; options = [ "subvol=/home" "compress=zstd" "discard" ]; }; - "/boot" = { device = "/dev/disk/by-partlabel/_esp"; fsType = "vfat"; }; - }; - - system.stateVersion = "20.09"; + pkgs = "unstable"; + system = "x86_64-linux"; + hardware = "physical"; } diff --git a/hosts/neo/configuration.nix b/hosts/neo/configuration.nix new file mode 100644 index 0000000..f55434e --- /dev/null +++ b/hosts/neo/configuration.nix @@ -0,0 +1,34 @@ +{ pkgs, ... }: +{ + sconfig = { + gnome = true; + profile = "desktop"; + security-tools = true; + }; + + networking = { + search = [ "bck.me" ]; + }; + + environment.systemPackages = [ pkgs.vmware-horizon-client ]; + + services = { + pcscd.enable = true; + openssh.enable = true; + zfs.autoSnapshot = { enable = true; monthly = 0; weekly = 0; }; + }; + + boot = { + loader.systemd-boot.enable = true; + loader.efi.canTouchEfiVariables = true; + kernelPackages = pkgs.linuxPackages_5_10; + }; + + fileSystems = { + "/" = { device = "zroot/locker/os"; fsType = "zfs"; }; + "/home" = { device = "zroot/locker/home"; fsType = "zfs"; }; + "/boot" = { device = "/dev/disk/by-partlabel/_esp"; fsType = "vfat"; }; + }; + + system.stateVersion = "20.09"; +} diff --git a/hosts/neo/default.nix b/hosts/neo/default.nix index f55434e..d00154b 100644 --- a/hosts/neo/default.nix +++ b/hosts/neo/default.nix @@ -1,34 +1,5 @@ -{ pkgs, ... }: { - sconfig = { - gnome = true; - profile = "desktop"; - security-tools = true; - }; - - networking = { - search = [ "bck.me" ]; - }; - - environment.systemPackages = [ pkgs.vmware-horizon-client ]; - - services = { - pcscd.enable = true; - openssh.enable = true; - zfs.autoSnapshot = { enable = true; monthly = 0; weekly = 0; }; - }; - - boot = { - loader.systemd-boot.enable = true; - loader.efi.canTouchEfiVariables = true; - kernelPackages = pkgs.linuxPackages_5_10; - }; - - fileSystems = { - "/" = { device = "zroot/locker/os"; fsType = "zfs"; }; - "/home" = { device = "zroot/locker/home"; fsType = "zfs"; }; - "/boot" = { device = "/dev/disk/by-partlabel/_esp"; fsType = "vfat"; }; - }; - - system.stateVersion = "20.09"; + pkgs = "unstable"; + system = "x86_64-linux"; + hardware = "physical"; } diff --git a/hosts/vm/configuration.nix b/hosts/vm/configuration.nix new file mode 100644 index 0000000..da04115 --- /dev/null +++ b/hosts/vm/configuration.nix @@ -0,0 +1,7 @@ +{ ... }: +{ + sconfig.profile = "server"; + boot.loader.grub.device = "/dev/vda"; + fileSystems."/" = { device = "/dev/vda1"; fsType = "ext4"; }; + security.sudo.wheelNeedsPassword = false; +} diff --git a/hosts/vm/default.nix b/hosts/vm/default.nix index da04115..ca5efb2 100644 --- a/hosts/vm/default.nix +++ b/hosts/vm/default.nix @@ -1,7 +1,5 @@ -{ ... }: { - sconfig.profile = "server"; - boot.loader.grub.device = "/dev/vda"; - fileSystems."/" = { device = "/dev/vda1"; fsType = "ext4"; }; - security.sudo.wheelNeedsPassword = false; + pkgs = "unstable"; + system = "x86_64-linux"; + hardware = "qemu"; }