resholve: 0.6.0 -> 0.6.1, add resholveScript* fns
This commit is contained in:
parent
67ec4fa479
commit
b5833091d4
@ -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
|
||||
|
@ -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}
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
@ -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=";
|
||||
};
|
||||
}
|
||||
|
@ -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 .
|
||||
'';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user