From 37f1e07e742562e82fa13f0fbd83c2450030cdb3 Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Wed, 15 Nov 2023 13:06:59 +0100 Subject: [PATCH] create helpers for creating nixos system and deploy nodes move machine definitions to separate directory --- flake.nix | 58 +++++++++---------- machines/default.nix | 8 +++ .../jefke_host_ed25519-cert.pub | 0 .../jefke_user_ed25519-cert.pub | 0 4 files changed, 34 insertions(+), 32 deletions(-) create mode 100644 machines/default.nix rename jefke_host_ed25519-cert.pub => machines/jefke_host_ed25519-cert.pub (100%) rename jefke_user_ed25519-cert.pub => machines/jefke_user_ed25519-cert.pub (100%) diff --git a/flake.nix b/flake.nix index c5056ad..9b2b797 100644 --- a/flake.nix +++ b/flake.nix @@ -20,14 +20,16 @@ system = "x86_64-linux"; pkgs = nixpkgs.legacyPackages.${system}; pkgs-unstable = nixpkgs-unstable.legacyPackages.${system}; - machines = { - jefke = { - name = "jefke"; - hostname = "jefke.hyp"; - user-cert = builtins.readFile ./jefke_user_ed25519-cert.pub; - host-cert = builtins.readFile ./jefke_host_ed25519-cert.pub; - }; - }; + machines = import ./machines; + mkNixosSystems = systemDef: + nixpkgs.lib.foldlAttrs (acc: name: machine: + acc // { + "${name}" = nixpkgs.lib.nixosSystem (systemDef machine); + }) { } machines; + mkDeployNodes = nodeDef: + nixpkgs.lib.foldlAttrs + (acc: name: machine: acc // { "${name}" = nodeDef machine; }) { } + machines; in { devShells.${system}.default = pkgs.mkShell { packages = [ @@ -40,35 +42,27 @@ # TODO. if uncommented, nix flake check fails # formatter = pkgs.nixfmt; - # TODO create helper - nixosConfigurations = nixpkgs.lib.foldlAttrs (acc: name: machine: - acc // { - "${name}" = nixpkgs.lib.nixosSystem { - inherit system; - specialArgs = { inherit machine; }; - modules = [ - disko.nixosModules.disko - agenix.nixosModules.default - ./configuration.nix - ]; - }; - }) { } machines; + nixosConfigurations = mkNixosSystems (machine: { + inherit system; + specialArgs = { inherit machine; }; + modules = [ + disko.nixosModules.disko + agenix.nixosModules.default + ./configuration.nix + ]; + }); deploy = { sshUser = "root"; user = "root"; - # TODO create helper - nodes = nixpkgs.lib.foldlAttrs (acc: name: machine: - acc // { - "${name}" = { - hostname = machine.hostname; - profiles.hypervisor = { - path = deploy-rs.lib.${system}.activate.nixos - self.nixosConfigurations.${name}; - }; - }; - }) { } machines; + nodes = mkDeployNodes (machine: { + hostname = machine.hostname; + profiles.hypervisor = { + path = deploy-rs.lib.${system}.activate.nixos + self.nixosConfigurations.${machine.name}; + }; + }); }; checks = builtins.mapAttrs diff --git a/machines/default.nix b/machines/default.nix new file mode 100644 index 0000000..c9ebbe4 --- /dev/null +++ b/machines/default.nix @@ -0,0 +1,8 @@ +{ + jefke = { + name = "jefke"; + hostname = "jefke.hyp"; + user-cert = builtins.readFile ./jefke_user_ed25519-cert.pub; + host-cert = builtins.readFile ./jefke_host_ed25519-cert.pub; + }; +} diff --git a/jefke_host_ed25519-cert.pub b/machines/jefke_host_ed25519-cert.pub similarity index 100% rename from jefke_host_ed25519-cert.pub rename to machines/jefke_host_ed25519-cert.pub diff --git a/jefke_user_ed25519-cert.pub b/machines/jefke_user_ed25519-cert.pub similarity index 100% rename from jefke_user_ed25519-cert.pub rename to machines/jefke_user_ed25519-cert.pub