about summary refs log tree commit diff
path: root/pkgs/profpatsch/execline/run-execline.nix
blob: 40915f255dfb317d3aff5f1899390fe69424fc39 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{ stdenv, importasCommand, execlinebCommand }:
{ name
# the execline script
, execline
# additional arguments to pass to the derivation
, derivationArgs ? {}
}:

# those arguments can’t be overwritten
assert !derivationArgs ? system;
assert !derivationArgs ? name;
assert !derivationArgs ? builder;
assert !derivationArgs ? args;

derivation (derivationArgs // {
  inherit (stdenv) system;
  inherit name;

  # okay, `builtins.toFile` does not accept strings
  # that reference drv outputs. This means we need
  # to pass the script as envvar;
  # this might clash with another passed envar,
  # so we give it a long & unique name
  _runExeclineScript = execline;
  passAsFile = [ "_runExeclineScript" ]
            ++ derivationArgs.passAsFile or [];

  builder = importasCommand;
  args = [
    "-ui"                    # drop the envvar afterwards
    "script"                 # substitution name
    "_runExeclineScriptPath" # passed script file
    execlinebCommand         # the actual invocation
    "-P"                     # ignore command line arguments
    "-W"                     # die on syntax error
    "$script"                # substituted by importas
  ];
})