-
-
Notifications
You must be signed in to change notification settings - Fork 528
Expand file tree
/
Copy pathflake.nix
More file actions
296 lines (263 loc) · 9.5 KB
/
flake.nix
File metadata and controls
296 lines (263 loc) · 9.5 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
{
description = "A tool for modifying ELF executables and libraries";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
# dev tooling
inputs.flake-parts.url = "github:hercules-ci/flake-parts";
inputs.git-hooks-nix.url = "github:cachix/git-hooks.nix";
# work around https://github.com/NixOS/nix/issues/7730
inputs.flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
inputs.git-hooks-nix.inputs.nixpkgs.follows = "nixpkgs";
inputs.git-hooks-nix.inputs.nixpkgs-stable.follows = "nixpkgs";
# work around 7730 and https://github.com/NixOS/nix/issues/7807
inputs.git-hooks-nix.inputs.flake-compat.follows = "";
inputs.git-hooks-nix.inputs.gitignore.follows = "";
outputs =
inputs@{ self, nixpkgs, ... }:
let
inherit (nixpkgs) lib;
supportedSystems = [
"x86_64-linux"
"i686-linux"
"aarch64-linux"
];
forAllSystems = lib.genAttrs supportedSystems;
version = lib.removeSuffix "\n" (builtins.readFile ./version);
pkgs = nixpkgs.legacyPackages.x86_64-linux;
baseSrcFiles = [
./COPYING
./README.md
./completions
./patchelf.1
./patchelf.spec.in
(lib.fileset.difference ./src (
lib.fileset.unions [
./src/Makefile.am
./src/CMakeLists.txt
./src/meson.build
]
))
(lib.fileset.difference ./tests (
lib.fileset.unions [
./tests/Makefile.am
#./tests/CMakeLists.txt
#./tests/meson.build
]
))
./version
];
autotoolsSrcFiles = [
./Makefile.am
./src/Makefile.am
./tests/Makefile.am
./configure.ac
./m4
];
cmakeSrcFiles = [
./CMakeLists.txt
./src/CMakeLists.txt
#./tests/CMakeLists.txt
];
mesonSrcFiles = [
./meson.build
./meson.options
./src/meson.build
#./tests/meson.build
];
autotoolsSrc = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions (baseSrcFiles ++ autotoolsSrcFiles);
};
patchelfFor =
pkgs:
pkgs.callPackage ./package-autotools.nix {
inherit version;
src = autotoolsSrc;
};
# We don't apply flake-parts to the whole flake so that non-development attributes
# load without fetching any development inputs.
devFlake = inputs.flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ ./maintainers/flake-module.nix ];
systems = supportedSystems;
perSystem =
{ system, ... }:
{
_module.args.pkgs = nixpkgs.legacyPackages.${system};
};
};
in
{
overlays.default = final: prev: {
patchelf-new-musl = patchelfFor final.pkgsMusl;
patchelf-new = patchelfFor final;
};
hydraJobs = {
tarball = pkgs.releaseTools.sourceTarball rec {
name = "patchelf-tarball";
inherit version;
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions (baseSrcFiles ++ autotoolsSrcFiles ++ cmakeSrcFiles ++ mesonSrcFiles);
};
versionSuffix = ""; # obsolete
preAutoconf = "echo ${version} > version";
# portable configure shouldn't have a shebang pointing to the nix store
postConfigure = ''
sed -i '1s|^.*$|#!/bin/sh|' ./configure
'';
postDist = ''
cp README.md $out/
echo "doc readme $out/README.md" >> $out/nix-support/hydra-build-products
'';
};
coverage =
(pkgs.releaseTools.coverageAnalysis {
name = "patchelf-coverage";
src = self.hydraJobs.tarball;
lcovFilter = [ "*/tests/*" ];
}).overrideAttrs
(old: {
preCheck = ''
# coverage cflag breaks this target
NIX_CFLAGS_COMPILE=''${NIX_CFLAGS_COMPILE//--coverage} make -C tests phdr-corruption.so
'';
});
build = forAllSystems (system: self.packages.${system}.patchelf);
build-sanitized = forAllSystems (
system:
self.packages.${system}.patchelf.overrideAttrs (old: {
configureFlags = [
"--with-asan "
"--with-ubsan"
];
# -Wno-unused-command-line-argument is for clang, which does not like
# our cc wrapper arguments
CFLAGS = "-Werror -Wno-unused-command-line-argument";
})
);
build-cmake = forAllSystems (system: self.packages.${system}.patchelf-cmake);
build-meson = forAllSystems (system: self.packages.${system}.patchelf-meson);
# x86_64-linux seems to be only working clangStdenv at the moment
build-sanitized-clang = lib.genAttrs [ "x86_64-linux" ] (
system:
self.hydraJobs.build-sanitized.${system}.override {
stdenv = nixpkgs.legacyPackages.${system}.llvmPackages_latest.libcxxStdenv;
}
);
# To get mingw compiler from hydra cache
inherit (self.packages.x86_64-linux) patchelf-win32 patchelf-win64;
release = pkgs.releaseTools.aggregate {
name = "patchelf-${self.hydraJobs.tarball.version}";
constituents = [
self.hydraJobs.tarball
self.hydraJobs.build.x86_64-linux
self.hydraJobs.build.i686-linux
self.hydraJobs.build-cmake.x86_64-linux
self.hydraJobs.build-meson.x86_64-linux
# FIXME: add aarch64 emulation to our github action...
#self.hydraJobs.build.aarch64-linux
self.hydraJobs.build-sanitized.x86_64-linux
#self.hydraJobs.build-sanitized.aarch64-linux
self.hydraJobs.build-sanitized.i686-linux
self.hydraJobs.build-sanitized-clang.x86_64-linux
];
meta.description = "Release-critical builds";
};
};
checks = forAllSystems (
system:
{
build = self.hydraJobs.build.${system};
}
// devFlake.checks.${system} or { }
);
devShells = forAllSystems (
system:
let
mkShell =
patchelf:
patchelf.overrideAttrs (
old:
let
pkgs = nixpkgs.legacyPackages.${system};
modular = devFlake.getSystem pkgs.stdenv.buildPlatform.system;
in
{
env = (old.env or { }) // {
_NIX_PRE_COMMIT_HOOKS_CONFIG = "${(pkgs.formats.yaml { }).generate "pre-commit-config.yaml"
modular.pre-commit.settings.rawConfig
}";
};
nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
#pkgs.buildPackages.cmake
#pkgs.buildPackages.meson
#pkgs.buildPackages.ninja
modular.pre-commit.settings.package
(pkgs.buildPackages.writeScriptBin "pre-commit-hooks-install" modular.pre-commit.settings.installationScript)
];
}
);
in
{
glibc = mkShell self.packages.${system}.patchelf;
default = self.devShells.${system}.glibc;
}
// lib.optionalAttrs (system != "i686-linux") {
musl = mkShell self.packages.${system}.patchelf-musl;
}
);
packages = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
patchelfForWindowsStatic =
pkgs:
(pkgs.callPackage ./package-autotools.nix {
inherit version;
src = autotoolsSrc;
# On windows we use win32 threads to get a static binary,
# otherwise `-static` below doesn't work.
stdenv = pkgs.stdenv.override (old: {
cc = old.cc.override (old: {
cc = old.cc.override {
threadsCross = {
model = "win32";
package = null;
};
};
});
});
}).overrideAttrs
(old: {
NIX_CFLAGS_COMPILE = "-static";
});
in
{
patchelf = patchelfFor pkgs;
default = self.packages.${system}.patchelf;
patchelf-cmake = pkgs.callPackage ./package-cmake.nix {
inherit version;
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions (baseSrcFiles ++ cmakeSrcFiles);
};
};
patchelf-meson = pkgs.callPackage ./package-meson.nix {
inherit version;
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions (baseSrcFiles ++ mesonSrcFiles);
};
};
# This is a good test to see if packages can be cross-compiled. It also
# tests if our testsuite uses target-prefixed executable names.
patchelf-musl-cross = patchelfFor pkgs.pkgsCross.musl64;
patchelf-netbsd-cross = patchelfFor pkgs.pkgsCross.x86_64-netbsd;
patchelf-win32 = patchelfForWindowsStatic pkgs.pkgsCross.mingw32;
patchelf-win64 = patchelfForWindowsStatic pkgs.pkgsCross.mingwW64;
}
// lib.optionalAttrs (system != "i686-linux") {
patchelf-musl = patchelfFor nixpkgs.legacyPackages.${system}.pkgsMusl;
}
);
};
}