Modularise some config

This commit is contained in:
Fern Garden 2025-07-16 16:38:31 +08:00
parent fac0e003a7
commit b504700e61
4 changed files with 145 additions and 144 deletions

81
lib/default.nix Normal file
View file

@ -0,0 +1,81 @@
inputs:
with inputs;
with inputs.nixpkgs.lib; {
mergeHosts = lists.foldl' (
a: b: attrsets.recursiveUpdate a b
) {};
mkHost = hostname: {
platform ? "x86_64-linux",
suite,
user ? "fern",
extraModules ? [],
}: let
system = platform;
secrets = builtins.toString inputs.secrets;
pkgs = import nixpkgs {
inherit system;
config = {
allowUnfree = true;
permittedInsecurePackages = [
"dotnet-sdk-6.0.428"
"dotnet-runtime-6.0.36"
];
};
overlays = [
(import ../overlays {inherit inputs system;})
];
};
deployPkgs = import nixpkgs {
inherit system;
overlays = [
deploy-rs.overlays.default
(self: super: {
deploy-rs = {
inherit (pkgs) deploy-rs;
lib = super.deploy-rs.lib;
};
})
];
};
in
{
nixosConfigurations.${hostname} = nixosSystem {
inherit system pkgs;
specialArgs = {
inherit
hostname
platform
suite
user
secrets
; # Inherit variables.
};
modules =
[
nixvim.nixosModules.nixvim
../suites/common.nix
../suites/${suite}.nix
../hosts/${hostname}.nix
]
++ (filesystem.listFilesRecursive ../modules)
++ extraModules;
};
}
// optionalAttrs ((suite == "server")
|| (suite == "vm")
|| (suite == "lxc")) {
deploy.nodes.${hostname} = {
hostname = "${hostname}.local";
profiles.system = {
user = "root";
sshUser = user;
path = deployPkgs.deploy-rs.lib.activate.nixos self.nixosConfigurations.${hostname};
};
};
};
}