···8989 => "usr/local/bin"
9090 */
9191 concatStringsSep = builtins.concatStringsSep or (separator: list:
9292- concatStrings (intersperse separator list));
9292+ lib.foldl' (x: y: x + y) "" (intersperse separator list));
93939494 /* Maps a function over a list of strings and then concatenates the
9595 result with the specified separator interspersed between
+3
nixos/modules/services/misc/paperless-ng.nix
···284284 PATH = mkForce cfg.package.path;
285285 PYTHONPATH = "${cfg.package.pythonPath}:${cfg.package}/lib/paperless-ng/src";
286286 };
287287+ # Allow the web interface to access the private /tmp directory of the server.
288288+ # This is required to support uploading files via the web interface.
289289+ unitConfig.JoinsNamespaceOf = "paperless-ng-server.service";
287290 # Bind to `paperless-ng-server` so that the web server never runs
288291 # during migrations
289292 bindsTo = [ "paperless-ng-server.service" ];
+12-2
nixos/tests/paperless-ng.nix
···2525 # Wait until server accepts connections
2626 machine.wait_until_succeeds("curl -fs localhost:28981")
27272828- with subtest("Document is consumed"):
2828+ with subtest("Create web test doc"):
2929+ machine.succeed(
3030+ "convert -size 400x40 xc:white -font 'DejaVu-Sans' -pointsize 20 -fill black "
3131+ "-annotate +5+20 'hello web 16-10-2005' /tmp/webdoc.png"
3232+ )
3333+ machine.wait_until_succeeds("curl -u admin:admin -F document=@/tmp/webdoc.png -fs localhost:28981/api/documents/post_document/")
3434+3535+ with subtest("Documents are consumed"):
2936 machine.wait_until_succeeds(
3030- "(($(curl -u admin:admin -fs localhost:28981/api/documents/ | jq .count) == 1))"
3737+ "(($(curl -u admin:admin -fs localhost:28981/api/documents/ | jq .count) == 2))"
3138 )
3239 assert "2005-10-16" in machine.succeed(
3340 "curl -u admin:admin -fs localhost:28981/api/documents/ | jq '.results | .[0] | .created'"
4141+ )
4242+ assert "2005-10-16" in machine.succeed(
4343+ "curl -u admin:admin -fs localhost:28981/api/documents/ | jq '.results | .[1] | .created'"
3444 )
3545 '';
3646})
···11+{ lib, stdenv
22+, fetchurl, perl, gcc
33+, ncurses5
44+, ncurses6, gmp, libiconv, numactl
55+, llvmPackages
66+77+ # minimal = true; will remove files that aren't strictly necessary for
88+ # regular builds and GHC bootstrapping.
99+ # This is "useful" for staying within hydra's output limits for at least the
1010+ # aarch64-linux architecture.
1111+, minimal ? false
1212+}:
1313+1414+# Prebuilt only does native
1515+assert stdenv.targetPlatform == stdenv.hostPlatform;
1616+1717+let
1818+ downloadsUrl = "https://downloads.haskell.org/ghc";
1919+2020+ version = "8.10.5";
2121+2222+ # Information about available bindists that we use in the build.
2323+ #
2424+ # # Bindist library checking
2525+ #
2626+ # The field `archSpecificLibraries` also provides a way for us get notified
2727+ # early when the upstream bindist changes its dependencies (e.g. because a
2828+ # newer Debian version is used that uses a new `ncurses` version).
2929+ #
3030+ # Usage:
3131+ #
3232+ # * You can find the `fileToCheckFor` of libraries by running `readelf -d`
3333+ # on the compiler binary (`exePathForLibraryCheck`).
3434+ # * To skip library checking for an architecture,
3535+ # set `exePathForLibraryCheck = null`.
3636+ # * To skip file checking for a specific arch specfic library,
3737+ # set `fileToCheckFor = null`.
3838+ ghcBinDists = {
3939+ # Binary distributions for the default libc (e.g. glibc, or libSystem on Darwin)
4040+ # nixpkgs uses for the respective system.
4141+ defaultLibc = {
4242+ i686-linux = {
4343+ src = {
4444+ url = "${downloadsUrl}/${version}/ghc-${version}-i386-deb9-linux.tar.xz";
4545+ sha256 = "17cwmhhyz952psmp4j3pkdj0yrfxah3l2dawg5s4hdr228n5pjqc";
4646+ };
4747+ exePathForLibraryCheck = "ghc/stage2/build/tmp/ghc-stage2";
4848+ archSpecificLibraries = [
4949+ # The i686-linux bindist provided by GHC HQ is currently built on Debian 9,
5050+ # which link it against `libtinfo.so.5` (ncurses 5).
5151+ # Other bindists are linked `libtinfo.so.6` (ncurses 6).
5252+ { nixPackage = ncurses5; fileToCheckFor = "libtinfo.so.5"; }
5353+ ];
5454+ };
5555+ x86_64-linux = {
5656+ src = {
5757+ url = "${downloadsUrl}/${version}/ghc-${version}-x86_64-deb10-linux.tar.xz";
5858+ sha256 = "11v76wgljyszc6mgz6r16i6wkifgl15a26q7ablihp2cr8h3qqmw";
5959+ };
6060+ exePathForLibraryCheck = "ghc/stage2/build/tmp/ghc-stage2";
6161+ archSpecificLibraries = [
6262+ { nixPackage = ncurses6; fileToCheckFor = "libtinfo.so.6"; }
6363+ ];
6464+ };
6565+ armv7l-linux = {
6666+ src = {
6767+ url = "${downloadsUrl}/${version}/ghc-${version}-armv7-deb10-linux.tar.xz";
6868+ sha256 = "0v5bvhb2z9j26yr0n9gc4xdq2lm37mr98g62p5z8pqahhhd0s5sn";
6969+ };
7070+ exePathForLibraryCheck = "ghc/stage2/build/tmp/ghc-stage2";
7171+ archSpecificLibraries = [
7272+ { nixPackage = ncurses6; fileToCheckFor = "libtinfo.so.6"; }
7373+ ];
7474+ };
7575+ aarch64-linux = {
7676+ src = {
7777+ url = "${downloadsUrl}/${version}/ghc-${version}-aarch64-deb10-linux.tar.xz";
7878+ sha256 = "1p0dgyn1m2nd8ax1g25lchaz9z2nk9jvyzf63biarq7qlzc5q24s";
7979+ };
8080+ exePathForLibraryCheck = "ghc/stage2/build/tmp/ghc-stage2";
8181+ archSpecificLibraries = [
8282+ { nixPackage = ncurses6; fileToCheckFor = "libtinfo.so.6"; }
8383+ { nixPackage = numactl; fileToCheckFor = null; }
8484+ ];
8585+ };
8686+ x86_64-darwin = {
8787+ src = {
8888+ url = "${downloadsUrl}/${version}/ghc-${version}-x86_64-apple-darwin.tar.xz";
8989+ sha256 = "08javwfqd21kglbr1bnhnbjw2cggz1n668vi8kx5hbcnz3plf3zg";
9090+ };
9191+ exePathForLibraryCheck = null; # we don't have a library check for darwin yet
9292+ archSpecificLibraries = [
9393+ { nixPackage = ncurses6; fileToCheckFor = null; }
9494+ { nixPackage = libiconv; fileToCheckFor = null; }
9595+ ];
9696+ };
9797+ aarch64-darwin = {
9898+ src = {
9999+ url = "${downloadsUrl}/${version}/ghc-${version}-aarch64-apple-darwin.tar.xz";
100100+ sha256 = "02fbcrzcc6m25z3ji867isml38jkg4blry70ljwl3l03zxq4ws03";
101101+ };
102102+ exePathForLibraryCheck = null; # we don't have a library check for darwin yet
103103+ archSpecificLibraries = [
104104+ { nixPackage = ncurses6; fileToCheckFor = null; }
105105+ { nixPackage = libiconv; fileToCheckFor = null; }
106106+ ];
107107+ };
108108+ };
109109+ # Binary distributions for the musl libc for the respective system.
110110+ musl = {
111111+ x86_64-linux = {
112112+ src = {
113113+ url = "${downloadsUrl}/${version}/ghc-${version}-x86_64-alpine3.10-linux-integer-simple.tar.xz";
114114+ sha256 = "1ql2qxywbbv0b9syvrm9kyh5d8midnl676lw4698ajras6gcvmzl";
115115+ };
116116+ exePathForLibraryCheck = "bin/ghc";
117117+ archSpecificLibraries = [
118118+ # In contrast to glibc builds, the musl-bindist uses `libncursesw.so.*`
119119+ # instead of `libtinfo.so.*.`
120120+ { nixPackage = ncurses6; fileToCheckFor = "libncursesw.so.6"; }
121121+ ];
122122+ };
123123+ };
124124+ };
125125+126126+ distSetName = if stdenv.hostPlatform.isMusl then "musl" else "defaultLibc";
127127+128128+ binDistUsed = ghcBinDists.${distSetName}.${stdenv.hostPlatform.system}
129129+ or (throw "cannot bootstrap GHC on this platform ('${stdenv.hostPlatform.system}' with libc '${distSetName}')");
130130+131131+ useLLVM = !stdenv.targetPlatform.isx86;
132132+133133+ libPath =
134134+ lib.makeLibraryPath (
135135+ [
136136+ gmp
137137+ ]
138138+ # Add arch-specific libraries.
139139+ ++ map ({ nixPackage, ... }: nixPackage) binDistUsed.archSpecificLibraries
140140+ );
141141+142142+ libEnvVar = lib.optionalString stdenv.hostPlatform.isDarwin "DY"
143143+ + "LD_LIBRARY_PATH";
144144+145145+in
146146+147147+stdenv.mkDerivation rec {
148148+ inherit version;
149149+150150+ name = "ghc-${version}-binary";
151151+152152+ src = fetchurl binDistUsed.src;
153153+154154+ nativeBuildInputs = [ perl ];
155155+ propagatedBuildInputs =
156156+ lib.optionals useLLVM [ llvmPackages.llvm ]
157157+ # Because musl bindists currently provide no way to tell where
158158+ # libgmp is (see not [musl bindists have no .buildinfo]), we need
159159+ # to propagate `gmp`, otherwise programs built by this ghc will
160160+ # fail linking with `cannot find -lgmp` errors.
161161+ # Also, as of writing, the release pages of musl bindists claim
162162+ # that they use `integer-simple` and do not require `gmp`; however
163163+ # that is incorrect, so `gmp` is required until a release has been
164164+ # made that includes https://gitlab.haskell.org/ghc/ghc/-/issues/20059.
165165+ # (Note that for packaging the `-binary` compiler, nixpkgs does not care
166166+ # about whether or not `gmp` is used; this comment is just here to explain
167167+ # why the `gmp` dependency exists despite what the release page says.)
168168+ ++ lib.optionals stdenv.hostPlatform.isMusl [ gmp ]; # musl bindist needs this
169169+170170+ # Set LD_LIBRARY_PATH or equivalent so that the programs running as part
171171+ # of the bindist installer can find the libraries they expect.
172172+ # Cannot patchelf beforehand due to relative RPATHs that anticipate
173173+ # the final install location.
174174+ ${libEnvVar} = libPath;
175175+176176+ postUnpack =
177177+ # Verify our assumptions of which `libtinfo.so` (ncurses) version is used,
178178+ # so that we know when ghc bindists upgrade that and we need to update the
179179+ # version used in `libPath`.
180180+ lib.optionalString
181181+ (binDistUsed.exePathForLibraryCheck != null)
182182+ # Note the `*` glob because some GHCs have a suffix when unpacked, e.g.
183183+ # the musl bindist has dir `ghc-VERSION-x86_64-unknown-linux/`.
184184+ # As a result, don't shell-quote this glob when splicing the string.
185185+ (let buildExeGlob = ''ghc-${version}*/"${binDistUsed.exePathForLibraryCheck}"''; in
186186+ lib.concatStringsSep "\n" [
187187+ (''
188188+ echo "Checking that ghc binary exists in bindist at ${buildExeGlob}"
189189+ if ! test -e ${buildExeGlob}; then
190190+ echo >&2 "GHC binary ${binDistUsed.exePathForLibraryCheck} could not be found in the bindist build directory (at ${buildExeGlob}) for arch ${stdenv.hostPlatform.system}, please check that ghcBinDists correctly reflect the bindist dependencies!"; exit 1;
191191+ fi
192192+ '')
193193+ (lib.concatMapStringsSep
194194+ "\n"
195195+ ({ fileToCheckFor, nixPackage }:
196196+ lib.optionalString (fileToCheckFor != null) ''
197197+ echo "Checking bindist for ${fileToCheckFor} to ensure that is still used"
198198+ if ! readelf -d ${buildExeGlob} | grep "${fileToCheckFor}"; then
199199+ echo >&2 "File ${fileToCheckFor} could not be found in ${binDistUsed.exePathForLibraryCheck} for arch ${stdenv.hostPlatform.system}, please check that ghcBinDists correctly reflect the bindist dependencies!"; exit 1;
200200+ fi
201201+202202+ echo "Checking that the nix package ${nixPackage} contains ${fileToCheckFor}"
203203+ if ! test -e "${lib.getLib nixPackage}/lib/${fileToCheckFor}"; then
204204+ echo >&2 "Nix package ${nixPackage} did not contain ${fileToCheckFor} for arch ${stdenv.hostPlatform.system}, please check that ghcBinDists correctly reflect the bindist dependencies!"; exit 1;
205205+ fi
206206+ ''
207207+ )
208208+ binDistUsed.archSpecificLibraries
209209+ )
210210+ ])
211211+ # GHC has dtrace probes, which causes ld to try to open /usr/lib/libdtrace.dylib
212212+ # during linking
213213+ + lib.optionalString stdenv.isDarwin ''
214214+ export NIX_LDFLAGS+=" -no_dtrace_dof"
215215+ # not enough room in the object files for the full path to libiconv :(
216216+ for exe in $(find . -type f -executable); do
217217+ isScript $exe && continue
218218+ ln -fs ${libiconv}/lib/libiconv.dylib $(dirname $exe)/libiconv.dylib
219219+ install_name_tool -change /usr/lib/libiconv.2.dylib @executable_path/libiconv.dylib -change /usr/local/lib/gcc/6/libgcc_s.1.dylib ${gcc.cc.lib}/lib/libgcc_s.1.dylib $exe
220220+ done
221221+ '' +
222222+223223+ # Some scripts used during the build need to have their shebangs patched
224224+ ''
225225+ patchShebangs ghc-${version}/utils/
226226+ patchShebangs ghc-${version}/configure
227227+ '' +
228228+ # We have to patch the GMP paths for the integer-gmp package.
229229+ # Note [musl bindists have no .buildinfo]
230230+ # Note that musl bindists do not contain them; unclear if that's intended;
231231+ # see: https://gitlab.haskell.org/ghc/ghc/-/issues/20073#note_363231
232232+ ''
233233+ find . -name integer-gmp.buildinfo \
234234+ -exec sed -i "s@extra-lib-dirs: @extra-lib-dirs: ${gmp.out}/lib@" {} \;
235235+ '' + lib.optionalString stdenv.isDarwin ''
236236+ find . -name base.buildinfo \
237237+ -exec sed -i "s@extra-lib-dirs: @extra-lib-dirs: ${libiconv}/lib@" {} \;
238238+ '' +
239239+ # aarch64 does HAVE_NUMA so -lnuma requires it in library-dirs in rts/package.conf.in
240240+ # FFI_LIB_DIR is a good indication of places it must be needed.
241241+ lib.optionalString (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64) ''
242242+ find . -name package.conf.in \
243243+ -exec sed -i "s@FFI_LIB_DIR@FFI_LIB_DIR ${numactl.out}/lib@g" {} \;
244244+ '' +
245245+ # Rename needed libraries and binaries, fix interpreter
246246+ lib.optionalString stdenv.isLinux ''
247247+ find . -type f -executable -exec patchelf \
248248+ --interpreter ${stdenv.cc.bintools.dynamicLinker} {} \;
249249+ '';
250250+251251+ # fix for `configure: error: Your linker is affected by binutils #16177`
252252+ preConfigure = lib.optionalString
253253+ stdenv.targetPlatform.isAarch32
254254+ "LD=ld.gold";
255255+256256+ configurePlatforms = [ ];
257257+ configureFlags = [
258258+ "--with-gmp-includes=${lib.getDev gmp}/include"
259259+ # Note `--with-gmp-libraries` does nothing for GHC bindists:
260260+ # https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6124
261261+ ] ++ lib.optional stdenv.isDarwin "--with-gcc=${./gcc-clang-wrapper.sh}"
262262+ # From: https://github.com/NixOS/nixpkgs/pull/43369/commits
263263+ ++ lib.optional stdenv.hostPlatform.isMusl "--disable-ld-override";
264264+265265+ # No building is necessary, but calling make without flags ironically
266266+ # calls install-strip ...
267267+ dontBuild = true;
268268+269269+ # Apparently necessary for the ghc Alpine (musl) bindist:
270270+ # When we strip, and then run the
271271+ # patchelf --set-rpath "${libPath}:$(patchelf --print-rpath $p)" $p
272272+ # below, running ghc (e.g. during `installCheckPhase)` gives some apparently
273273+ # corrupted rpath or whatever makes the loader work on nonsensical strings:
274274+ # running install tests
275275+ # Error relocating /nix/store/...-ghc-8.10.2-binary/lib/ghc-8.10.5/bin/ghc: : symbol not found
276276+ # Error relocating /nix/store/...-ghc-8.10.2-binary/lib/ghc-8.10.5/bin/ghc: ir6zf6c9f86pfx8sr30n2vjy-ghc-8.10.2-binary/lib/ghc-8.10.5/bin/../lib/x86_64-linux-ghc-8.10.5/libHSexceptions-0.10.4-ghc8.10.5.so: symbol not found
277277+ # Error relocating /nix/store/...-ghc-8.10.2-binary/lib/ghc-8.10.5/bin/ghc: y/lib/ghc-8.10.5/bin/../lib/x86_64-linux-ghc-8.10.5/libHStemplate-haskell-2.16.0.0-ghc8.10.5.so: symbol not found
278278+ # Error relocating /nix/store/...-ghc-8.10.2-binary/lib/ghc-8.10.5/bin/ghc: 8.10.5/libHStemplate-haskell-2.16.0.0-ghc8.10.5.so: symbol not found
279279+ # Error relocating /nix/store/...-ghc-8.10.2-binary/lib/ghc-8.10.5/bin/ghc: �: symbol not found
280280+ # Error relocating /nix/store/...-ghc-8.10.2-binary/lib/ghc-8.10.5/bin/ghc: �?: symbol not found
281281+ # Error relocating /nix/store/...-ghc-8.10.2-binary/lib/ghc-8.10.5/bin/ghc: 64-linux-ghc-8.10.5/libHSexceptions-0.10.4-ghc8.10.5.so: symbol not found
282282+ # This is extremely bogus and should be investigated.
283283+ dontStrip = if stdenv.hostPlatform.isMusl then true else false; # `if` for explicitness
284284+285285+ # On Linux, use patchelf to modify the executables so that they can
286286+ # find editline/gmp.
287287+ postFixup = lib.optionalString stdenv.isLinux
288288+ (if stdenv.hostPlatform.isAarch64 then
289289+ # Keep rpath as small as possible on aarch64 for patchelf#244. All Elfs
290290+ # are 2 directories deep from $out/lib, so pooling symlinks there makes
291291+ # a short rpath.
292292+ ''
293293+ (cd $out/lib; ln -s ${ncurses6.out}/lib/libtinfo.so.6)
294294+ (cd $out/lib; ln -s ${gmp.out}/lib/libgmp.so.10)
295295+ (cd $out/lib; ln -s ${numactl.out}/lib/libnuma.so.1)
296296+ for p in $(find "$out/lib" -type f -name "*\.so*"); do
297297+ (cd $out/lib; ln -s $p)
298298+ done
299299+300300+ for p in $(find "$out/lib" -type f -executable); do
301301+ if isELF "$p"; then
302302+ echo "Patchelfing $p"
303303+ patchelf --set-rpath "\$ORIGIN:\$ORIGIN/../.." $p
304304+ fi
305305+ done
306306+ ''
307307+ else
308308+ ''
309309+ for p in $(find "$out" -type f -executable); do
310310+ if isELF "$p"; then
311311+ echo "Patchelfing $p"
312312+ patchelf --set-rpath "${libPath}:$(patchelf --print-rpath $p)" $p
313313+ fi
314314+ done
315315+ '') + lib.optionalString stdenv.isDarwin ''
316316+ # not enough room in the object files for the full path to libiconv :(
317317+ for exe in $(find "$out" -type f -executable); do
318318+ isScript $exe && continue
319319+ ln -fs ${libiconv}/lib/libiconv.dylib $(dirname $exe)/libiconv.dylib
320320+ install_name_tool -change /usr/lib/libiconv.2.dylib @executable_path/libiconv.dylib -change /usr/local/lib/gcc/6/libgcc_s.1.dylib ${gcc.cc.lib}/lib/libgcc_s.1.dylib $exe
321321+ done
322322+323323+ for file in $(find "$out" -name setup-config); do
324324+ substituteInPlace $file --replace /usr/bin/ranlib "$(type -P ranlib)"
325325+ done
326326+ '' +
327327+ lib.optionalString minimal ''
328328+ # Remove profiling files
329329+ find $out -type f -name '*.p_o' -delete
330330+ find $out -type f -name '*.p_hi' -delete
331331+ find $out -type f -name '*_p.a' -delete
332332+ # `-f` because e.g. musl bindist does not have this file.
333333+ rm -f $out/lib/ghc-*/bin/ghc-iserv-prof
334334+ # Hydra will redistribute this derivation, so we have to keep the docs for
335335+ # legal reasons (retaining the legal notices etc)
336336+ # As a last resort we could unpack the docs separately and symlink them in.
337337+ # They're in $out/share/{doc,man}.
338338+ '';
339339+340340+ # In nixpkgs, musl based builds currently enable `pie` hardening by default
341341+ # (see `defaultHardeningFlags` in `make-derivation.nix`).
342342+ # But GHC cannot currently produce outputs that are ready for `-pie` linking.
343343+ # Thus, disable `pie` hardening, otherwise `recompile with -fPIE` errors appear.
344344+ # See:
345345+ # * https://github.com/NixOS/nixpkgs/issues/129247
346346+ # * https://gitlab.haskell.org/ghc/ghc/-/issues/19580
347347+ hardeningDisable = lib.optional stdenv.targetPlatform.isMusl "pie";
348348+349349+ doInstallCheck = true;
350350+ installCheckPhase = ''
351351+ unset ${libEnvVar}
352352+ # Sanity check, can ghc create executables?
353353+ cd $TMP
354354+ mkdir test-ghc; cd test-ghc
355355+ cat > main.hs << EOF
356356+ {-# LANGUAGE TemplateHaskell #-}
357357+ module Main where
358358+ main = putStrLn \$([|"yes"|])
359359+ EOF
360360+ $out/bin/ghc --make main.hs || exit 1
361361+ echo compilation ok
362362+ [ $(./main) == "yes" ]
363363+ '';
364364+365365+ passthru = {
366366+ targetPrefix = "";
367367+ enableShared = true;
368368+369369+ # Our Cabal compiler name
370370+ haskellCompilerName = "ghc-${version}";
371371+ };
372372+373373+ meta = rec {
374374+ homepage = "http://haskell.org/ghc";
375375+ description = "The Glasgow Haskell Compiler";
376376+ license = lib.licenses.bsd3;
377377+ # HACK: since we can't encode the libc / abi in platforms, we need
378378+ # to make the platform list dependent on the evaluation platform
379379+ # in order to avoid eval errors with musl which supports less
380380+ # platforms than the default libcs (i. e. glibc / libSystem).
381381+ # This is done for the benefit of Hydra, so `packagePlatforms`
382382+ # won't return any platforms that would cause an evaluation
383383+ # failure for `pkgsMusl.haskell.compiler.ghc8102Binary`, as
384384+ # long as the evaluator runs on a platform that supports
385385+ # `pkgsMusl`.
386386+ platforms = builtins.attrNames ghcBinDists.${distSetName};
387387+ hydraPlatforms = builtins.filter (p: minimal || p != "aarch64-linux") platforms;
388388+ maintainers = with lib.maintainers; [ lostnet ];
389389+ };
390390+}