nixos/builders.nix

77 lines
2.1 KiB
Nix
Raw Normal View History

2024-08-10 11:02:58 -07:00
{ nixpkgs, self, ... }@inputs:
let
2024-08-19 05:55:29 -07:00
makePkgs = system: (import nixpkgs {
inherit system;
config.allowUnfree = true;
2024-09-11 17:34:57 -07:00
overlays = [
self.overlays.default
inputs.niri.overlays.niri
];
2024-08-19 05:55:29 -07:00
});
2024-08-22 00:17:55 -07:00
lib = nixpkgs.lib.extend (import ./lib);
2024-08-19 06:21:38 -07:00
2024-08-01 00:46:04 -07:00
inherit (inputs.home-manager.lib) homeManagerConfiguration;
2024-08-21 23:48:39 -07:00
inherit (lib) nixosSystem;
2024-08-01 00:46:04 -07:00
inherit (lib.strings) optionalString;
inherit (lib.attrsets) nameValuePair;
in
rec {
toPartialNixosConfig =
2024-08-22 00:03:54 -07:00
{ hostname, system ? "x86_64-linux" }:
2024-08-01 00:46:04 -07:00
nameValuePair
hostname
(nixosSystem rec {
2024-08-19 05:55:29 -07:00
pkgs = makePkgs system;
2024-08-19 06:21:38 -07:00
specialArgs = { inherit inputs self; };
2024-08-19 05:55:29 -07:00
modules = [
2024-08-22 00:17:55 -07:00
./hosts/${hostname}/hardware-configuration.nix
./hosts/${hostname}/configuration.nix
inputs.home-manager.nixosModules.default
2024-10-02 07:07:25 -07:00
inputs.chaotic.nixosModules.default
2024-09-11 17:34:57 -07:00
inputs.niri.nixosModules.niri
2024-09-17 22:16:08 -07:00
inputs.lix-module.nixosModules.default
{
home-manager.extraSpecialArgs = {
inherit inputs self pkgs;
lib = pkgs.lib.extend (_: _: inputs.home-manager.lib);
};
}
];
2024-08-01 00:46:04 -07:00
});
compileSystems =
systems:
lib.right
builtins.listToAttrs
(map toPartialNixosConfig)
systems;
2024-07-21 14:19:02 -07:00
toPartialHomeManagerConfig =
2024-08-22 00:03:54 -07:00
{ user, system ? "x86_64-linux", hostname ? "", configHostname ? "" }:
2024-07-21 14:19:02 -07:00
let
configHost = if builtins.stringLength configHostname > 0 then configHostname else hostname;
2024-08-01 00:46:04 -07:00
hostStr = optionalString (builtins.stringLength hostname > 0) "@${hostname}";
2024-07-21 14:19:02 -07:00
in
2024-07-22 00:05:45 -07:00
assert lib.assertMsg (builtins.stringLength configHost > 0) "either configHostname or hostname need to exist";
2024-08-01 00:46:04 -07:00
nameValuePair
"${user}${hostStr}"
(homeManagerConfiguration {
2024-08-19 05:55:29 -07:00
pkgs = makePkgs system;
2024-08-19 06:21:38 -07:00
extraSpecialArgs = { inherit inputs self; };
2024-07-21 14:19:02 -07:00
modules = [
2024-10-02 07:07:25 -07:00
inputs.chaotic.homeManagerModules.default
2024-08-22 00:17:55 -07:00
./hosts/${configHost}/home.nix
2024-07-21 14:19:02 -07:00
];
2024-08-01 00:46:04 -07:00
});
2024-07-21 14:19:02 -07:00
compileHomes =
systems:
lib.right
builtins.listToAttrs
(map toPartialHomeManagerConfig)
systems;
}