-
Notifications
You must be signed in to change notification settings - Fork 399
Expand file tree
/
Copy pathderivation.nix
More file actions
75 lines (75 loc) · 2.07 KB
/
derivation.nix
File metadata and controls
75 lines (75 loc) · 2.07 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
{ stdenv
, pkgs
, enableCriu
, enableSystemd
, libcap
, libseccomp
, libsystemd
, yajl
, criu
}:
with pkgs; stdenv.mkDerivation {
name = "crun";
src = ./..;
vendorSha256 = null;
doCheck = false;
enableParallelBuilding = true;
outputs = [ "out" ];
nativeBuildInputs = with buildPackages; [
autoreconfHook
autoPatchelfHook
bash
git
pkg-config
python3
which
];
buildInputs =
(if stdenv.hostPlatform.isMusl then [
argp-standalone
] else [
glibc
glibc.static
]) ++ [
libcap
libseccomp
libsystemd
yajl
] ++ lib.optionals enableCriu [ criu ];
configureFlags = [ "--enable-static" ] ++ lib.optional (!enableSystemd) [ "--disable-systemd" ];
prePatch = let
staticLibs =
lib.optional enableCriu "${criu}/lib/libcriu.a"
++ (if stdenv.hostPlatform.isMusl
then map (l: "${musl}/lib/${l}") [ "libc.a" "libpthread.a" "librt.a" ]
else map (l: "${glibc.static}/lib/${l}") [ "libc.a" "libpthread.a" "librt.a" ])
++ [
"${lib.getLib libcap}/lib/libcap.a"
"${lib.getLib libseccomp}/lib/libseccomp.a"
]
++ lib.optional enableSystemd "${lib.getLib libsystemd}/lib/libsystemd.a"
++ [ "${yajl}/lib/libyajl.a" ];
in ''
export CFLAGS='-static -pthread -DSTATIC'
export LDFLAGS='-s -w -static-libgcc -static'
export EXTRA_LDFLAGS='-s -w -linkmode external -extldflags "-static -lm"'
export CRUN_LDFLAGS='-all-static'
export LIBS='${lib.concatStringsSep " " staticLibs}'
'';
buildPhase = ''
patchShebangs .
if [ -f .tarball-git-version.h ]; then
cp .tarball-git-version.h git-version.h
elif [ -f .git ]; then
version=$(git rev-parse HEAD)
printf '/* autogenerated. */\n#ifndef GIT_VERSION\n# define GIT_VERSION "%s"\n#endif\n' "$version" > git-version.h
else
printf '/* autogenerated. */\n#ifndef GIT_VERSION\n# define GIT_VERSION "unknown"\n#endif\n' > git-version.h
fi
make -C libocispec libocispec.la
make crun
'';
installPhase = ''
install -Dm755 crun $out/bin/crun
'';
}