diff options
| author | Robin Gloster <mail@glob.in> | 2021-05-24 09:55:24 -0500 |
|---|---|---|
| committer | Robin Gloster <mail@glob.in> | 2021-05-24 09:55:24 -0500 |
| commit | 4bc5fbef9d159e143fb7e2c3231932e6e76f667c (patch) | |
| tree | e2198f5c552e0667d838b8ec764ddb3a4d8f6dec /pkgs/build-support | |
| parent | jq: fix build with structured-attrs on darwin (diff) | |
| parent | Merge pull request #123802 from superherointj/package-virtmanager-bugfix (diff) | |
| download | nixpkgs-origin/structured-attrs.tar.gz | |
Merge remote-tracking branch 'upstream/master' into structured-attrsorigin/structured-attrs
Diffstat (limited to 'pkgs/build-support')
22 files changed, 370 insertions, 32 deletions
diff --git a/pkgs/build-support/agda/default.nix b/pkgs/build-support/agda/default.nix index 984d61f1f751..ed7d11a13147 100644 --- a/pkgs/build-support/agda/default.nix +++ b/pkgs/build-support/agda/default.nix @@ -1,6 +1,6 @@ # Builder for Agda packages. -{ stdenv, lib, self, Agda, runCommandNoCC, makeWrapper, writeText, mkShell, ghcWithPackages, nixosTests }: +{ stdenv, lib, self, Agda, runCommandNoCC, makeWrapper, writeText, ghcWithPackages, nixosTests }: with lib.strings; diff --git a/pkgs/build-support/appimage/default.nix b/pkgs/build-support/appimage/default.nix index 7659c9f42a10..3a820853b1fb 100644 --- a/pkgs/build-support/appimage/default.nix +++ b/pkgs/build-support/appimage/default.nix @@ -61,7 +61,7 @@ rec { targetPkgs = pkgs: with pkgs; [ gtk3 bashInteractive - gnome3.zenity + gnome.zenity python2 xorg.xrandr which diff --git a/pkgs/build-support/build-fhs-userenv-bubblewrap/default.nix b/pkgs/build-support/build-fhs-userenv-bubblewrap/default.nix index 1911d08d2a1c..868686bd5c01 100644 --- a/pkgs/build-support/build-fhs-userenv-bubblewrap/default.nix +++ b/pkgs/build-support/build-fhs-userenv-bubblewrap/default.nix @@ -14,6 +14,7 @@ args @ { , unshareNet ? false , unshareUts ? true , unshareCgroup ? true +, dieWithParent ? true , ... }: @@ -22,7 +23,7 @@ let buildFHSEnv = callPackage ./env.nix { }; env = buildFHSEnv (removeAttrs args [ - "runScript" "extraInstallCommands" "meta" "passthru" + "runScript" "extraInstallCommands" "meta" "passthru" "dieWithParent" "unshareUser" "unshareCgroup" "unshareUts" "unshareNet" "unsharePid" "unshareIpc" ]); @@ -30,6 +31,13 @@ let files = [ # NixOS Compatibility "static" + "nix" # mainly for nixUnstable users, but also for access to nix/netrc + # Shells + "bashrc" + "zshenv" + "zshrc" + "zinputrc" + "zprofile" # Users, Groups, NSS "passwd" "group" @@ -136,7 +144,7 @@ let ${lib.optionalString unshareNet "--unshare-net"} ${lib.optionalString unshareUts "--unshare-uts"} ${lib.optionalString unshareCgroup "--unshare-cgroup"} - --die-with-parent + ${lib.optionalString dieWithParent "--die-with-parent"} --ro-bind /nix /nix # Our glibc will look for the cache in its own path in `/nix/store`. # As such, we need a cache to exist there, because pressure-vessel diff --git a/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/pkgs/build-support/cc-wrapper/cc-wrapper.sh index b402893100b0..2e62aef46048 100644 --- a/pkgs/build-support/cc-wrapper/cc-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/cc-wrapper.sh @@ -25,8 +25,9 @@ dontLink=0 nonFlagArgs=0 cc1=0 # shellcheck disable=SC2193 -[[ "@prog@" = *++ ]] && isCpp=1 || isCpp=0 -cppInclude=1 +[[ "@prog@" = *++ ]] && isCxx=1 || isCxx=0 +cxxInclude=1 +cxxLibrary=1 cInclude=1 setDynamicLinker=1 @@ -50,15 +51,15 @@ while (( "$n" < "$nParams" )); do dontLink=1 elif [[ "$p" = -x && "$p2" = *-header ]]; then dontLink=1 - elif [[ "$p" = -x && "$p2" = c++* && "$isCpp" = 0 ]]; then - isCpp=1 + elif [[ "$p" = -x && "$p2" = c++* && "$isCxx" = 0 ]]; then + isCxx=1 elif [ "$p" = -nostdlib ]; then - isCpp=-1 + cxxLibrary=0 elif [ "$p" = -nostdinc ]; then cInclude=0 - cppInclude=0 + cxxInclude=0 elif [ "$p" = -nostdinc++ ]; then - cppInclude=0 + cxxInclude=0 elif [[ "$p" = -static || "$p" = -static-pie ]]; then setDynamicLinker=0 elif [[ "$p" != -?* ]]; then @@ -131,12 +132,13 @@ if [ "$NIX_ENFORCE_NO_NATIVE_@suffixSalt@" = 1 ]; then params=(${rest+"${rest[@]}"}) fi -if [[ "$isCpp" = 1 ]]; then - NIX_CFLAGS_LINK_@suffixSalt@+=" $NIX_CXXSTDLIB_LINK_@suffixSalt@" -fi - -if [[ "$cppInclude" = 1 ]]; then - NIX_CFLAGS_COMPILE_@suffixSalt@+=" $NIX_CXXSTDLIB_COMPILE_@suffixSalt@" +if [[ "$isCxx" = 1 ]]; then + if [[ "$cxxInclude" = 1 ]]; then + NIX_CFLAGS_COMPILE_@suffixSalt@+=" $NIX_CXXSTDLIB_COMPILE_@suffixSalt@" + fi + if [[ "$cxxLibrary" = 1 ]]; then + NIX_CFLAGS_LINK_@suffixSalt@+=" $NIX_CXXSTDLIB_LINK_@suffixSalt@" + fi fi source @out@/nix-support/add-hardening.sh diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index 14317cbe4cc5..36a98a180b3e 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -370,7 +370,7 @@ stdenv.mkDerivation { done '' + optionalString (libcxx.isLLVM or false) ('' - echo "-isystem ${libcxx}/include/c++/v1" >> $out/nix-support/libcxx-cxxflags + echo "-isystem ${lib.getDev libcxx}/include/c++/v1" >> $out/nix-support/libcxx-cxxflags echo "-stdlib=libc++" >> $out/nix-support/libcxx-ldflags '' + lib.optionalString stdenv.targetPlatform.isLinux '' echo "-lc++abi" >> $out/nix-support/libcxx-ldflags @@ -404,7 +404,7 @@ stdenv.mkDerivation { echo "$ccLDFlags" >> $out/nix-support/cc-ldflags echo "$ccCFlags" >> $out/nix-support/cc-cflags '' + optionalString (targetPlatform.isDarwin && (libcxx != null) && (cc.isClang or false)) '' - echo " -L${libcxx}/lib" >> $out/nix-support/cc-ldflags + echo " -L${lib.getLib libcxx}/lib" >> $out/nix-support/cc-ldflags '' ## diff --git a/pkgs/build-support/emacs/wrapper.nix b/pkgs/build-support/emacs/wrapper.nix index fcbf5bcabe6d..571d0eb687ce 100644 --- a/pkgs/build-support/emacs/wrapper.nix +++ b/pkgs/build-support/emacs/wrapper.nix @@ -159,7 +159,7 @@ runCommand (add-to-list 'load-path "$out/share/emacs/site-lisp") (add-to-list 'exec-path "$out/bin") ${optionalString nativeComp '' - (add-to-list 'comp-eln-load-path "$out/share/emacs/native-lisp/") + (add-to-list 'native-comp-eln-load-path "$out/share/emacs/native-lisp/") ''} EOF # Link subdirs.el from the emacs distribution @@ -170,7 +170,7 @@ runCommand ${optionalString nativeComp '' $emacs/bin/emacs --batch \ - --eval "(add-to-list 'comp-eln-load-path \"$out/share/emacs/native-lisp/\")" \ + --eval "(add-to-list 'native-comp-eln-load-path \"$out/share/emacs/native-lisp/\")" \ -f batch-native-compile "$siteStart" "$subdirs" ''} ''; diff --git a/pkgs/build-support/fetchgit/nix-prefetch-git b/pkgs/build-support/fetchgit/nix-prefetch-git index f2df9d9a8693..661e0d674c58 100755 --- a/pkgs/build-support/fetchgit/nix-prefetch-git +++ b/pkgs/build-support/fetchgit/nix-prefetch-git @@ -47,6 +47,7 @@ Options: --deepClone Clone the entire repository. --no-deepClone Make a shallow clone of just the required ref. --leave-dotGit Keep the .git directories. + --fetch-lfs Fetch git Large File Storage (LFS) files. --fetch-submodules Fetch submodules. --builder Clone as fetchgit does, but url, rev, and out option are mandatory. --quiet Only print the final json summary. diff --git a/pkgs/build-support/mkshell/default.nix b/pkgs/build-support/mkshell/default.nix index a70dc0390cb5..7ca4cc23c1d5 100644 --- a/pkgs/build-support/mkshell/default.nix +++ b/pkgs/build-support/mkshell/default.nix @@ -3,18 +3,22 @@ # A special kind of derivation that is only meant to be consumed by the # nix-shell. { - inputsFrom ? [], # a list of derivations whose inputs will be made available to the environment - buildInputs ? [], - nativeBuildInputs ? [], - propagatedBuildInputs ? [], - propagatedNativeBuildInputs ? [], - ... + # a list of packages to add to the shell environment + packages ? [ ] +, # propagate all the inputs from the given derivations + inputsFrom ? [ ] +, buildInputs ? [ ] +, nativeBuildInputs ? [ ] +, propagatedBuildInputs ? [ ] +, propagatedNativeBuildInputs ? [ ] +, ... }@attrs: let mergeInputs = name: lib.concatLists (lib.catAttrs name - ([attrs] ++ inputsFrom)); + ([ attrs ] ++ inputsFrom)); rest = builtins.removeAttrs attrs [ + "packages" "inputsFrom" "buildInputs" "nativeBuildInputs" @@ -26,15 +30,15 @@ in stdenv.mkDerivation ({ name = "nix-shell"; - phases = ["nobuildPhase"]; + phases = [ "nobuildPhase" ]; buildInputs = mergeInputs "buildInputs"; - nativeBuildInputs = mergeInputs "nativeBuildInputs"; + nativeBuildInputs = packages ++ (mergeInputs "nativeBuildInputs"); propagatedBuildInputs = mergeInputs "propagatedBuildInputs"; propagatedNativeBuildInputs = mergeInputs "propagatedNativeBuildInputs"; shellHook = lib.concatStringsSep "\n" (lib.catAttrs "shellHook" - (lib.reverseList inputsFrom ++ [attrs])); + (lib.reverseList inputsFrom ++ [ attrs ])); nobuildPhase = '' echo diff --git a/pkgs/build-support/replace-secret/replace-secret.nix b/pkgs/build-support/replace-secret/replace-secret.nix new file mode 100644 index 000000000000..e04d1aed5f70 --- /dev/null +++ b/pkgs/build-support/replace-secret/replace-secret.nix @@ -0,0 +1,35 @@ +{ stdenv, lib, python3 }: + +stdenv.mkDerivation { + name = "replace-secret"; + buildInputs = [ python3 ]; + phases = [ "installPhase" "checkPhase" ]; + installPhase = '' + install -D ${./replace-secret.py} $out/bin/replace-secret + patchShebangs $out + ''; + doCheck = true; + checkPhase = '' + install -m 0600 ${./test/input_file} long_test + $out/bin/replace-secret "replace this" ${./test/passwd} long_test + $out/bin/replace-secret "and this" ${./test/rsa} long_test + diff ${./test/expected_long_output} long_test + + install -m 0600 ${./test/input_file} short_test + $out/bin/replace-secret "replace this" <(echo "a") short_test + $out/bin/replace-secret "and this" <(echo "b") short_test + diff ${./test/expected_short_output} short_test + ''; + meta = with lib; { + platforms = platforms.all; + maintainers = with maintainers; [ talyz ]; + license = licenses.mit; + description = "Replace a string in one file with a secret from a second file"; + longDescription = '' + Replace a string in one file with a secret from a second file. + + Since the secret is read from a file, it won't be leaked through + '/proc/<pid>/cmdline', unlike when 'sed' or 'replace' is used. + ''; + }; +} diff --git a/pkgs/build-support/replace-secret/replace-secret.py b/pkgs/build-support/replace-secret/replace-secret.py new file mode 100755 index 000000000000..30ff41d491ba --- /dev/null +++ b/pkgs/build-support/replace-secret/replace-secret.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +import argparse +from argparse import RawDescriptionHelpFormatter + +description = """ +Replace a string in one file with a secret from a second file. + +Since the secret is read from a file, it won't be leaked through +'/proc/<pid>/cmdline', unlike when 'sed' or 'replace' is used. +""" + +parser = argparse.ArgumentParser( + description=description, + formatter_class=RawDescriptionHelpFormatter +) +parser.add_argument("string_to_replace", help="the string to replace") +parser.add_argument("secret_file", help="the file containing the secret") +parser.add_argument("file", help="the file to perform the replacement on") +args = parser.parse_args() + +with open(args.secret_file) as sf, open(args.file, 'r+') as f: + old = f.read() + secret = sf.read().strip("\n") + new_content = old.replace(args.string_to_replace, secret) + f.seek(0) + f.write(new_content) + f.truncate() diff --git a/pkgs/build-support/replace-secret/test/expected_long_output b/pkgs/build-support/replace-secret/test/expected_long_output new file mode 100644 index 000000000000..37bd66b905f5 --- /dev/null +++ b/pkgs/build-support/replace-secret/test/expected_long_output @@ -0,0 +1,30 @@ +beginning +middle $6$UcbJUl5g$HRMfKNKsLTfVbcQb.P5o0bmZUfHDYkWseMSuZ8F5jSIGZZcI3Jnit23f8ZeZOGi4KL86HVM9RYqrpYySOu/fl0 not this +-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEAzrru6v5tfwQl6L+rOUjtLo8kbhMUlCLXP7TYngSGrkzPMWe+ +0gB04UAmiPZXfBmvj5fPqYiFjIaEDHE/SD41vJB/RJKKtId2gCAIHhBLkbr+4+60 +yEbLkJci5i4kJC1dt8OKFEzXkaVnwOSgjH+0NwO3bstZ+E70zMXS9+NS71qGsIEb +5J1TnacwW/u6CdFyakLljWOXOR14rLIpiPBBFLf+oZiepjIhlWXWHqsxZOb7zMI0 +T4W5WJ2dwGFsJ8rkYaGZ+A5qzYbi/KmHqaSPaNDsyoi7yJhAhKPByALJU916+8QO +xOnqZxWGki3PDzCslRwW4i3mGbZlBQMnlfbN3QIDAQABAoIBAHDn1W7QkFrLmCy6 +6bf6pVdFZF8d2qJhOPAZRClhTXFKj+pqv+QPzcXr9F/fMr6bhK/G+Oqdnlq2aM4m +16oMF+spe+impEyeo1CsreJFghBQcb9o8qFjUPBiKvROBP0hLcscZ4BYy29HSBgo +harWYEWfqQJA251q+fYQoP0z0WrZKddOZbRRnJ0ICRxAE7IEtDT6EYt8R9oGi2j4 +/rpdW+rYGjW3TcmzdR7lpVMJRLlbMbSdR8n6cI6rnfySygcoE5tFX5t/YZSNbBPg +GebKCbEHYNTTG8bC1qjUyzlbEQ6XYWvFO7HTKU7105XpjYTQFByeo0IVkin0o5KW +t7eQWb0CgYEA6zZUWsYoQ13nXEU6Ky89Q9uhesMfaJ/F2X5ikQSRqRvrR3QR+ULe +eNnCl10O9SiFpR4b5gSbLSHMffxGN60P1nEO4CiIKE+gOii8Kdk5htIJFy/dcZUc +PuPM+zD9/6Is5sAWUZo45bnT6685h6EjM2+6zNZtx/XMjSfWbHaY+HMCgYEA4QAy +6ZEgd6FHnNfM/q2o8XU3d6OCdhcu26u6ydnCalbSpPSKWOi6gnHK4ZnGdryXgIYw +hRkvYINfiONkShYytotIh4YxUbgpwdvJRyKa2ZdWhcMmtFzZOcEVzQTKBasFT74C +Wo0iybZ++XZh3M0+n7oyyx39aR7diZ+/zq6PnG8CgYB8B1QH4cHNdDDRqPd5WhmW +NLQ7xbREOSvc+hYDnkMoxz4TmZL4u1gQpdNEeZ+visSeQvg3HGqvK8lnDaYBKdLW +IxvS+8yAZSx6PoyqDI+XFh4RCf5dLGGOkBTAyB7Hs761lsiuEwK5sHmdJ/LQIBot +v1bjOJb/AA/yxvT8kLUtHQKBgGIA9iwqXJv/EfRNQytDdS0HQ4vHGtJZMr3YRVoa +kcZD3yieo4wqguLCsf4mPv4FE3CWAphW6f39+yTi9xIWLSy56nOtjdnsf7PDCh8E +AbL5amSFJly1fKDda6OLjHt/jKa5Osk6ZIa8CP6cA/BrLfXg4rL6cyDQouqJPMDH +5CHdAoGBAIChjbTyoYvANkoANCK4SuqLUYeiYREfiM3sqHe1xirK1PPHw03ZLITl +ltjo9qE6kPXWcTBVckTKGFlntyCT283FC0/vMmHo8dTdtxF4/wSbkqs3ORuJ3p5J +cNtLYGD3vgwLmg6tTur4U60XN+tYDzWGteez8J9GwTMfKJmuS9af +-----END RSA PRIVATE KEY----- +end diff --git a/pkgs/build-support/replace-secret/test/expected_short_output b/pkgs/build-support/replace-secret/test/expected_short_output new file mode 100644 index 000000000000..3c81b2e2f991 --- /dev/null +++ b/pkgs/build-support/replace-secret/test/expected_short_output @@ -0,0 +1,4 @@ +beginning +middle a not this +b +end diff --git a/pkgs/build-support/replace-secret/test/input_file b/pkgs/build-support/replace-secret/test/input_file new file mode 100644 index 000000000000..1e7eadfaab20 --- /dev/null +++ b/pkgs/build-support/replace-secret/test/input_file @@ -0,0 +1,4 @@ +beginning +middle replace this not this +and this +end diff --git a/pkgs/build-support/replace-secret/test/passwd b/pkgs/build-support/replace-secret/test/passwd new file mode 100644 index 000000000000..68f266226e4a --- /dev/null +++ b/pkgs/build-support/replace-secret/test/passwd @@ -0,0 +1 @@ +$6$UcbJUl5g$HRMfKNKsLTfVbcQb.P5o0bmZUfHDYkWseMSuZ8F5jSIGZZcI3Jnit23f8ZeZOGi4KL86HVM9RYqrpYySOu/fl0 diff --git a/pkgs/build-support/replace-secret/test/rsa b/pkgs/build-support/replace-secret/test/rsa new file mode 100644 index 000000000000..138cc99ed225 --- /dev/null +++ b/pkgs/build-support/replace-secret/test/rsa @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEAzrru6v5tfwQl6L+rOUjtLo8kbhMUlCLXP7TYngSGrkzPMWe+ +0gB04UAmiPZXfBmvj5fPqYiFjIaEDHE/SD41vJB/RJKKtId2gCAIHhBLkbr+4+60 +yEbLkJci5i4kJC1dt8OKFEzXkaVnwOSgjH+0NwO3bstZ+E70zMXS9+NS71qGsIEb +5J1TnacwW/u6CdFyakLljWOXOR14rLIpiPBBFLf+oZiepjIhlWXWHqsxZOb7zMI0 +T4W5WJ2dwGFsJ8rkYaGZ+A5qzYbi/KmHqaSPaNDsyoi7yJhAhKPByALJU916+8QO +xOnqZxWGki3PDzCslRwW4i3mGbZlBQMnlfbN3QIDAQABAoIBAHDn1W7QkFrLmCy6 +6bf6pVdFZF8d2qJhOPAZRClhTXFKj+pqv+QPzcXr9F/fMr6bhK/G+Oqdnlq2aM4m +16oMF+spe+impEyeo1CsreJFghBQcb9o8qFjUPBiKvROBP0hLcscZ4BYy29HSBgo +harWYEWfqQJA251q+fYQoP0z0WrZKddOZbRRnJ0ICRxAE7IEtDT6EYt8R9oGi2j4 +/rpdW+rYGjW3TcmzdR7lpVMJRLlbMbSdR8n6cI6rnfySygcoE5tFX5t/YZSNbBPg +GebKCbEHYNTTG8bC1qjUyzlbEQ6XYWvFO7HTKU7105XpjYTQFByeo0IVkin0o5KW +t7eQWb0CgYEA6zZUWsYoQ13nXEU6Ky89Q9uhesMfaJ/F2X5ikQSRqRvrR3QR+ULe +eNnCl10O9SiFpR4b5gSbLSHMffxGN60P1nEO4CiIKE+gOii8Kdk5htIJFy/dcZUc +PuPM+zD9/6Is5sAWUZo45bnT6685h6EjM2+6zNZtx/XMjSfWbHaY+HMCgYEA4QAy +6ZEgd6FHnNfM/q2o8XU3d6OCdhcu26u6ydnCalbSpPSKWOi6gnHK4ZnGdryXgIYw +hRkvYINfiONkShYytotIh4YxUbgpwdvJRyKa2ZdWhcMmtFzZOcEVzQTKBasFT74C +Wo0iybZ++XZh3M0+n7oyyx39aR7diZ+/zq6PnG8CgYB8B1QH4cHNdDDRqPd5WhmW +NLQ7xbREOSvc+hYDnkMoxz4TmZL4u1gQpdNEeZ+visSeQvg3HGqvK8lnDaYBKdLW +IxvS+8yAZSx6PoyqDI+XFh4RCf5dLGGOkBTAyB7Hs761lsiuEwK5sHmdJ/LQIBot +v1bjOJb/AA/yxvT8kLUtHQKBgGIA9iwqXJv/EfRNQytDdS0HQ4vHGtJZMr3YRVoa +kcZD3yieo4wqguLCsf4mPv4FE3CWAphW6f39+yTi9xIWLSy56nOtjdnsf7PDCh8E +AbL5amSFJly1fKDda6OLjHt/jKa5Osk6ZIa8CP6cA/BrLfXg4rL6cyDQouqJPMDH +5CHdAoGBAIChjbTyoYvANkoANCK4SuqLUYeiYREfiM3sqHe1xirK1PPHw03ZLITl +ltjo9qE6kPXWcTBVckTKGFlntyCT283FC0/vMmHo8dTdtxF4/wSbkqs3ORuJ3p5J +cNtLYGD3vgwLmg6tTur4U60XN+tYDzWGteez8J9GwTMfKJmuS9af +-----END RSA PRIVATE KEY----- diff --git a/pkgs/build-support/rust/default-crate-overrides.nix b/pkgs/build-support/rust/default-crate-overrides.nix index 3d2dc3733c22..61cec2a6abab 100644 --- a/pkgs/build-support/rust/default-crate-overrides.nix +++ b/pkgs/build-support/rust/default-crate-overrides.nix @@ -92,7 +92,7 @@ in nettle-sys = attrs: { nativeBuildInputs = [ pkg-config ]; buildInputs = [ nettle clang ]; - LIBCLANG_PATH = "${llvmPackages.libclang}/lib"; + LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib"; }; openssl = attrs: { diff --git a/pkgs/build-support/trivial-builders.nix b/pkgs/build-support/trivial-builders.nix index fb162ed87c98..a75a4555de2b 100644 --- a/pkgs/build-support/trivial-builders.nix +++ b/pkgs/build-support/trivial-builders.nix @@ -431,6 +431,35 @@ rec { done < graph ''; + /* + Write the set of references to a file, that is, their immediate dependencies. + + This produces the equivalent of `nix-store -q --references`. + */ + writeDirectReferencesToFile = path: runCommand "runtime-references" + { + exportReferencesGraph = ["graph" path]; + inherit path; + } + '' + touch ./references + while read p; do + read dummy + read nrRefs + if [[ $p == $path ]]; then + for ((i = 0; i < nrRefs; i++)); do + read ref; + echo $ref >>./references + done + else + for ((i = 0; i < nrRefs; i++)); do + read ref; + done + fi + done < graph + sort ./references >$out + ''; + /* Print an error message if the file with the specified name and * hash doesn't exist in the Nix store. This function should only @@ -534,4 +563,37 @@ rec { phases = "unpackPhase patchPhase installPhase"; installPhase = "cp -R ./ $out"; }; + + /* Checks the command output contains the specified version + * + * Although simplistic, this test assures that the main program + * can run. While there's no substitute for a real test case, + * it does catch dynamic linking errors and such. It also provides + * some protection against accidentally building the wrong version, + * for example when using an 'old' hash in a fixed-output derivation. + * + * Examples: + * + * passthru.tests.version = testVersion { package = hello; }; + * + * passthru.tests.version = testVersion { + * package = seaweedfs; + * command = "weed version"; + * }; + * + * passthru.tests.version = testVersion { + * package = key; + * command = "KeY --help"; + * # Wrong '2.5' version in the code. Drop on next version. + * version = "2.5"; + * }; + */ + testVersion = + { package, + command ? "${package.meta.mainProgram or package.pname or package.name} --version", + version ? package.version, + }: runCommand "test-version" { nativeBuildInputs = [ package ]; meta.timeout = 60; } '' + ${command} | grep -Fw ${version} + touch $out + ''; } diff --git a/pkgs/build-support/trivial-builders/test.nix b/pkgs/build-support/trivial-builders/test.nix new file mode 100644 index 000000000000..204fb54fca3d --- /dev/null +++ b/pkgs/build-support/trivial-builders/test.nix @@ -0,0 +1,53 @@ +{ lib, nixosTest, pkgs, writeText, hello, figlet, stdenvNoCC }: + +# -------------------------------------------------------------------------- # +# +# trivial-builders test +# +# -------------------------------------------------------------------------- # +# +# This file can be run independently (quick): +# +# $ pkgs/build-support/trivial-builders/test.sh +# +# or in the build sandbox with a ~20s VM overhead +# +# $ nix-build -A tests.trivial-builders +# +# -------------------------------------------------------------------------- # + +let + invokeSamples = file: + lib.concatStringsSep " " ( + lib.attrValues (import file { inherit pkgs; }) + ); +in +nixosTest { + name = "nixpkgs-trivial-builders"; + nodes.machine = { ... }: { + virtualisation.writableStore = true; + + # Test runs without network, so we don't substitute and prepare our deps + nix.binaryCaches = lib.mkForce []; + environment.etc."pre-built-paths".source = writeText "pre-built-paths" ( + builtins.toJSON [hello figlet stdenvNoCC] + ); + environment.variables = { + SAMPLE = invokeSamples ./test/sample.nix; + REFERENCES = invokeSamples ./test/invoke-writeReferencesToFile.nix; + DIRECT_REFS = invokeSamples ./test/invoke-writeDirectReferencesToFile.nix; + }; + }; + testScript = '' + machine.succeed(""" + ${./test.sh} 2>/dev/console + """) + ''; + meta = { + license = lib.licenses.mit; # nixpkgs license + maintainers = with lib.maintainers; [ + roberth + ]; + description = "Run the Nixpkgs trivial builders tests"; + }; +} diff --git a/pkgs/build-support/trivial-builders/test.sh b/pkgs/build-support/trivial-builders/test.sh new file mode 100755 index 000000000000..b7c4726a9be0 --- /dev/null +++ b/pkgs/build-support/trivial-builders/test.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +# -------------------------------------------------------------------------- # +# +# trivial-builders test +# +# -------------------------------------------------------------------------- # +# +# This file can be run independently (quick): +# +# $ pkgs/build-support/trivial-builders/test.sh +# +# or in the build sandbox with a ~20s VM overhead +# +# $ nix-build -A tests.trivial-builders +# +# -------------------------------------------------------------------------- # + +# strict bash +set -euo pipefail + +# debug +# set -x +# PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' + +cd "$(dirname ${BASH_SOURCE[0]})" # nixpkgs root + +if [[ -z ${SAMPLE:-} ]]; then + sample=( `nix-build test/sample.nix` ) + directRefs=( `nix-build test/invoke-writeDirectReferencesToFile.nix` ) + references=( `nix-build test/invoke-writeReferencesToFile.nix` ) +else + # Injected by Nix (to avoid evaluating in a derivation) + # turn them into arrays + sample=($SAMPLE) + directRefs=($DIRECT_REFS) + references=($REFERENCES) +fi + +echo >&2 Testing direct references... +for i in "${!sample[@]}"; do + echo >&2 Checking '#'$i ${sample[$i]} ${directRefs[$i]} + diff -U3 \ + <(sort <${directRefs[$i]}) \ + <(nix-store -q --references ${sample[$i]} | sort) +done + +echo >&2 Testing closure... +for i in "${!sample[@]}"; do + echo >&2 Checking '#'$i ${sample[$i]} ${references[$i]} + diff -U3 \ + <(sort <${references[$i]}) \ + <(nix-store -q --requisites ${sample[$i]} | sort) +done + +echo 'OK!' diff --git a/pkgs/build-support/trivial-builders/test/invoke-writeDirectReferencesToFile.nix b/pkgs/build-support/trivial-builders/test/invoke-writeDirectReferencesToFile.nix new file mode 100644 index 000000000000..ead3f7a2f571 --- /dev/null +++ b/pkgs/build-support/trivial-builders/test/invoke-writeDirectReferencesToFile.nix @@ -0,0 +1,4 @@ +{ pkgs ? import ../../../.. { config = {}; overlays = []; } }: +pkgs.lib.mapAttrs + (k: v: pkgs.writeDirectReferencesToFile v) + (import ./sample.nix { inherit pkgs; }) diff --git a/pkgs/build-support/trivial-builders/test/invoke-writeReferencesToFile.nix b/pkgs/build-support/trivial-builders/test/invoke-writeReferencesToFile.nix new file mode 100644 index 000000000000..99c6c2f7dcc4 --- /dev/null +++ b/pkgs/build-support/trivial-builders/test/invoke-writeReferencesToFile.nix @@ -0,0 +1,4 @@ +{ pkgs ? import ../../../.. { config = {}; overlays = []; } }: +pkgs.lib.mapAttrs + (k: v: pkgs.writeReferencesToFile v) + (import ./sample.nix { inherit pkgs; }) diff --git a/pkgs/build-support/trivial-builders/test/sample.nix b/pkgs/build-support/trivial-builders/test/sample.nix new file mode 100644 index 000000000000..060be011093a --- /dev/null +++ b/pkgs/build-support/trivial-builders/test/sample.nix @@ -0,0 +1,15 @@ +{ pkgs ? import ../../../.. { config = {}; overlays = []; } }: +let + inherit (pkgs) + figlet + hello + writeText + ; +in +{ + hello = hello; + figlet = figlet; + norefs = writeText "hi" "hello"; + helloRef = writeText "hi" "hello ${hello}"; + helloFigletRef = writeText "hi" "hello ${hello} ${figlet}"; +} |
