Files
dendritic/modules/nix-tools/rebuild.nix
T
John Lancaster 9a05384ae5 variables
2026-03-27 09:00:35 -05:00

54 lines
1.6 KiB
Nix

{ inputs, ... }:
{
flake.modules.homeManager.rebuild =
{ pkgs, lib, config, ... }:
let
hostnameCmd = "$(${lib.getExe pkgs.hostname} -s)";
in
{
options = {
homeManagerFlakeDir = lib.mkOption {
description = "Path to the home-manager flake directory.";
type = lib.types.str;
default = "${config.xdg.configHome}/home-manager";
};
buildHostname = lib.mkOption {
description = "Hostname for the NixOS configuration to use.";
type = lib.types.str;
default = hostnameCmd;
};
};
config = let
nixBin = lib.getExe pkgs.nix;
flakeDir = config.homeManagerFlakeDir;
in
{
home.activation.printFlakeDir = lib.hm.dag.entryAfter ["writeBoundary"] ''
run echo "Home Manager flake directory: ${flakeDir}"
'';
home.packages = with pkgs; [
home-manager
(writeShellScriptBin "flake-parts-test" ''
echo "Test ${flakeDir}"
'')
(writeShellScriptBin "flake-parts-check" ''
cd ${flakeDir}
${nixBin} run "${flakeDir}#write-flake"
${nixBin} flake check
'')
(writeShellScriptBin "nhms" ''
HOSTNAME=${hostnameCmd}
echo "Switching to the $HOSTNAME profile"
${lib.getExe home-manager} switch --impure --flake ${flakeDir}#$HOSTNAME
'')
(writeShellScriptBin "nhmu" ''
${nixBin} flake update --flake ${flakeDir}
nhms
'')
];
};
};
}