about summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorVladimír Čunát <v@cunat.cz>2020-07-29 18:40:28 +0200
committerVladimír Čunát <v@cunat.cz>2020-07-29 18:40:28 +0200
commit60d89e579393e1e5f72c529775773b9fa20925e5 (patch)
tree5d0741bac9746f54b6a42ef949e1634376cba314 /pkgs/build-support
parentcd719c1eae306a6ba1bade46c534bc83fe8f7162 (diff)
parentd807152c69bf2854631ff9b8706478c10b84401b (diff)
Merge branch 'master' into staging
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/emacs/generic.nix10
-rw-r--r--pkgs/build-support/singularity-tools/default.nix1
-rw-r--r--pkgs/build-support/writers/default.nix67
-rw-r--r--pkgs/build-support/writers/test.nix8
4 files changed, 63 insertions, 23 deletions
diff --git a/pkgs/build-support/emacs/generic.nix b/pkgs/build-support/emacs/generic.nix
index 6fa27f0983927..956787ad59e4e 100644
--- a/pkgs/build-support/emacs/generic.nix
+++ b/pkgs/build-support/emacs/generic.nix
@@ -56,6 +56,16 @@ stdenv.mkDerivation ({
   meta = defaultMeta // meta;
 }
 
+// lib.optionalAttrs (emacs.nativeComp or false) {
+
+  LIBRARY_PATH = "${lib.getLib stdenv.cc.libc}/lib";
+
+  postInstall = ''
+    find $out/share/emacs -type f -name '*.el' -print0 | xargs -0 -n 1 -I {} -P $NIX_BUILD_CORES sh -c "emacs --batch -f batch-native-compile {} || true"
+  '';
+
+}
+
 // removeAttrs args [ "buildInputs" "packageRequires"
                       "meta"
                     ])
diff --git a/pkgs/build-support/singularity-tools/default.nix b/pkgs/build-support/singularity-tools/default.nix
index 54749e416ea37..f1d4808e3ccec 100644
--- a/pkgs/build-support/singularity-tools/default.nix
+++ b/pkgs/build-support/singularity-tools/default.nix
@@ -97,6 +97,7 @@ rec {
             cd ..
             mkdir -p /var/singularity/mnt/{container,final,overlay,session,source}
             echo "root:x:0:0:System administrator:/root:/bin/sh" > /etc/passwd
+            echo > /etc/resolv.conf
             TMPDIR=$(pwd -P) singularity build $out ./img
           '');
 
diff --git a/pkgs/build-support/writers/default.nix b/pkgs/build-support/writers/default.nix
index af492d80db01a..4673b4e6cd873 100644
--- a/pkgs/build-support/writers/default.nix
+++ b/pkgs/build-support/writers/default.nix
@@ -22,7 +22,30 @@ rec {
       inherit interpreter;
       contentPath = content;
     }) ''
-      echo "#! $interpreter" > $out
+      # On darwin a script cannot be used as an interpreter in a shebang but
+      # there doesn't seem to be a limit to the size of shebang and multiple
+      # arguments to the interpreter are allowed.
+      if [[ -n "${toString pkgs.stdenvNoCC.isDarwin}" ]] && isScript $interpreter
+      then
+        wrapperInterpreterLine=$(head -1 "$interpreter" | tail -c+3)
+        # Get first word from the line (note: xargs echo remove leading spaces)
+        wrapperInterpreter=$(echo "$wrapperInterpreterLine" | xargs echo | cut -d " " -f1)
+
+        if isScript $wrapperInterpreter
+        then
+          echo "error: passed interpreter ($interpreter) is a script which has another script ($wrapperInterpreter) as an interpreter, which is not supported."
+          exit 1
+        fi
+
+        # This should work as long as wrapperInterpreter is a shell, which is
+        # the case for programs wrapped with makeWrapper, like
+        # python3.withPackages etc.
+        interpreterLine="$wrapperInterpreterLine $interpreter"
+      else
+        interpreterLine=$interpreter
+      fi
+
+      echo "#! $interpreterLine" > $out
       cat "$contentPath" >> $out
       ${optionalString (check != "") ''
         ${check} $out
@@ -227,6 +250,24 @@ rec {
   writePerlBin = name:
     writePerl "/bin/${name}";
 
+  # makePythonWriter takes python and compatible pythonPackages and produces python script writer,
+  # which validates the script with flake8 at build time. If any libraries are specified,
+  # python.withPackages is used as interpreter, otherwise the "bare" python is used.
+  makePythonWriter = python: pythonPackages: name: { libraries ? [], flakeIgnore ? [] }:
+  let
+    ignoreAttribute = optionalString (flakeIgnore != []) "--ignore ${concatMapStringsSep "," escapeShellArg flakeIgnore}";
+  in
+  makeScriptWriter {
+    interpreter =
+      if libraries == []
+      then "${python}/bin/python"
+      else "${python.withPackages (ps: libraries)}/bin/python"
+    ;
+    check = writeDash "python2check.sh" ''
+      exec ${pythonPackages.flake8}/bin/flake8 --show-source ${ignoreAttribute} "$1"
+    '';
+  } name;
+
   # writePython2 takes a name an attributeset with libraries and some python2 sourcecode and
   # returns an executable
   #
@@ -239,17 +280,7 @@ rec {
   #
   #   print Test.a
   # ''
-  writePython2 = name: { libraries ? [], flakeIgnore ? [] }:
-  let
-    py = pkgs.python2.withPackages (ps: libraries);
-    ignoreAttribute = optionalString (flakeIgnore != []) "--ignore ${concatMapStringsSep "," escapeShellArg flakeIgnore}";
-  in
-  makeScriptWriter {
-    interpreter = "${py}/bin/python";
-    check = writeDash "python2check.sh" ''
-      exec ${pkgs.python2Packages.flake8}/bin/flake8 --show-source ${ignoreAttribute} "$1"
-    '';
-  } name;
+  writePython2 = makePythonWriter pkgs.python2 pkgs.python2Packages;
 
   # writePython2Bin takes the same arguments as writePython2 but outputs a directory (like writeScriptBin)
   writePython2Bin = name:
@@ -267,17 +298,7 @@ rec {
   #   """)
   #   print(y[0]['test'])
   # ''
-  writePython3 = name: { libraries ? [], flakeIgnore ? [] }:
-  let
-    py = pkgs.python3.withPackages (ps: libraries);
-    ignoreAttribute = optionalString (flakeIgnore != []) "--ignore ${concatMapStringsSep "," escapeShellArg flakeIgnore}";
-  in
-  makeScriptWriter {
-    interpreter = "${py}/bin/python";
-    check = writeDash "python3check.sh" ''
-      exec ${pkgs.python3Packages.flake8}/bin/flake8 --show-source ${ignoreAttribute} "$1"
-    '';
-  } name;
+  writePython3 = makePythonWriter pkgs.python3 pkgs.python3Packages;
 
   # writePython3Bin takes the same arguments as writePython3 but outputs a directory (like writeScriptBin)
   writePython3Bin = name:
diff --git a/pkgs/build-support/writers/test.nix b/pkgs/build-support/writers/test.nix
index 3cd0a080ae8f9..d284bda43d059 100644
--- a/pkgs/build-support/writers/test.nix
+++ b/pkgs/build-support/writers/test.nix
@@ -152,6 +152,14 @@ let
       """)
       print(y[0]['test'])
     '';
+
+    python2NoLibs = writePython2 "test_python2_no_libs" {} ''
+      print("success")
+    '';
+
+    python3NoLibs = writePython3 "test_python3_no_libs" {} ''
+      print("success")
+    '';
   };