nixos/lib/builders.nix

53 lines
1.4 KiB
Nix

{ nixpkgs, ... }@inputs:
let
lib = nixpkgs.lib.extend (import ../lib);
in
rec {
toPartialNixosConfig =
{ hostname, system }:
{
name = hostname;
value = nixpkgs.lib.nixosSystem {
inherit system;
specialArgs = { inherit inputs lib; };
modules = [
../hosts/${hostname}/hardware-configuration.nix
../hosts/${hostname}/configuration.nix
inputs.home-manager.nixosModules.default
];
};
};
compileSystems =
systems:
lib.right
builtins.listToAttrs
(map toPartialNixosConfig)
systems;
toPartialHomeManagerConfig =
{ user, system, hostname ? "", configHostname ? "" }:
let
configHost = if builtins.stringLength configHostname > 0 then configHostname else hostname;
hostStr = lib.strings.optionalString (builtins.stringLength hostname > 0) "@${hostname}";
in
assert lib.assertMsg (builtins.stringLength configHost > 0) "either configHostname or hostname need to exist";
{
name = "${user}${hostStr}";
value = inputs.home-manager.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages."${system}";
extraSpecialArgs = { inherit inputs lib; };
modules = [
../hosts/${configHost}/home.nix
];
};
};
compileHomes =
systems:
lib.right
builtins.listToAttrs
(map toPartialHomeManagerConfig)
systems;
}