79 lines
2.5 KiB
Nix
79 lines
2.5 KiB
Nix
|
{ inputs, secrets }:
|
||
|
{
|
||
|
createNixosSystem = {
|
||
|
system ? "x86_64-linux",
|
||
|
entrypoint
|
||
|
}: inputs.nixpkgs.lib.nixosSystem {
|
||
|
inherit system;
|
||
|
|
||
|
specialArgs = {
|
||
|
inherit inputs system secrets;
|
||
|
};
|
||
|
|
||
|
modules = [ entrypoint ];
|
||
|
};
|
||
|
|
||
|
createColmenaHive = {
|
||
|
defaultSystem ? "x86_64-linux",
|
||
|
hostConfigs ? []
|
||
|
}: {
|
||
|
# Set meta options for the colmena hive
|
||
|
meta = {
|
||
|
# Standard options
|
||
|
allowApplyAll = false;
|
||
|
# Defaults for nodes
|
||
|
nixpkgs = import inputs.nixpkgs { system = defaultSystem; };
|
||
|
specialArgs = {
|
||
|
inherit inputs secrets;
|
||
|
system = defaultSystem;
|
||
|
};
|
||
|
# Overrides for individual nodes
|
||
|
nodeNixpkgs = (
|
||
|
builtins.foldl'
|
||
|
(acc: cur:
|
||
|
acc // {
|
||
|
${cur.name} = import inputs.nixpkgs { system = cur.system; };
|
||
|
}
|
||
|
)
|
||
|
{}
|
||
|
(builtins.filter
|
||
|
(c: builtins.hasAttr "system" c && c.system != defaultSystem)
|
||
|
hostConfigs)
|
||
|
);
|
||
|
nodeSpecialArgs = (
|
||
|
builtins.foldl'
|
||
|
(acc: cur:
|
||
|
acc // {
|
||
|
${cur.name} = {
|
||
|
inherit inputs secrets;
|
||
|
system = cur.system;
|
||
|
};
|
||
|
}
|
||
|
)
|
||
|
{}
|
||
|
(builtins.filter
|
||
|
(c: builtins.hasAttr "system" c && c.system != defaultSystem)
|
||
|
hostConfigs)
|
||
|
);
|
||
|
};
|
||
|
} // (
|
||
|
# Add all of the hosts
|
||
|
builtins.foldl'
|
||
|
(acc: cur:
|
||
|
acc // {
|
||
|
${cur.name} = { ... }: {
|
||
|
deployment = {
|
||
|
replaceUnknownProfiles = false;
|
||
|
targetUser = if (builtins.hasAttr "sshUser" cur) then cur.sshUser else "root";
|
||
|
targetHost = if (builtins.hasAttr "sshHost" cur) then cur.sshHost else cur.name;
|
||
|
targetPort = if (builtins.hasAttr "sshPort" cur) then cur.sshPort else 22;
|
||
|
};
|
||
|
|
||
|
imports = [ cur.entrypoint ];
|
||
|
};
|
||
|
}
|
||
|
)
|
||
|
{}
|
||
|
hostConfigs
|
||
|
);
|
||
|
}
|