about summary refs log tree commit diff
path: root/nix
diff options
context:
space:
mode:
authorzimbatm <zimbatm@zimbatm.com>2022-05-30T16·59+0200
committertazjin <tazjin@tvl.su>2022-12-26T10·31+0000
commit99030d10ce114124e7303231e9bcb382f10bd0e7 (patch)
treeb01cd4f90291a8a9fbdd56baf8e468d2919e6bf9 /nix
parent71174f6626cbf100a8428ddc334681e4edfb45e6 (diff)
refactor(nix/lazy-deps): use runCommand r/5487
writeTextFile is nice, but not flexible enough to allow the passthru
argument needed for a follow-up change.

Change-Id: I4f0cffd0f29b2c06b0155101d3806c9c5745c37a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/5854
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'nix')
-rw-r--r--nix/lazy-deps/default.nix66
1 files changed, 37 insertions, 29 deletions
diff --git a/nix/lazy-deps/default.nix b/nix/lazy-deps/default.nix
index 3cce48d8a53e..bfdf5490ce22 100644
--- a/nix/lazy-deps/default.nix
+++ b/nix/lazy-deps/default.nix
@@ -38,38 +38,46 @@ in
   # derivation.
 tools:
 
-pkgs.writeTextFile {
-  name = "lazy-dispatch";
-  executable = true;
-  destination = "/bin/__dispatch";
+let
+  self = pkgs.runCommandNoCC "lazy-dispatch"
+    {
+      text = ''
+        #!${pkgs.runtimeShell}
+        set -ue
 
-  text = ''
-    #!${pkgs.runtimeShell}
-    set -ue
+        if ! type git>/dev/null || ! type nix-build>/dev/null; then
+          echo "The 'git' and 'nix-build' commands must be available." >&2
+          exit 127
+        fi
 
-    if ! type git>/dev/null || ! type nix-build>/dev/null; then
-      echo "The 'git' and 'nix-build' commands must be available." >&2
-      exit 127
-    fi
+        readonly REPO_ROOT=$(git rev-parse --show-toplevel)
+        TARGET_TOOL=$(basename "$0")
 
-    readonly REPO_ROOT=$(git rev-parse --show-toplevel)
-    TARGET_TOOL=$(basename "$0")
+        case "''${TARGET_TOOL}" in
+        ${invocations tools}
+        *)
+          echo "''${TARGET_TOOL} is currently not installed in this repository." >&2
+          exit 127
+          ;;
+        esac
 
-    case "''${TARGET_TOOL}" in
-    ${invocations tools}
-    *)
-      echo "''${TARGET_TOOL} is currently not installed in this repository." >&2
-      exit 127
-      ;;
-    esac
+        result=$(nix-build --no-out-link --attr "''${attr}" "''${REPO_ROOT}")
+        PATH="''${result}/bin:$PATH"
+        exec "''${TARGET_TOOL}" "''${@}"
+      '';
+    }
+    ''
+      # Write the dispatch code
+      target=$out/bin/__dispatch
+      mkdir -p "$(dirname "$target")"
+      echo "$text" > $target
+      chmod +x $target
 
-    result=$(nix-build --no-out-link --attr "''${attr}" "''${REPO_ROOT}")
-    PATH="''${result}/bin:$PATH"
-    exec "''${TARGET_TOOL}" "''${@}"
-  '';
+      # Add symlinks from all the tools to the dispatch
+      ${concatStringsSep "\n" (map link (attrNames tools))}
 
-  checkPhase = ''
-    ${pkgs.stdenv.shellDryRun} "$target"
-    ${concatStringsSep "\n" (map link (attrNames tools))}
-  '';
-}
+      # Check that it's working-ish
+      ${pkgs.stdenv.shellDryRun} $target
+    '';
+in
+self