1{
2 lib,
3 coreutils,
4 stdenv,
5 fetchFromGitLab,
6 fetchpatch,
7 getopt,
8 libcap,
9 gnused,
10 nixosTests,
11 testers,
12 autoreconfHook,
13 po4a,
14}:
15
16stdenv.mkDerivation (finalAttrs: {
17 version = "1.37.1.2";
18 pname = "fakeroot";
19
20 src = fetchFromGitLab {
21 owner = "clint";
22 repo = "fakeroot";
23 rev = "upstream/${finalAttrs.version}";
24 domain = "salsa.debian.org";
25 hash = "sha256-2ihdvYRnv2wpZrEikP4hCdshY8Eqarqnw3s9HPb+xKU=";
26 };
27
28 patches =
29 lib.optionals stdenv.hostPlatform.isLinux [
30 ./einval.patch
31
32 # patches needed for musl libc, borrowed from alpine packaging.
33 # it is applied regardless of the environment to prevent patchrot
34 (fetchpatch {
35 name = "fakeroot-no64.patch";
36 url = "https://git.alpinelinux.org/aports/plain/main/fakeroot/fakeroot-no64.patch?id=f68c541324ad07cc5b7f5228501b5f2ce4b36158";
37 sha256 = "sha256-NCDaB4nK71gvz8iQxlfaQTazsG0SBUQ/RAnN+FqwKkY=";
38 })
39 ]
40 ++ lib.optionals stdenv.hostPlatform.isDarwin [
41 # patch needed to fix execution on macos
42 # TODO: remove when the next release comes out: https://salsa.debian.org/clint/fakeroot/-/merge_requests/34
43 (fetchpatch {
44 name = "fakeroot-fix-macos.patch";
45 url = "https://salsa.debian.org/clint/fakeroot/-/merge_requests/34.diff";
46 hash = "sha256-D5f1bXUaN2YMD/NTx/WIrqDBx/qNHpfLRcPhbdHYLl8=";
47 })
48 ];
49
50 nativeBuildInputs = [
51 autoreconfHook
52 po4a
53 ];
54 buildInputs = lib.optional stdenv.hostPlatform.isLinux libcap;
55
56 postUnpack = ''
57 sed -i \
58 -e 's@getopt@${getopt}/bin/getopt@g' \
59 -e 's@sed@${gnused}/bin/sed@g' \
60 -e 's@kill@${coreutils}/bin/kill@g' \
61 -e 's@/bin/ls@${coreutils}/bin/ls@g' \
62 -e 's@cut@${coreutils}/bin/cut@g' \
63 source/scripts/fakeroot.in
64 '';
65
66 postConfigure = ''
67 pushd doc
68 po4a -k 0 --variable "srcdir=../doc/" po4a/po4a.cfg
69 popd
70 '';
71
72 passthru = {
73 tests = {
74 version = testers.testVersion {
75 package = finalAttrs.finalPackage;
76 };
77 # A lightweight *unit* test that exercises fakeroot and fakechroot together:
78 nixos-etc = nixosTests.etc.test-etc-fakeroot;
79 };
80 };
81
82 meta = {
83 homepage = "https://salsa.debian.org/clint/fakeroot";
84 description = "Give a fake root environment through LD_PRELOAD";
85 mainProgram = "fakeroot";
86 license = lib.licenses.gpl2Plus;
87 maintainers = [ ];
88 platforms = lib.platforms.unix;
89 };
90})