diff options
author | Travis A. Everett <travis.a.everett@gmail.com> | 2021-09-23 18:23:52 -0500 |
---|---|---|
committer | Raphael Megzari <raphael@megzari.com> | 2021-09-27 16:01:09 +0900 |
commit | b5833091d4d24e7a742df703a4b02acfe8f4ecb1 (patch) | |
tree | eb21b9c349d6f0ff959ced518d84f96898f0108c | |
parent | 67ec4fa479b82a264ee647785df261f0f12b7f05 (diff) |
resholve: 0.6.0 -> 0.6.1, add resholveScript* fns
-rw-r--r-- | pkgs/development/misc/resholve/README.md | 35 | ||||
-rw-r--r-- | pkgs/development/misc/resholve/default.nix | 35 | ||||
-rw-r--r-- | pkgs/development/misc/resholve/source.nix | 4 | ||||
-rw-r--r-- | pkgs/development/misc/resholve/test.nix | 18 |
4 files changed, 86 insertions, 6 deletions
diff --git a/pkgs/development/misc/resholve/README.md b/pkgs/development/misc/resholve/README.md index 024465f306cd2..c5f7b8750b7a8 100644 --- a/pkgs/development/misc/resholve/README.md +++ b/pkgs/development/misc/resholve/README.md @@ -2,7 +2,8 @@ resholve converts bare executable references in shell scripts to absolute paths. This will hopefully make its way into the Nixpkgs manual soon, but -until then I'll outline how to use the `resholvePackage` function. +until then I'll outline how to use the `resholvePackage`, `resholveScript`, +and `resholveScriptBin` functions. > Fair warning: resholve does *not* aspire to resolving all valid Shell > scripts. It depends on the OSH/Oil parser, which aims to support most (but @@ -21,7 +22,10 @@ Each "solution" (k=v pair) in this attrset describes one resholve invocation. > - Packages with scripts that require conflicting directives can use multiple > solutions to resolve the scripts separately, but produce a single package. -## Basic Example +The `resholveScript` and `resholveScriptBin` functions support a _single_ +`solution` attrset. This is basically the same as any single solution in `resholvePackage`, except that it doesn't need a `scripts` attr (it is automatically added). + +## Basic `resholvePackage` Example Here's a simple example from one of my own projects, with annotations: <!-- @@ -68,6 +72,28 @@ resholvePackage rec { } ``` +## Basic `resholveScript` and `resholveScriptBin` examples + +Both of these functions have the same basic API. This example is a little +trivial for now. If you have a real usage that you find helpful, please PR it. + +```nix +resholvedScript = resholveScript "name" { + inputs = [ file ]; + interpreter = "${bash}/bin/bash"; + } '' + echo "Hello" + file . + ''; +resholvedScriptBin = resholveScriptBin "name" { + inputs = [ file ]; + interpreter = "${bash}/bin/bash"; + } '' + echo "Hello" + file . + ''; +``` + ## Options `resholvePackage` maps Nix types/idioms into the flags and environment variables @@ -177,6 +203,11 @@ some of the more common commands. - "wrapper" lore maps shell exec wrappers to the programs they exec so that resholve can substitute an executable's verdict for its wrapper's. +> **Caution:** At least when it comes to common utilities, it's best to treat +> overrides as a stopgap until they can be properly handled in resholve and/or +> binlore. Please report things you have to override and, if possible, help +> get them sorted. + There will be more mechanisms for controlling this process in the future (and your reports/experiences will play a role in shaping them...) For now, the main lever is the ability to substitute your own lore. This is how you'd diff --git a/pkgs/development/misc/resholve/default.nix b/pkgs/development/misc/resholve/default.nix index cb32f9f9c756f..714c4ecabe082 100644 --- a/pkgs/development/misc/resholve/default.nix +++ b/pkgs/development/misc/resholve/default.nix @@ -1,5 +1,5 @@ { callPackage -, ... +, writeTextFile }: let @@ -17,4 +17,37 @@ rec { resholvePackage = callPackage ./resholve-package.nix { inherit resholve resholve-utils; }; + resholveScript = name: partialSolution: text: + writeTextFile { + inherit name text; + executable = true; + checkPhase = '' + ( + PS4=$'\x1f'"\033[33m[resholve context]\033[0m " + set -x + ${resholve-utils.makeInvocation name (partialSolution // { + scripts = [ "${placeholder "out"}" ]; + })} + ) + ${partialSolution.interpreter} -n $out + ''; + }; + resholveScriptBin = name: partialSolution: text: + writeTextFile rec { + inherit name text; + executable = true; + destination = "/bin/${name}"; + checkPhase = '' + ( + cd "$out" + PS4=$'\x1f'"\033[33m[resholve context]\033[0m " + set -x + : changing directory to $PWD + ${resholve-utils.makeInvocation name (partialSolution // { + scripts = [ "bin/${name}" ]; + })} + ) + ${partialSolution.interpreter} -n $out/bin/${name} + ''; + }; } diff --git a/pkgs/development/misc/resholve/source.nix b/pkgs/development/misc/resholve/source.nix index 32ffeb98fd7e2..cdcc9e37cc90a 100644 --- a/pkgs/development/misc/resholve/source.nix +++ b/pkgs/development/misc/resholve/source.nix @@ -3,7 +3,7 @@ }: rec { - version = "0.6.0"; + version = "0.6.1"; rSrc = # local build -> `make ci`; `make clean` to restore # return to remote source @@ -14,6 +14,6 @@ rec { owner = "abathur"; repo = "resholve"; rev = "v${version}"; - hash = "sha256-GfhhU9f5kiYcuYTPKWXCIkAGsz7GhAUGjAmIZ8Ww5X4="; + hash = "sha256-W7pZZBI3740zBSIpL+4MFuo9j5bkURdEjgv1EfKTFHQ="; }; } diff --git a/pkgs/development/misc/resholve/test.nix b/pkgs/development/misc/resholve/test.nix index f263c019d8137..ca8a51c705d62 100644 --- a/pkgs/development/misc/resholve/test.nix +++ b/pkgs/development/misc/resholve/test.nix @@ -23,7 +23,7 @@ let inherit (callPackage ./default.nix { }) - resholve resholvePackage; + resholve resholvePackage resholveScript resholveScriptBin; # ourCoreutils = coreutils.override { singleBinary = false; }; @@ -224,4 +224,20 @@ rec { fi ''; }; + + # Caution: ci.nix asserts the equality of both of these w/ diff + resholvedScript = resholveScript "resholved-script" { + inputs = [ file ]; + interpreter = "${bash}/bin/bash"; + } '' + echo "Hello" + file . + ''; + resholvedScriptBin = resholveScriptBin "resholved-script-bin" { + inputs = [ file ]; + interpreter = "${bash}/bin/bash"; + } '' + echo "Hello" + file . + ''; } |