nix/utils/default.nix
2024-12-21 22:33:52 -07:00

91 lines
3 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 = if (builtins.hasAttr "allowLocal" cur) then cur.allowLocal else 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;
allowLocalDeployment = if (builtins.hasAttr "allowLocal" cur) then cur.allowLocal else false;
};
imports = [ cur.entrypoint ];
};
}
)
{}
hostConfigs
);
createDroidSystem = {
system ? "aarch64-linux",
entrypoint
}: inputs.nix-on-droid.lib.nixOnDroidConfiguration {
pkgs = import inputs.nixpkgs { inherit system; };
modules = [ entrypoint ];
extraSpecialArgs = {
inherit inputs system secrets;
};
};
}