Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 applyPatches,
6 autoreconfHook,
7 nix-update-script,
8
9 # Required dependencies.
10 openssl,
11 zlib,
12 libxml2,
13
14 # Optional dependencies.
15 e2fsprogs,
16 bzip2,
17 xz, # lzma
18
19 # Platform-specific dependencies.
20 acl,
21 musl-fts,
22
23 # for tests
24 testers,
25 python3,
26 libxslt, # xsltproc
27 runCommand,
28 runCommandCC,
29 makeWrapper,
30 xar,
31}:
32stdenv.mkDerivation (finalAttrs: {
33 pname = "xar${lib.optionalString (e2fsprogs == null) "-minimal"}";
34 version = "501";
35
36 src = fetchFromGitHub {
37 owner = "apple-oss-distributions";
38 repo = "xar";
39 rev = "xar-${finalAttrs.version}";
40 hash = "sha256-Fq+Re0LCBIGhW2FR+pgV8SWtaDOEFgTh+rQ8JFWK/k0=";
41 };
42
43 # Update patch set with
44 # git clone https://github.com/apple-oss-distributions/xar
45 # cd xar
46 # git switch -c nixpkgs
47 # git am ../pkgs/by-name/xa/xar/patches/*
48 # # …
49 # rm -r ../pkgs/by-name/xa/xar/patches
50 # git format-patch --zero-commit --output-directory ../pkgs/by-name/xa/xar/patches main
51 patches =
52 # Avoid Darwin rebuilds on staging-next
53 lib.filter (
54 p: stdenv.hostPlatform.isDarwin -> baseNameOf p != "0020-Fall-back-to-readlink-on-Linux.patch"
55 ) (lib.filesystem.listFilesRecursive ./patches);
56
57 # We do not use or modify files outside of the xar subdirectory.
58 patchFlags = [ "-p2" ];
59 sourceRoot = "${finalAttrs.src.name}/xar";
60
61 outputs = [
62 "out"
63 "lib"
64 "dev"
65 ];
66
67 strictDeps = true;
68
69 nativeBuildInputs = [ autoreconfHook ];
70
71 env.NIX_CFLAGS_COMPILE = toString (
72 [
73 # For some reason libxml2 package headers are in subdirectory and thus aren’t
74 # picked up by stdenv’s C compiler wrapper (see ccWrapper_addCVars). This
75 # doesn’t really belong here and either should be part of libxml2 package or
76 # libxml2 in Nixpkgs can just fix their header paths.
77 "-isystem ${libxml2.dev}/include/libxml2"
78 ]
79 ++ lib.optionals stdenv.cc.isGNU [
80 # fix build on GCC 14
81 "-Wno-error=implicit-function-declaration"
82 "-Wno-error=incompatible-pointer-types"
83 ]
84 );
85
86 buildInputs = [
87 # NB we use OpenSSL instead of CommonCrypto on Darwin.
88 openssl
89 zlib
90 libxml2
91 bzip2
92 xz
93 e2fsprogs
94 ]
95 ++ lib.optional stdenv.hostPlatform.isLinux acl
96 ++ lib.optional stdenv.hostPlatform.isMusl musl-fts;
97
98 passthru =
99 let
100 patchedSource = applyPatches { inherit (finalAttrs) src patches; };
101 pythonForTests = python3.withPackages (p: [ p.xattr ]);
102 in
103 {
104 # Tests xar outside of the Nix sandbox (extended attributes are not supported
105 # in Nix sandbox, e.g. filtered with seccomp on Linux).
106 #
107 # Run with
108 # $ nix run --file . xar.impureTests.integrationTest
109 # Ensure that all tests are PASSED and none are FAILED or SKIPPED.
110 impureTests.integrationTest =
111 runCommand "xar-impure-tests-integration-test"
112 {
113 src = patchedSource;
114 xar = finalAttrs.finalPackage;
115 xsltproc = lib.getBin libxslt;
116 pythonInterpreter = pythonForTests.interpreter;
117 nativeBuildInputs = [ makeWrapper ];
118 }
119 ''
120 makeWrapper "$pythonInterpreter" "$out/bin/$name" \
121 --prefix PATH : "$xar/bin" \
122 --suffix PATH : "$xsltproc/bin" \
123 --add-flags -- \
124 --add-flags "$src/xar/test/run-all.py"
125 '';
126
127 tests = lib.optionalAttrs (stdenv.buildPlatform.canExecute stdenv.hostPlatform) {
128 version = testers.testVersion {
129 package = finalAttrs.finalPackage;
130 version = "1.8dev";
131 };
132
133 integrationTest =
134 runCommand "xar-tests-integration-test"
135 {
136 src = patchedSource;
137 strictDeps = true;
138 pythonExecutable = pythonForTests.executable;
139 nativeBuildInputs = [
140 finalAttrs.finalPackage
141 pythonForTests
142 libxslt
143 ];
144 }
145 ''
146 "$pythonExecutable" "$src"/xar/test/run-all.py
147 touch "$out"
148 '';
149
150 smokeTest =
151 runCommandCC "xar-tests-smoke-test"
152 {
153 src = patchedSource;
154 strictDeps = true;
155 nativeBuildInputs = [ finalAttrs.finalPackage ];
156 buildInputs = [
157 finalAttrs.finalPackage
158 openssl
159 ];
160 }
161 ''
162 cp "$src"/xar/test/{buffer.c,validate.c} .
163 "$CC" -lxar -o buffer buffer.c
164 "$CC" -lxar -lcrypto -o validate validate.c
165 ./buffer validate.c
166 xar -x -f test.xar
167 diff validate.c mydir/secondfile
168 ./validate test.xar
169 touch "$out"
170 '';
171 };
172
173 updateScript = nix-update-script {
174 extraArgs = [
175 "--version-regex"
176 "xar-(.*)"
177 ];
178 };
179 };
180
181 meta = {
182 homepage = "https://github.com/apple-oss-distributions/xar";
183 description = "Easily extensible archive format";
184 license = lib.licenses.bsd3;
185 maintainers = lib.attrValues { inherit (lib.maintainers) tie; };
186 teams = [ lib.teams.darwin ];
187 platforms = lib.platforms.unix;
188 mainProgram = "xar";
189 };
190})