refactor(lib): expose lib to nixos as lib'

This commit is contained in:
Artur Manuel 2025-03-05 18:50:30 +00:00
commit f4770f1908
Signed by: amadaluzia
SSH key fingerprint: SHA256:Zwg7gBuZyaG48ucAZneJwltiXu0+tJb7c3lYt9AYlLg
3 changed files with 45 additions and 35 deletions

View file

@ -3,46 +3,55 @@
self,
...
}: {
flake.lib = inputs.nixpkgs.lib.extend (_: _: {
flake.lib = let
inherit (inputs.nixpkgs.lib) nixosSystem;
inherit (builtins) mapAttrs;
mkHost = {
host,
hostname,
system,
extraModules ? [],
extraSpecialArgs ? {},
}:
inputs.nixpkgs.lib.nixosSystem {
nixosSystem {
inherit system;
specialArgs = {inherit inputs self;} // extraSpecialArgs;
modules =
extraModules
++ [
../hosts/${host}
inputs.self.nixosModules.default
({config, ...}: {
config = {
nix = {
settings.extra-experimental-features = [
"nix-command"
"flakes"
];
gc = {
automatic = true;
dates = "weekly";
};
};
nixpkgs.config.allowUnfree = true;
environment.shellAliases = {
rebs = "nixos-rebuild --use-remote-sudo switch --flake .#${host}";
rebt = "nixos-rebuild --use-remote-sudo test --flake .#${host}";
};
networking.hostName = host;
systemd.oomd = {
enableRootSlice = true;
[
../hosts/${hostname}
self.nixosModules.default
{
_module.args = {
lib' = self.lib;
inherit system;
};
nixpkgs = {
inherit system;
config.allowUnfree = true;
};
}
{
networking.hostName = hostname;
nix = {
settings.extra-experimental-features = [
"nix-command"
"flakes"
];
gc = {
automatic = true;
dates = "weekly";
};
};
})
];
specialArgs = {
inherit inputs self;
};
systemd.oomd = {
enableRootSlice = true;
extraConfig = {DefaultMemoryPressureDurationSec = "20s";};
};
}
]
++ extraModules;
};
});
mkHosts = mapAttrs (hostname: args: mkHost (args // {inherit hostname;}));
in {
inherit mkHosts;
};
}