From d51f6f14db38b6780f2b4b9f11ad406aae8e6644 Mon Sep 17 00:00:00 2001 From: William Date: Thu, 19 Feb 2026 08:08:27 -0300 Subject: [PATCH] created mkHost and mkHomeConfiguration --- aspects/constants.nix | 82 +++++++++++++++++++++++++++++++- aspects/hosts/alexandria.nix | 36 +++++--------- aspects/hosts/io.nix | 41 +++++----------- aspects/hosts/rotterdam.nix | 39 +++++---------- aspects/hosts/trantor.nix | 43 ++++++----------- aspects/users/user.nix | 63 ++++++++++++++++++------ aspects/users/user_io.nix | 32 ------------- aspects/users/user_rotterdam.nix | 33 ------------- 8 files changed, 178 insertions(+), 191 deletions(-) delete mode 100644 aspects/users/user_io.nix delete mode 100644 aspects/users/user_rotterdam.nix diff --git a/aspects/constants.nix b/aspects/constants.nix index 7d77098..5a82660 100644 --- a/aspects/constants.nix +++ b/aspects/constants.nix @@ -1,4 +1,9 @@ -{ lib, config, ... }: +{ + inputs, + lib, + config, + ... +}: let # Host submodule type @@ -132,6 +137,81 @@ in local-data = lanData; } ]; + # Generates flake.homeConfigurations + mkHomeConfiguration = + { + user, + hostname, + system ? "x86_64-linux", + stateVersion ? "22.05", + nixpkgs ? inputs.nixpkgs, # override with e.g. inputs.nixpkgs-stable + userModules ? [ ], + overlays ? [ inputs.self.overlays.default ], + homeManagerModules ? with inputs.self.modules.homeManager; [ + base + cli + ], + userDirectory ? "/home/${user}", + }: + inputs.home-manager.lib.homeManagerConfiguration { + pkgs = nixpkgs.legacyPackages.${system}; + + extraSpecialArgs = { + inherit inputs hostname; + }; + + modules = [ + { nixpkgs.overlays = overlays; } + { + home = { + username = user; + homeDirectory = userDirectory; + inherit stateVersion; + }; + } + ((inputs.import-tree.initFilter (p: lib.hasSuffix ".nix" p)) + "/${inputs.self}/aspects/users/_${user}" + ) + ] + ++ homeManagerModules + ++ userModules; + }; + # Generates flake.nixosConfigurations + mkHost = + { + hostname, + system ? "x86_64-linux", + nixpkgs ? inputs.nixpkgs, + overlays ? [ + inputs.agenix.overlays.default + inputs.self.overlays.default + ], + ephemeralRootDev ? null, # pass rootDevice string to enable, e.g. ephemeralephemeralRootDev = "/dev/mapper/cryptroot" + nixosModules ? with inputs.self.modules.nixos; [ + base + cli + user + root + ], + extraModules ? [ ], + }: + nixpkgs.lib.nixosSystem { + inherit system; + specialArgs = { inherit inputs; }; + modules = [ + inputs.agenix.nixosModules.default + { networking.hostName = hostname; } + { nixpkgs.overlays = overlays; } + ((inputs.import-tree.initFilter (p: lib.hasSuffix ".nix" p)) + "${inputs.self}/aspects/hosts/_${hostname}" + ) + ] + ++ (lib.optional (ephemeralRootDev != null) ( + inputs.self.factory.ephemeral { rootDevice = ephemeralRootDev; } + )) + ++ nixosModules + ++ extraModules; + }; }; }; } diff --git a/aspects/hosts/alexandria.nix b/aspects/hosts/alexandria.nix index 55867fa..be5027e 100644 --- a/aspects/hosts/alexandria.nix +++ b/aspects/hosts/alexandria.nix @@ -1,33 +1,19 @@ -{ inputs, lib, ... }: +{ inputs, ... }: + +let + mkHost = inputs.self.lib.mkHost; +in { - flake.nixosConfigurations.alexandria = inputs.nixpkgs-stable.lib.nixosSystem { - system = "x86_64-linux"; - specialArgs = { inherit inputs; }; - modules = [ - inputs.agenix.nixosModules.default - { networking.hostName = "alexandria"; } - { - nixpkgs.overlays = [ - inputs.agenix.overlays.default - inputs.self.overlays.default - ]; - } - ((inputs.import-tree.initFilter (p: lib.hasSuffix ".nix" p)) ./_alexandria) - ] - ++ (with inputs.self.modules.nixos; [ - # system aspects - base - cli + flake.nixosConfigurations.alexandria = mkHost { + hostname = "alexandria"; + nixpkgs = inputs.nixpkgs-stable; + extraModules = with inputs.self.modules.nixos; [ + # base aspects server - - # user aspects - user - root - # other aspects fwupd libvirtd - ]); + ]; }; } diff --git a/aspects/hosts/io.nix b/aspects/hosts/io.nix index 6944555..cf5ecec 100644 --- a/aspects/hosts/io.nix +++ b/aspects/hosts/io.nix @@ -1,34 +1,17 @@ -{ inputs, lib, ... }: +{ inputs, ... }: + +let + mkHost = inputs.self.lib.mkHost; +in { - flake.nixosConfigurations.io = inputs.nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - specialArgs = { inherit inputs; }; - modules = [ - inputs.agenix.nixosModules.default - { networking.hostName = "io"; } - { - nixpkgs.overlays = [ - inputs.agenix.overlays.default - inputs.self.overlays.default - ]; - } - ((inputs.import-tree.initFilter (p: lib.hasSuffix ".nix" p)) ./_io) - (inputs.self.factory.ephemeral { - rootDevice = "/dev/mapper/cryptroot"; - }) - ] - ++ (with inputs.self.modules.nixos; [ - # system aspects - base - cli + flake.nixosConfigurations.io = mkHost { + hostname = "io"; + ephemeralRootDev = "/dev/mapper/cryptroot"; + extraModules = with inputs.self.modules.nixos; [ + # base aspects desktop - - # user aspects - user - root - - # Other aspects + # other aspects ai bluetooth dev @@ -36,6 +19,6 @@ networkmanager niri podman - ]); + ]; }; } diff --git a/aspects/hosts/rotterdam.nix b/aspects/hosts/rotterdam.nix index 1c177e4..f3b6fca 100644 --- a/aspects/hosts/rotterdam.nix +++ b/aspects/hosts/rotterdam.nix @@ -1,34 +1,17 @@ -{ inputs, lib, ... }: +{ inputs, ... }: + +let + mkHost = inputs.self.lib.mkHost; +in { - flake.nixosConfigurations.rotterdam = inputs.nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - specialArgs = { inherit inputs; }; - modules = [ - inputs.agenix.nixosModules.default - { networking.hostName = "rotterdam"; } - { - nixpkgs.overlays = [ - inputs.agenix.overlays.default - inputs.self.overlays.default - ]; - } - ((inputs.import-tree.initFilter (p: lib.hasSuffix ".nix" p)) ./_rotterdam) - (inputs.self.factory.ephemeral { - rootDevice = "/dev/mapper/cryptroot"; - }) - ] - ++ (with inputs.self.modules.nixos; [ - # system aspects - base - cli + flake.nixosConfigurations.rotterdam = mkHost { + hostname = "rotterdam"; + ephemeralRootDev = "/dev/mapper/cryptroot"; + extraModules = with inputs.self.modules.nixos; [ + # base aspects desktop gaming - - # user aspects - user - root - # other aspects ai bluetooth @@ -38,6 +21,6 @@ networkmanager niri podman - ]); + ]; }; } diff --git a/aspects/hosts/trantor.nix b/aspects/hosts/trantor.nix index 076672c..14f9dd7 100644 --- a/aspects/hosts/trantor.nix +++ b/aspects/hosts/trantor.nix @@ -1,31 +1,18 @@ -{ inputs, lib, ... }: -{ - flake.nixosConfigurations.trantor = inputs.nixpkgs-stable.lib.nixosSystem { - system = "aarch64-linux"; - specialArgs = { inherit inputs; }; - modules = [ - inputs.agenix.nixosModules.default - { networking.hostName = "trantor"; } - { - nixpkgs.overlays = [ - inputs.agenix.overlays.default - inputs.self.overlays.default - ]; - } - ((inputs.import-tree.initFilter (p: lib.hasSuffix ".nix" p)) ./_trantor) - (inputs.self.factory.ephemeral { - rootDevice = "/dev/disk/by-id/scsi-360b207ed25d84372a95d1ecf842f8e20-part2"; - }) - ] - ++ (with inputs.self.modules.nixos; [ - # system aspects - base - cli - server +{ inputs, ... }: - # user aspects - user - root - ]); +let + mkHost = inputs.self.lib.mkHost; +in + +{ + flake.nixosConfigurations.trantor = mkHost { + hostname = "trantor"; + system = "aarch64-linux"; + nixpkgs = inputs.nixpkgs-stable; + ephemeralRootDev = "/dev/disk/by-id/scsi-360b207ed25d84372a95d1ecf842f8e20-part2"; + extraModules = with inputs.self.modules.nixos; [ + # base aspects + server + ]; }; } diff --git a/aspects/users/user.nix b/aspects/users/user.nix index e3f8530..86bcddb 100644 --- a/aspects/users/user.nix +++ b/aspects/users/user.nix @@ -1,22 +1,55 @@ -{ ... }: +{ inputs, ... }: + +let + mkHomeConfiguration = inputs.self.lib.mkHomeConfiguration; +in { - flake.modules.nixos.user = - { pkgs, ... }: - { - users.users.user = { - isNormalUser = true; - shell = pkgs.fish; - extraGroups = [ - "networkmanager" - "wheel" + flake = { + modules.nixos.user = + { pkgs, ... }: + { + users.users.user = { + isNormalUser = true; + shell = pkgs.fish; + extraGroups = [ + "networkmanager" + "wheel" + ]; + openssh.authorizedKeys.keys = [ + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICQPkAyy+Du9Omc2WtnUF2TV8jFAF4H6mJi2D4IZ1nzg user@himalia" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO3Y0PVpGfJHonqDS7qoCFhqzUvqGq9I9sax+F9e/5cs user@io" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIA1v3+q3EaruiiStWjubEJWvtejam/r41uoOpCdwJtLL user@rotterdam" + ]; + hashedPassword = "$6$Pj7v/CpstyuWQQV0$cNujVDhfMBdwlGVEnnd8t71.kZPixbo0u25cd.874iaqLTH4V5fa1f98V5zGapjQCz5JyZmsR94xi00sUrntT0"; + }; + }; + homeConfigurations = { + "user@rotterdam" = mkHomeConfiguration { + user = "user"; + hostname = "rotterdam"; + userModules = with inputs.self.modules.homeManager; [ + # system aspects + desktop + gaming + + # other aspects + stylix + niri ]; - openssh.authorizedKeys.keys = [ - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICQPkAyy+Du9Omc2WtnUF2TV8jFAF4H6mJi2D4IZ1nzg user@himalia" - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO3Y0PVpGfJHonqDS7qoCFhqzUvqGq9I9sax+F9e/5cs user@io" - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIA1v3+q3EaruiiStWjubEJWvtejam/r41uoOpCdwJtLL user@rotterdam" + }; + "user@io" = mkHomeConfiguration { + user = "user"; + hostname = "io"; + userModules = with inputs.self.modules.homeManager; [ + # system aspects + desktop + + # other aspects + stylix + niri ]; - hashedPassword = "$6$Pj7v/CpstyuWQQV0$cNujVDhfMBdwlGVEnnd8t71.kZPixbo0u25cd.874iaqLTH4V5fa1f98V5zGapjQCz5JyZmsR94xi00sUrntT0"; }; }; + }; } diff --git a/aspects/users/user_io.nix b/aspects/users/user_io.nix deleted file mode 100644 index a8fa675..0000000 --- a/aspects/users/user_io.nix +++ /dev/null @@ -1,32 +0,0 @@ -{ inputs, lib, ... }: - -{ - flake.homeConfigurations."user@io" = { - pkgs = inputs.nixpkgs.legacyPackages.x86_64-linux; - extraSpecialArgs = { - inherit inputs; - hostname = "io"; - }; - modules = [ - { nixpkgs.overlays = [ inputs.self.overlays.default ]; } - { - home = { - username = "user"; - homeDirectory = "/home/user"; - stateVersion = "22.05"; - }; - } - ((inputs.import-tree.initFilter (p: lib.hasSuffix ".nix" p)) ./_user) - ] - ++ (with inputs.self.modules.homeManager; [ - # system aspects - base - cli - desktop - - # other aspects - stylix - niri - ]); - }; -} diff --git a/aspects/users/user_rotterdam.nix b/aspects/users/user_rotterdam.nix deleted file mode 100644 index 36f512d..0000000 --- a/aspects/users/user_rotterdam.nix +++ /dev/null @@ -1,33 +0,0 @@ -{ inputs, lib, ... }: - -{ - flake.homeConfigurations."user@rotterdam" = { - pkgs = inputs.nixpkgs.legacyPackages.x86_64-linux; - extraSpecialArgs = { - inherit inputs; - hostname = "rotterdam"; - }; - modules = [ - { nixpkgs.overlays = [ inputs.self.overlays.default ]; } - { - home = { - username = "user"; - homeDirectory = "/home/user"; - stateVersion = "22.05"; - }; - } - ((inputs.import-tree.initFilter (p: lib.hasSuffix ".nix" p)) ./_user) - ] - ++ (with inputs.self.modules.homeManager; [ - # system aspects - base - cli - desktop - gaming - - # other aspects - stylix - niri - ]); - }; -}