Files
dendritic/modules/nix-tools/rebuild.nix
T
John Lancaster fa787740e9 nixify
2026-03-27 19:16:07 -05:00

76 lines
2.2 KiB
Nix

{ inputs, ... }:
{
flake.modules.homeManager.rebuild =
{ pkgs, lib, config, ... }:
let
flakeDir = config.homeManagerFlakeDir;
echoCmd = lib.getExe' pkgs.coreutils "echo";
hostnameCmd = "$(${lib.getExe pkgs.hostname} -s)";
nhms = (pkgs.writeShellScriptBin "nhms" ''
HOSTNAME=${hostnameCmd}
${echoCmd} "Switching to the $HOSTNAME home-manager profile"
${lib.getExe pkgs.home-manager} switch --impure --flake ${flakeDir}#$HOSTNAME
'');
nfs = (pkgs.writeShellScriptBin "nfs" ''
HOSTNAME=${hostnameCmd}
${echoCmd} "Switching to the $HOSTNAME nixos profile"
sudo ${lib.getExe pkgs.nixos-rebuild} switch --impure --flake ${flakeDir}#$HOSTNAME
'');
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;
in
{
home.activation.printFlakeDir = lib.hm.dag.entryAfter ["writeBoundary"] ''
run ${echoCmd} "Home Manager flake directory: ${flakeDir}"
'';
home.packages = with pkgs; [
home-manager
#
# Flake-Parts checks
#
(writeShellScriptBin "flake-parts-check" ''
cd ${flakeDir}
${nixBin} run "${flakeDir}#write-flake"
${nixBin} flake check
'')
#
# Home-Manager rebuilds
#
nhms
(writeShellScriptBin "nhmu" ''
${nixBin} flake update --flake ${flakeDir}
${lib.getExe nhms}
'')
#
# NixOS rebuilds
#
nfs
(writeShellScriptBin "nfsu" ''
${nixBin} flake update --impure --flake ${flakeDir}
${lib.getExe git} -C ${flakeDir} add ${flakeDir}/flake.lock > /dev/null 2>&1
${lib.getExe nfs}
'')
];
};
};
}