diff --git a/CLAUDE.md b/CLAUDE.md index 3566bad..8396ca0 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -402,6 +402,8 @@ This means: **Firewall**: Disabled on most hosts (trusted network). Enable selectively in host configuration if needed. +**Shell scripts**: Use `pkgs.writeShellApplication` instead of `pkgs.writeShellScriptBin` for creating shell scripts. `writeShellApplication` provides automatic shellcheck validation, sets strict bash options (`set -euo pipefail`), and allows declaring `runtimeInputs` for dependencies. + ### Monitoring Stack All hosts ship metrics and logs to `monitoring01`: diff --git a/system/nix.nix b/system/nix.nix index 3ab9094..f50d35c 100644 --- a/system/nix.nix +++ b/system/nix.nix @@ -1,5 +1,25 @@ -{ lib, ... }: +{ lib, pkgs, ... }: +let + nixos-rebuild-test = pkgs.writeShellApplication { + name = "nixos-rebuild-test"; + runtimeInputs = [ pkgs.nixos-rebuild ]; + text = '' + if [ $# -lt 2 ]; then + echo "Usage: nixos-rebuild-test " + echo "Example: nixos-rebuild-test boot my-feature-branch" + exit 1 + fi + + action="$1" + branch="$2" + shift 2 + + exec nixos-rebuild "$action" --flake "git+https://git.t-juice.club/torjus/nixos-servers.git?ref=$branch" "$@" + ''; + }; +in { + environment.systemPackages = [ nixos-rebuild-test ]; nix = { gc = { automatic = true;