nixos/lib/builders.nix

59 lines
1.6 KiB
Nix
Raw Normal View History

{ nixpkgs, ... }@inputs:
let
2024-07-21 21:18:23 +00:00
lib = nixpkgs.lib.extend (import ../lib);
2024-08-01 07:46:04 +00:00
inherit (inputs.home-manager.lib) homeManagerConfiguration;
inherit (nixpkgs.lib) nixosSystem;
inherit (lib.strings) optionalString;
inherit (lib.attrsets) nameValuePair;
in
rec {
toPartialNixosConfig =
{ hostname, system }:
2024-08-01 07:46:04 +00:00
nameValuePair
hostname
(nixosSystem {
inherit system;
specialArgs = { inherit inputs lib; };
modules = [
../hosts/${hostname}/hardware-configuration.nix
../hosts/${hostname}/configuration.nix
inputs.home-manager.nixosModules.default
];
2024-08-01 07:46:04 +00:00
});
compileSystems =
systems:
lib.right
builtins.listToAttrs
(map toPartialNixosConfig)
systems;
2024-07-21 21:19:02 +00:00
toPartialHomeManagerConfig =
{ user, system, hostname ? "", configHostname ? "" }:
let
configHost = if builtins.stringLength configHostname > 0 then configHostname else hostname;
2024-08-01 07:46:04 +00:00
hostStr = optionalString (builtins.stringLength hostname > 0) "@${hostname}";
2024-07-21 21:19:02 +00:00
in
2024-07-22 07:05:45 +00:00
assert lib.assertMsg (builtins.stringLength configHost > 0) "either configHostname or hostname need to exist";
2024-08-01 07:46:04 +00:00
nameValuePair
"${user}${hostStr}"
(homeManagerConfiguration {
2024-07-21 21:19:02 +00:00
pkgs = nixpkgs.legacyPackages."${system}";
extraSpecialArgs = {
inherit inputs;
lib = lib.extend (_: _: inputs.home-manager.lib);
};
2024-07-21 21:19:02 +00:00
modules = [
../hosts/${configHost}/home.nix
];
2024-08-01 07:46:04 +00:00
});
2024-07-21 21:19:02 +00:00
compileHomes =
systems:
lib.right
builtins.listToAttrs
(map toPartialHomeManagerConfig)
systems;
}