93 lines
2.9 KiB
Nix
93 lines
2.9 KiB
Nix
{ self, inputs, ... }:
|
|
{
|
|
flake.modules.nixos.rebuild =
|
|
{ config, pkgs, lib, ... }:
|
|
let
|
|
flakeDir = config.rebuild.flakeDir;
|
|
echoCmd = lib.getExe' pkgs.coreutils "echo";
|
|
hostnameCmd = "$(${lib.getExe pkgs.hostname} -s)";
|
|
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.rebuild = {
|
|
flakeDir = lib.mkOption {
|
|
description = "Path to the flake directory.";
|
|
type = lib.types.str;
|
|
default = "/etc/nixos";
|
|
};
|
|
};
|
|
|
|
config = {
|
|
environment.systemPackages = with pkgs; [
|
|
nfs
|
|
(writeShellScriptBin "nfsu" ''
|
|
${lib.getExe nix} flake update --impure --flake ${flakeDir}
|
|
${lib.getExe git} -C ${flakeDir} add ${flakeDir}/flake.lock > /dev/null 2>&1
|
|
${lib.getExe nfs}
|
|
'')
|
|
(writeShellScriptBin "test-build" ''
|
|
if [ -z "$1" ]; then
|
|
HOSTNAME=${hostnameCmd}
|
|
else
|
|
HOSTNAME="$1"
|
|
fi
|
|
${echoCmd} "Testing the evaulation of the nixos config for $HOSTNAME"
|
|
${lib.getExe nix} eval ${flakeDir}#nixosConfigurations.$HOSTNAME.config.system.build.toplevel.drvPath
|
|
'')
|
|
];
|
|
};
|
|
};
|
|
|
|
flake.modules.homeManager.rebuild =
|
|
{ config, pkgs, lib, ... }:
|
|
let
|
|
nixBin = lib.getExe pkgs.nix;
|
|
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
|
|
'');
|
|
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 = {
|
|
home.activation.printFlakeDir = lib.hm.dag.entryAfter ["writeBoundary"] ''
|
|
run ${echoCmd} "Home Manager flake directory: ${flakeDir}"
|
|
'';
|
|
|
|
home.packages = with pkgs; [
|
|
home-manager
|
|
(writeShellScriptBin "flake-parts-check" ''
|
|
cd ${flakeDir}
|
|
${nixBin} run "${flakeDir}#write-flake"
|
|
${nixBin} flake check
|
|
'')
|
|
nhms
|
|
(writeShellScriptBin "nhmu" ''
|
|
${nixBin} flake update --flake ${flakeDir}
|
|
${lib.getExe nhms}
|
|
'')
|
|
];
|
|
};
|
|
};
|
|
}
|