feat: use pipes to create homeConfigurations

This commit is contained in:
Iain Learmonth 2025-07-07 14:36:56 +01:00
parent de5a9787f6
commit 671533f47c
2 changed files with 57 additions and 28 deletions

View file

@ -36,11 +36,6 @@
sops-nix, sops-nix,
}@inputs: }@inputs:
let let
homeRoles = [
"desktop"
"minimal"
"server"
];
outputs = inputs.self; outputs = inputs.self;
overlays = [ overlays = [
apple-silicon.overlays.apple-silicon-overlay apple-silicon.overlays.apple-silicon-overlay
@ -74,23 +69,35 @@
}; };
}; };
homeManagerModules = import ./modules/home-manager; homeManagerModules = import ./modules/home-manager;
homeConfigurations = nixpkgs.lib.foldl' (c: e: homeConfigurations =
c // { {
"irl-${e.role}-${e.system}" = home-manager.lib.homeManagerConfiguration { role = [
pkgs = import nixpkgs { "desktop"
inherit overlays; "minimal"
system = e.system; "server"
}; ];
extraSpecialArgs = { system = supportedSystems;
inherit outputs;
};
modules = [
./home-manager/irl.nix
{ role = "${e.role}"; }
];
};
} }
) { } (nixpkgs.lib.cartesianProduct { role = homeRoles; system = supportedSystems; }); |> nixpkgs.lib.cartesianProduct
|> nixpkgs.lib.foldl' (
c: e:
c
// {
"irl-${e.role}-${e.system}" = home-manager.lib.homeManagerConfiguration {
pkgs = import nixpkgs {
inherit overlays;
system = e.system;
};
extraSpecialArgs = {
inherit outputs;
};
modules = [
./home-manager/irl.nix
{ role = "${e.role}"; }
];
};
}
) { };
} }
// flake-utils.lib.eachSystem supportedSystems (system: { // flake-utils.lib.eachSystem supportedSystems (system: {
formatter = nixpkgs.legacyPackages.${system}.nixfmt-tree; formatter = nixpkgs.legacyPackages.${system}.nixfmt-tree;

View file

@ -11,26 +11,48 @@
options.role = lib.mkOption { options.role = lib.mkOption {
description = "Home role to set up"; description = "Home role to set up";
default = "minimal"; default = "minimal";
type = with lib.types; enum ["desktop" "minimal" "server"]; type =
with lib.types;
enum [
"desktop"
"minimal"
"server"
];
}; };
config = { config = {
feature.cli.enable = builtins.elem config.role ["desktop" "minimal" "server"]; feature.cli.enable = builtins.elem config.role [
"desktop"
"minimal"
"server"
];
feature.firefox.enable = config.role == "desktop"; feature.firefox.enable = config.role == "desktop";
feature.git.enable = builtins.elem config.role ["desktop" "server"]; feature.git.enable = builtins.elem config.role [
"desktop"
"server"
];
feature.ops.enable = config.role == "desktop"; feature.ops.enable = config.role == "desktop";
feature.tmux.enable = builtins.elem config.role ["desktop" "server"]; feature.tmux.enable = builtins.elem config.role [
feature.vim.enable = builtins.elem config.role ["desktop" "minimal" "server"]; "desktop"
"server"
];
feature.vim.enable = builtins.elem config.role [
"desktop"
"minimal"
"server"
];
home.username = "irl"; home.username = "irl";
home.homeDirectory = home.homeDirectory =
if lib.strings.hasSuffix "darwin" pkgs.system then "/Users/irl" else "/home/irl"; if lib.strings.hasSuffix "darwin" pkgs.system then "/Users/irl" else "/home/irl";
home.file.".config/nix/nix.conf".text = ''
experimental-features = nix-command flakes pipe-operators
'';
home.packages = with pkgs; [ home.packages = with pkgs; [
neofetch neofetch
]; ];
home.shellAliases = { home.shellAliases = {
hms = hms = "home-manager switch --flake ~/.config/nix-configs#irl-${config.role}-${pkgs.system}";
"home-manager switch --flake ~/.config/nix-configs#irl-${config.role}-${pkgs.system}";
drs = "sudo darwin-rebuild switch --flake ~/.config/nix-configs"; drs = "sudo darwin-rebuild switch --flake ~/.config/nix-configs";
}; };
home.stateVersion = "25.05"; home.stateVersion = "25.05";