-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpackage.nix
More file actions
131 lines (113 loc) · 3.12 KB
/
Copy pathpackage.nix
File metadata and controls
131 lines (113 loc) · 3.12 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
{
firmwareDirectory ? null,
lib,
nukeReferences,
stdenvNoCC,
zig,
}:
stdenvNoCC.mkDerivation (
finalAttrs:
let
deps = stdenvNoCC.mkDerivation {
pname = finalAttrs.pname + "-deps";
inherit (finalAttrs) src version;
depsBuildBuild = [ zig ];
buildCommand = ''
export ZIG_GLOBAL_CACHE_DIR=$(mktemp -d)
runHook unpackPhase
cd $sourceRoot
zig build --fetch
mv $ZIG_GLOBAL_CACHE_DIR/p $out
'';
outputHashAlgo = null;
outputHashMode = "recursive";
outputHash = "sha256-9gTF1Ir7HhgZqg1iswQEF4buU+KpLoCpHJuPneIKMBE=";
};
buildRunnerCache = stdenvNoCC.mkDerivation {
pname = finalAttrs.pname + "-build-runner-cache";
inherit (finalAttrs) version zigBuildFlags;
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./build.zig
./build.zig.zon
./deps
];
};
nativeBuildInputs = [ zig ];
__structuredAttrs = true;
strictDeps = true;
dontInstall = true;
dontFixup = true;
buildPhase = ''
runHook preBuild
export ZIG_GLOBAL_CACHE_DIR=$TMPDIR/zig-cache
mkdir -p $ZIG_GLOBAL_CACHE_DIR $out
ln -s ${deps} $ZIG_GLOBAL_CACHE_DIR/p
# --list-steps compiles the build script without running any of the
# steps it describes.
zig build --list-steps ''${zigBuildFlags[@]} > /dev/null
rm $ZIG_GLOBAL_CACHE_DIR/p
cp -r $ZIG_GLOBAL_CACHE_DIR/. $out/
runHook postBuild
'';
};
in
{
pname = "tinyboot";
version = "0.1.0";
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./build.zig
./build.zig.zon
./deps
./src
];
};
nativeBuildInputs = [
nukeReferences
zig
];
# Prevent zig (or anything else) from being in the runtime closure
allowedReferences = [ ];
__structuredAttrs = true;
doCheck = true;
strictDeps = true;
dontInstall = true;
zigBuildFlags = [
"--color off"
"--release=safe"
"-Dtarget=${stdenvNoCC.hostPlatform.qemuArch}-${stdenvNoCC.hostPlatform.parsed.kernel.name}"
]
++ lib.optionals (firmwareDirectory != null) [
"-Dfirmware-directory=${firmwareDirectory}"
];
configurePhase = ''
runHook preConfigure
export ZIG_GLOBAL_CACHE_DIR=$TMPDIR/zig-cache
mkdir -p $ZIG_GLOBAL_CACHE_DIR
cp -r ${buildRunnerCache}/. $ZIG_GLOBAL_CACHE_DIR/
chmod -R u+w $ZIG_GLOBAL_CACHE_DIR
ln -s ${deps} $ZIG_GLOBAL_CACHE_DIR/p
runHook postConfigure
'';
buildPhase = ''
runHook preBuild
zig build -j$NIX_BUILD_CORES install --prefix $out ''${zigBuildFlags[@]}
runHook postBuild
'';
checkPhase = ''
runHook preCheck
zig build -j$NIX_BUILD_CORES test ''${zigBuildFlags[@]}
runHook postCheck
'';
postFixup = ''
find $out -type f | while read i; do
nuke-refs -e $out $i
done
'';
passthru.initrdFile = "tboot-loader.cpio.zst";
meta.platforms = lib.platforms.linux;
}
)