summary refs log tree commit diff stats
path: root/hosts/default.nix
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-12-25 18:25:51 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-12-25 18:25:51 +0100
commitd9ab6c7ea59d29af3ae8c29c7367fe0e8808f5db (patch)
tree4076dca44feeb7fccf90af3f9c9cc6e73b845c6f /hosts/default.nix
parentfix(treewide): Add constant uids and gids to each user and group (diff)
downloadnixos-server-d9ab6c7ea59d29af3ae8c29c7367fe0e8808f5db.tar.gz
nixos-server-d9ab6c7ea59d29af3ae8c29c7367fe0e8808f5db.zip
refactor(hosts): Use a `by-name` structure and construct all host depended values
This allows us to outsource the host-handling from the `flake.nix` file.
Diffstat (limited to 'hosts/default.nix')
-rw-r--r--hosts/default.nix41
1 files changed, 41 insertions, 0 deletions
diff --git a/hosts/default.nix b/hosts/default.nix
new file mode 100644
index 0000000..f53ee35
--- /dev/null
+++ b/hosts/default.nix
@@ -0,0 +1,41 @@
+{
+  pkgs,
+  nixLib,
+  nixpkgs,
+  specialArgs,
+  extraModules,
+  deployPackage,
+}: let
+  hostnames = builtins.fromTOML (builtins.readFile ./host-names.toml);
+
+  hosts = nixLib.mkByName {
+    useShards = false;
+    baseDirectory = ./by-name;
+    fileName = "configuration.nix";
+    finalizeFunction = name: value: value;
+  };
+
+  mkNixosConfiguration = _: value:
+    nixpkgs.lib.nixosSystem {
+      system = "x86_64-linux";
+      inherit specialArgs;
+      modules =
+        extraModules
+        ++ [
+          ../modules
+          value
+        ];
+    };
+  nixosConfigurations = builtins.mapAttrs mkNixosConfiguration hosts;
+
+  mkDeploy = name: _: {
+    hostname = hostnames."${name}";
+    profiles.system = {
+      user = "root";
+      path = deployPackage.lib.activate.nixos nixosConfigurations."${name}";
+    };
+  };
+  deploy = {nodes = builtins.mapAttrs mkDeploy hosts;};
+in {
+  inherit nixosConfigurations deploy;
+}