feat(nix): add system module, pass config to lib

This commit introduces a system module for NixOS and Home Manager,
and passes the configuration to the lib file.
This commit is contained in:
Mohammad Rafiq 2025-07-07 07:58:15 +08:00
parent b7358cd825
commit 46cf93f69b
No known key found for this signature in database
4 changed files with 25 additions and 6 deletions

View file

@ -1,9 +1,11 @@
{ lib, ... }: { lib, config, ... }:
let let
inherit (lib.attrsets) concatMapAttrs; cfg = config.flake;
inherit (lib.attrsets) mapAttrs concatMapAttrs;
in in
{ {
flake.lib = { flake.lib = {
flattenAttrs = attrset: concatMapAttrs (_: v: v) attrset; flattenAttrs = attrset: concatMapAttrs (_: v: v) attrset;
forAllUsers = f: mapAttrs f cfg.manifest.users;
}; };
} }

View file

@ -8,7 +8,6 @@ let
}; };
nixpkgs.hostPlatform = "x86_64-linux"; nixpkgs.hostPlatform = "x86_64-linux";
boot.loader.systemd-boot.enable = true; boot.loader.systemd-boot.enable = true;
system.stateVersion = "25.05";
networking = { inherit hostName; }; networking = { inherit hostName; };
}; };
in in

10
nix/modules/system.nix Normal file
View file

@ -0,0 +1,10 @@
{
flake.modules.nixos.default = {
system.stateVersion = "25.11";
};
flake.modules.homeManager.default =
{ osConfig, ... }:
{
home.stateVersion = osConfig.system.stateVersion;
};
}

View file

@ -1,12 +1,13 @@
{ config, lib, ... }: { config, lib, ... }:
let let
inherit (config.flake.lib) flattenAttrs; cfg = config.flake;
inherit (config.flake.lib) forAllUsers flattenAttrs;
inherit (lib.attrsets) filterAttrs; inherit (lib.attrsets) filterAttrs;
owner = flattenAttrs (filterAttrs (_: v: (v.primary or false)) config.flake.manifest.users); owner = flattenAttrs (filterAttrs (_: v: (v.primary or false)) cfg.manifest.users);
in in
{ {
flake.modules.nixos.default = flake.modules.nixos.default =
{ pkgs, ... }: { pkgs, config, ... }:
{ {
#TODO: move sudo/security options elsewhere #TODO: move sudo/security options elsewhere
security.sudo.wheelNeedsPassword = false; security.sudo.wheelNeedsPassword = false;
@ -26,5 +27,12 @@ in
openssh.authorizedKeys.keys = [ owner.pubkey ]; openssh.authorizedKeys.keys = [ owner.pubkey ];
}; };
}; };
home-manager.users = forAllUsers (
name: _: {
#TODO: move into nixos/darwin config - should not apply to homeConfigurations
home.username = name;
home.homeDirectory = config.users.users.${name}.home;
}
);
}; };
} }