nix-conf/home/scripts/remoteRebuild.nix
2025-11-23 16:24:38 +08:00

38 lines
820 B
Nix
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
osConfig,
config,
pkgs,
}:
let
inherit (osConfig.networking) hostName;
shouldNotify =
(builtins.hasAttr "ntfy-client" config.services) && config.services.ntfy-client.enable;
rebuildCommand = ''
nixos-rebuild switch --target-host "$TARGET" \
--build-host "$BUILD" \
--sudo --ask-sudo-password $@'';
in
pkgs.writeShellScriptBin "rRebuild" ''
TARGET=$1
BUILD=$2
shift
shift
${
if shouldNotify then
''
export NTFY_TITLE="🎯 $TARGET built by 🏗 ''\${BUILD:-${hostName}}"
export NTFY_TAGS="gear"
if ${rebuildCommand}
then
ntfy pub system-build " Build success" > /dev/null 2>&1
else
ntfy pub system-build " Build failed" > /dev/null 2>&1
fi
''
else
rebuildCommand
}
''