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

@ -25,3 +25,4 @@ big warning shouting at them, I feel like showing off. :^)
- [tinted-theming](https://github.com/tinted-theming) - used their base16 - [tinted-theming](https://github.com/tinted-theming) - used their base16
stuff when needed. stuff when needed.
- [fdncred](https://github.com/fdncred) - made the `ls` alias i use - [fdncred](https://github.com/fdncred) - made the `ls` alias i use
- [diniamo](https://github.com/diniamo) - used his idea of importing a custom lib into nixos

View file

@ -3,10 +3,10 @@
self, self,
... ...
}: let }: let
inherit (self) lib; inherit (self.lib) mkHosts;
in { in {
flake = { flake = {
nixosConfigurations = builtins.mapAttrs (n: v: lib.mkHost (v // {host = n;})) { nixosConfigurations = mkHosts {
solterra = { solterra = {
system = "x86_64-linux"; system = "x86_64-linux";
extraModules = [ extraModules = [

View file

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