refactor(nix): dedupe home-manager wiring across hosts ♻️
Extract the per-host home-manager block (useGlobalPkgs, useUserPackages, backupFileExtension, users.<name> with username/homeDirectory/optional stateVersion/optional imports) into nixos/lib/home-manager-user.nix. Each flake-module now imports it with its per-host parameters, removing ~40 lines of boilerplate across the four hosts.
This commit is contained in:
parent
00ab64d83c
commit
c69c7c9b11
5 changed files with 55 additions and 44 deletions
|
|
@ -10,21 +10,12 @@
|
||||||
../hosts/daniel-macbook-air.nix
|
../hosts/daniel-macbook-air.nix
|
||||||
../fish.nix
|
../fish.nix
|
||||||
|
|
||||||
# Home Manager on macOS
|
|
||||||
inputs.home-manager.darwinModules.home-manager
|
inputs.home-manager.darwinModules.home-manager
|
||||||
({ lib, ... }: {
|
(import ../lib/home-manager-user.nix {
|
||||||
home-manager.useGlobalPkgs = true;
|
lib = inputs.nixpkgs.lib;
|
||||||
home-manager.useUserPackages = true;
|
user = "danny";
|
||||||
# Automatically backup files before home-manager overwrites them
|
homeDirectory = "/Users/danny";
|
||||||
home-manager.backupFileExtension = "backup";
|
userImports = [ ../home/danny/home.nix ];
|
||||||
home-manager.users.danny = { ... }: {
|
|
||||||
# Force an absolute path even if another module sets a bad value.
|
|
||||||
home.username = "danny";
|
|
||||||
home.homeDirectory = lib.mkForce "/Users/danny";
|
|
||||||
imports = [
|
|
||||||
../home/danny/home.nix
|
|
||||||
];
|
|
||||||
};
|
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -5,17 +5,12 @@
|
||||||
inputs.nix-openclaw.nixosModules.openclaw-gateway
|
inputs.nix-openclaw.nixosModules.openclaw-gateway
|
||||||
../hosts/phantom-ship.nix
|
../hosts/phantom-ship.nix
|
||||||
|
|
||||||
# Home Manager on NixOS
|
|
||||||
inputs.home-manager.nixosModules.home-manager
|
inputs.home-manager.nixosModules.home-manager
|
||||||
({ lib, ... }: {
|
(import ../lib/home-manager-user.nix {
|
||||||
home-manager.useGlobalPkgs = true;
|
lib = inputs.nixpkgs.lib;
|
||||||
home-manager.useUserPackages = true;
|
user = "danny";
|
||||||
home-manager.backupFileExtension = "backup";
|
homeDirectory = "/home/danny";
|
||||||
home-manager.users.danny = { ... }: {
|
stateVersion = "25.11";
|
||||||
home.username = "danny";
|
|
||||||
home.homeDirectory = lib.mkForce "/home/danny";
|
|
||||||
home.stateVersion = "25.11";
|
|
||||||
};
|
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,12 @@
|
||||||
modules = [
|
modules = [
|
||||||
../hosts/sunken-ship.nix
|
../hosts/sunken-ship.nix
|
||||||
|
|
||||||
# Home Manager on NixOS
|
|
||||||
inputs.home-manager.nixosModules.home-manager
|
inputs.home-manager.nixosModules.home-manager
|
||||||
({ lib, ... }: {
|
(import ../lib/home-manager-user.nix {
|
||||||
home-manager.useGlobalPkgs = true;
|
lib = inputs.nixpkgs.lib;
|
||||||
home-manager.useUserPackages = true;
|
user = "danny";
|
||||||
home-manager.backupFileExtension = "backup";
|
homeDirectory = "/home/danny";
|
||||||
home-manager.users.danny = { ... }: {
|
stateVersion = "25.11";
|
||||||
home.username = "danny";
|
|
||||||
home.homeDirectory = lib.mkForce "/home/danny";
|
|
||||||
home.stateVersion = "25.11";
|
|
||||||
};
|
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -7,17 +7,12 @@
|
||||||
../hosts/wsl.nix
|
../hosts/wsl.nix
|
||||||
../fish.nix
|
../fish.nix
|
||||||
|
|
||||||
# Home Manager on WSL
|
|
||||||
inputs.home-manager.nixosModules.home-manager
|
inputs.home-manager.nixosModules.home-manager
|
||||||
({ lib, ... }: {
|
(import ../lib/home-manager-user.nix {
|
||||||
home-manager.useGlobalPkgs = true;
|
lib = inputs.nixpkgs.lib;
|
||||||
home-manager.useUserPackages = true;
|
user = "dth";
|
||||||
home-manager.backupFileExtension = "backup";
|
homeDirectory = "/home/dth";
|
||||||
home-manager.users.dth = { ... }: {
|
userImports = [ ../home/danny/home.nix ];
|
||||||
home.username = "dth";
|
|
||||||
home.homeDirectory = lib.mkForce "/home/dth";
|
|
||||||
imports = [ ../home/danny/home.nix ];
|
|
||||||
};
|
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
||||||
35
nixos/lib/home-manager-user.nix
Normal file
35
nixos/lib/home-manager-user.nix
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
# Shared home-manager wiring for NixOS and nix-darwin hosts.
|
||||||
|
#
|
||||||
|
# Usage (from a flake-module):
|
||||||
|
# modules = [
|
||||||
|
# inputs.home-manager.nixosModules.home-manager # or .darwinModules
|
||||||
|
# (import ../lib/home-manager-user.nix {
|
||||||
|
# lib = inputs.nixpkgs.lib;
|
||||||
|
# user = "danny";
|
||||||
|
# homeDirectory = "/home/danny";
|
||||||
|
# stateVersion = "25.11"; # optional
|
||||||
|
# userImports = [ ../home/danny/home.nix ]; # optional
|
||||||
|
# })
|
||||||
|
# ];
|
||||||
|
{ lib
|
||||||
|
, user
|
||||||
|
, homeDirectory
|
||||||
|
, stateVersion ? null
|
||||||
|
, userImports ? [ ]
|
||||||
|
}:
|
||||||
|
{
|
||||||
|
home-manager.useGlobalPkgs = true;
|
||||||
|
home-manager.useUserPackages = true;
|
||||||
|
# Automatically back up files before home-manager overwrites them.
|
||||||
|
home-manager.backupFileExtension = "backup";
|
||||||
|
home-manager.users.${user} = { ... }: {
|
||||||
|
imports = userImports;
|
||||||
|
home = {
|
||||||
|
username = user;
|
||||||
|
# Force an absolute path even if another module sets a bad value.
|
||||||
|
homeDirectory = lib.mkForce homeDirectory;
|
||||||
|
} // lib.optionalAttrs (stateVersion != null) {
|
||||||
|
stateVersion = stateVersion;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue