writeShellApplication reworks
This commit is contained in:
@@ -6,11 +6,21 @@
|
|||||||
flakeDir = config.rebuild.flakeDir;
|
flakeDir = config.rebuild.flakeDir;
|
||||||
echoCmd = lib.getExe' pkgs.coreutils "echo";
|
echoCmd = lib.getExe' pkgs.coreutils "echo";
|
||||||
hostnameCmd = "$(${lib.getExe pkgs.hostname} -s)";
|
hostnameCmd = "$(${lib.getExe pkgs.hostname} -s)";
|
||||||
nfs = (pkgs.writeShellScriptBin "nfs" ''
|
|
||||||
HOSTNAME=${hostnameCmd}
|
nfs = with pkgs; writeShellApplication {
|
||||||
${echoCmd} "Switching to the $HOSTNAME nixos profile"
|
name = "nfs";
|
||||||
sudo ${lib.getExe pkgs.nixos-rebuild} switch --impure --flake ${flakeDir}#$HOSTNAME
|
runtimeInputs = [ coreutils hostname nh ];
|
||||||
'');
|
text = ''
|
||||||
|
HOSTNAME=$(hostname -s)
|
||||||
|
echo "Switching to the $HOSTNAME nixos profile"
|
||||||
|
sudo nh os switch "$@" ${flakeDir}#$HOSTNAME
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
nfsu = with pkgs; writeShellApplication {
|
||||||
|
name = "nfsu";
|
||||||
|
runtimeInputs = [ nfs pkgs.git ];
|
||||||
|
text = ''nfs --refresh "$@"'';
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.rebuild = {
|
options.rebuild = {
|
||||||
@@ -22,29 +32,73 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
environment.systemPackages = with pkgs; [
|
environment.systemPackages = with pkgs; [ nfs nfsu ];
|
||||||
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}
|
|
||||||
'')
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
flake.modules.homeManager.rebuild =
|
flake.modules.homeManager.rebuild =
|
||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
let
|
let
|
||||||
nixBin = lib.getExe pkgs.nix;
|
|
||||||
flakeDir = config.homeManagerFlakeDir;
|
flakeDir = config.homeManagerFlakeDir;
|
||||||
echoCmd = lib.getExe' pkgs.coreutils "echo";
|
|
||||||
hostnameCmd = "$(${lib.getExe pkgs.hostname} -s)";
|
hostnameCmd = "$(${lib.getExe pkgs.hostname} -s)";
|
||||||
nhms = (pkgs.writeShellScriptBin "nhms" ''
|
|
||||||
HOSTNAME=${hostnameCmd}
|
flake-parts-check = with pkgs; writeShellApplication {
|
||||||
${echoCmd} "Switching to the $HOSTNAME home-manager profile"
|
name = "flake-parts-check";
|
||||||
${lib.getExe pkgs.nh} home switch ${flakeDir} -c $HOSTNAME "$@"
|
runtimeInputs = [ nix ];
|
||||||
'');
|
text = ''
|
||||||
|
cd ${flakeDir}
|
||||||
|
nix run "${flakeDir}#write-flake"
|
||||||
|
nix flake check
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
nhms = with pkgs; writeShellApplication {
|
||||||
|
name = "nhms";
|
||||||
|
runtimeInputs = [ coreutils hostname nh ];
|
||||||
|
text = ''
|
||||||
|
HOSTNAME=$(hostname -s)
|
||||||
|
echo "Switching to the $HOSTNAME home-manager profile"
|
||||||
|
nh home switch ${flakeDir} -c "$HOSTNAME" "$@"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
nhmu = with pkgs; writeShellApplication {
|
||||||
|
name = "nhmu";
|
||||||
|
runtimeInputs = [ nhms ];
|
||||||
|
text = ''nhms --update'';
|
||||||
|
};
|
||||||
|
|
||||||
|
test-build = with pkgs; writeShellApplication {
|
||||||
|
name = "test-build";
|
||||||
|
runtimeInputs = [ coreutils nix hostname ];
|
||||||
|
text = ''
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
HOSTNAME=$(hostname -s)
|
||||||
|
else
|
||||||
|
HOSTNAME="$1"
|
||||||
|
fi
|
||||||
|
echo "Testing the evaulation of the nixos config for $HOSTNAME"
|
||||||
|
nix eval "${flakeDir}#nixosConfigurations.$HOSTNAME.config.system.build.toplevel.drvPath"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
cleanup = with pkgs; writeShellApplication {
|
||||||
|
name = "cleanup";
|
||||||
|
runtimeInputs = [ coreutils home-manager nix ];
|
||||||
|
text = ''
|
||||||
|
set -e
|
||||||
|
DAYS=$1
|
||||||
|
if [ -z "$DAYS" ]; then
|
||||||
|
echo "usage: cleanup <days>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
home-manager expire-generations "-$DAYS days"
|
||||||
|
nix profile wipe-history --older-than "''${DAYS}d"
|
||||||
|
nix store gc
|
||||||
|
nix store optimise
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
@@ -53,52 +107,25 @@
|
|||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
default = "${config.xdg.configHome}/home-manager";
|
default = "${config.xdg.configHome}/home-manager";
|
||||||
};
|
};
|
||||||
buildHostname = lib.mkOption {
|
|
||||||
description = "Hostname for the NixOS configuration to use.";
|
|
||||||
type = lib.types.str;
|
|
||||||
default = hostnameCmd;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
home.activation.printFlakeDir = lib.hm.dag.entryAfter ["writeBoundary"] ''
|
home.activation.printFlakeDir = lib.hm.dag.entryAfter ["writeBoundary"] ''
|
||||||
run ${echoCmd} "Home Manager flake directory: ${flakeDir}"
|
run echo "Home Manager flake directory: ${flakeDir}"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
home.packages = with pkgs; [
|
home.packages = with pkgs; [
|
||||||
home-manager
|
home-manager
|
||||||
(writeShellScriptBin "flake-parts-check" ''
|
(symlinkJoin {
|
||||||
cd ${flakeDir}
|
name = "build-tools";
|
||||||
${nixBin} run "${flakeDir}#write-flake"
|
paths = [
|
||||||
${nixBin} flake check
|
flake-parts-check
|
||||||
'')
|
|
||||||
nhms
|
nhms
|
||||||
(writeShellScriptBin "nhmu" ''
|
nhmu
|
||||||
${lib.getExe nhms} --update
|
test-build
|
||||||
'')
|
cleanup
|
||||||
|
];
|
||||||
(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
|
|
||||||
'')
|
|
||||||
|
|
||||||
(writeShellScriptBin "cleanup" ''
|
|
||||||
set -e
|
|
||||||
DAYS=$1
|
|
||||||
if [ -z "$DAYS" ]; then
|
|
||||||
${echoCmd} "usage: cleanup <days>"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
${lib.getExe home-manager} expire-generations "-$DAYS days"
|
|
||||||
${lib.getExe nix} profile wipe-history --older-than "''${DAYS}d"
|
|
||||||
${lib.getExe nix} store gc
|
|
||||||
${lib.getExe nix} store optimise
|
|
||||||
'')
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user