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