This repository has no description
1{
2 lib,
3 currentSystem,
4 bash,
5 busybox,
6}:
7
8let
9 run =
10 {
11 path ? [ ],
12 passAsFile ? [ ],
13 ...
14 }@args:
15 command:
16
17 derivation (
18 {
19 system = currentSystem;
20 builder = "${bash}/bin/bash";
21 args = [
22 "-euc"
23 ''
24 if [[ -v stdenv ]]; then
25 source $stdenv/setup
26 buildPhase
27 else
28 source $commandPath
29 fi
30 ''
31 ];
32 PATH = lib.makeBinPath (
33 path
34 ++ [
35 bash
36 busybox
37 ]
38 );
39 inherit command;
40 passAsFile = [ "command" ] ++ passAsFile;
41 }
42 // (removeAttrs args [
43 "path"
44 "passAsFile"
45 ])
46 );
47
48 stdenv =
49 run
50 {
51 name = "stdenv";
52 setup = ''
53 : ${"$"}{outputs:=out}
54
55 if [ 0 -eq "$NIX_BUILD_CORES" ]; then
56 NIX_BUILD_CORES=$(${busybox}/bin/nproc)
57 fi
58
59 eval "_build() { $(cat $commandPath); }"
60 buildPhase() {
61 if [[ "$name" =~ -env$ ]]; then
62 name="${"$"}{name%-env}"
63 if [ ! -d "overrides/$name/src" ]; then
64 echo "error: no override found for $name"
65 return 1
66 fi
67 cd overrides/$name/src
68 unset src
69 _build
70 return
71 fi
72
73 if [[ -v src ]]; then
74 cp -r $src src
75 cd src
76 chmod -R u+w .
77 unset src
78 fi
79 _build
80 }
81
82 runHook() {
83 "$1"
84 }
85 '';
86 passAsFile = [ "setup" ];
87 }
88 ''
89 mkdir $out
90 cp $setupPath $out/setup
91 chmod +x $out/setup
92 '';
93in
94
95args: run ({ inherit stdenv; } // args)