create helpers for creating nixos system and deploy nodes

move machine definitions to separate directory
This commit is contained in:
Pim Kunis 2023-11-15 13:06:59 +01:00
parent 3550a6e8a8
commit 37f1e07e74
4 changed files with 34 additions and 32 deletions

View file

@ -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

8
machines/default.nix Normal file
View file

@ -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;
};
}