nix/utils/default.nix

80 lines
2.7 KiB
Nix
Raw Normal View History

2024-12-15 23:36:16 -07:00
{ 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 = {
2024-12-15 23:45:19 -07:00
replaceUnknownProfiles = if (builtins.hasAttr "allowLocal" cur) then cur.allowLocal else false;
2024-12-15 23:36:16 -07:00
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;
2024-12-15 23:45:19 -07:00
allowLocalDeployment = if (builtins.hasAttr "allowLocal" cur) then cur.allowLocal else false;
2024-12-15 23:36:16 -07:00
};
imports = [ cur.entrypoint ];
};
}
)
{}
hostConfigs
);
}