From ae89ea7769db2405cebf1f5af3901a4957d8dff2 Mon Sep 17 00:00:00 2001 From: Carl Andersson Date: Thu, 23 Oct 2025 16:07:38 +0200 Subject: [PATCH] Implement support to fail deployment if cache push fails Rewrite deployment script in bash --- kluctl.nix | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/kluctl.nix b/kluctl.nix index a928441..9f0a4de 100644 --- a/kluctl.nix +++ b/kluctl.nix @@ -27,6 +27,7 @@ in type = lib.types.str; description = "nix store url"; }; + failCachePush = lib.mkEnableOption "fail deployment if unable to push to cache"; }; project = lib.mkOption { type = settingsFormat.type; @@ -156,26 +157,23 @@ in // cfg.files; }; kluctl.script = - pkgs.writeScriptBin "kubenixDeploy" # fish + pkgs.writeScriptBin "kubenixDeploy" # bash '' - #! ${lib.getExe pkgs.fishMinimal} + #! ${pkgs.runtimeShell} + set -euo pipefail + set -x ${lib.optionalString cfg.pushManifest.enable '' - nix copy --to ${cfg.pushManifest.to} ${config.internal.manifestJSONFile} + nix copy --to ${cfg.pushManifest.to} ${config.internal.manifestJSONFile} || ${ + lib.boolToString (!cfg.pushManifest.failCachePush) + } ''} - set command ${lib.getExe cfg.package} deploy \ + ${lib.getExe cfg.package} \ + deploy \ --no-update-check \ --target local \ --discriminator ${cfg.discriminator} \ --project-dir ${cfg.projectDir} \ - $argv # --dry-run? --yes? --prune! - echo $command - $command || begin - echo "Naughty naughty!" - exit 1 - end && begin - echo "Great success!" - exit 0 - end + $@ # --dry-run? --yes? --prune! ''; }; }