about summary refs log tree commit diff
path: root/pkgs/profpatsch
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2022-01-07 14:47:38 +0100
committerProfpatsch <mail@profpatsch.de>2022-01-07 15:01:34 +0100
commitc51ecb7691b659d9651679153bc1e4edfc5fb20e (patch)
treedf13dad1d98e4c21be19ab45863c396e4bac8f44 /pkgs/profpatsch
parent392ea892116f6cb659293cd55e0e2fa8c6329baf (diff)
pkgs/profpatsch: add nix-run-bin
Takes an additional argument and looks that argument up in the
respective nix build result directory bin dir.

Also add some documentation.
Diffstat (limited to 'pkgs/profpatsch')
-rw-r--r--pkgs/profpatsch/default.nix1
-rw-r--r--pkgs/profpatsch/nix-tools.nix28
2 files changed, 27 insertions, 2 deletions
diff --git a/pkgs/profpatsch/default.nix b/pkgs/profpatsch/default.nix
index 4488c3a8..c7516927 100644
--- a/pkgs/profpatsch/default.nix
+++ b/pkgs/profpatsch/default.nix
@@ -259,6 +259,7 @@ in rec {
 
   inherit (import ./nix-tools.nix { inherit pkgs getBins writeExecline runblock; })
     nix-run
+    nix-run-bin
     nix-eval
     ;
 
diff --git a/pkgs/profpatsch/nix-tools.nix b/pkgs/profpatsch/nix-tools.nix
index 557e6680..e0b20318 100644
--- a/pkgs/profpatsch/nix-tools.nix
+++ b/pkgs/profpatsch/nix-tools.nix
@@ -1,13 +1,36 @@
-{ pkgs, writeExecline, runblock, getBins }:
+{ pkgs, writeExecline, getBins, runblock }:
 
 let
   bins = getBins pkgs.nix [ "nix-build" "nix-instantiate" ];
 
+  # Usage (execline syntax):
+  #    nix-run { -A foo <more_nix_options> } args...
+  #
+  # Takes an execline block of `nix-build` arguments, which should produce an executable store path.
+  # Then runs the store path with `prog...`.
   nix-run = writeExecline "nix-run" { argMode = "env"; } [
     "backtick" "-iE" "storepath" [
       runblock "1" bins.nix-build
     ]
-    runblock "-r" "2" "exec" "$storepath"
+    runblock "-r" "2" "$storepath"
+  ];
+
+  # Usage (execline syntax):
+  #    nix-run-bin { -A foo <more_nix_options> } <foo_bin_name> args...
+  #
+  # Takes an execline block of `nix-build` arguments, which should produce a store path with a bin/ directory in it.
+  # Then runs the `/bin/<foo_bin_name>` executable in the store path with the given arguments.
+  nix-run-bin = writeExecline "nix-run-bin" { argMode = "env"; } [
+    "backtick" "-i" "storepath" [
+      runblock "1" bins.nix-build
+    ]
+    runblock "-r" "2"
+      # workaround, runblock does not set # and $0 and so forth in its blocks (yet)
+      (writeExecline "nix-run-bin-rest-block" { readNArgs = 1; } [
+        "importas" "-ui" "storepath" "storepath"
+        "if" [ "echo" "\${storepath}/bin/\${1}" ]
+        "\${storepath}/bin/\${1}" "$@"
+      ])
   ];
 
   nix-eval = writeExecline "nix-eval" {} [
@@ -21,6 +44,7 @@ let
 in {
   inherit
     nix-run
+    nix-run-bin
     nix-eval
     ;
 }