summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/emacs/melpa.nix85
-rw-r--r--pkgs/build-support/emacs/melpa2nix.el38
-rwxr-xr-xpkgs/build-support/fetchgit/nix-prefetch-git2
-rw-r--r--pkgs/build-support/fetchpatch/default.nix33
-rw-r--r--pkgs/build-support/rust/default-crate-overrides.nix6
-rw-r--r--pkgs/build-support/setup-hooks/auto-patchelf.sh12
-rw-r--r--pkgs/build-support/vm/default.nix2
7 files changed, 96 insertions, 82 deletions
diff --git a/pkgs/build-support/emacs/melpa.nix b/pkgs/build-support/emacs/melpa.nix
index 3b8a23d8c2a4..f55c91f82c7d 100644
--- a/pkgs/build-support/emacs/melpa.nix
+++ b/pkgs/build-support/emacs/melpa.nix
@@ -1,35 +1,19 @@
 # builder for Emacs packages built for packages.el
 # using MELPA package-build.el
 
-{ lib, stdenv, fetchurl, emacs, texinfo }:
+{ lib, stdenv, fetchurl, fetchFromGitHub, emacs, texinfo }:
 
 with lib;
 
 { pname
 , version
-
-, recipeFile ? null
-
-, files ? null
-, fileSpecs ? [ "*.el" "*.el.in" "dir"
-                "*.info" "*.texi" "*.texinfo"
-                "doc/dir" "doc/*.info" "doc/*.texi" "doc/*.texinfo"
-              ]
-
+, recipe
 , meta ? {}
-
 , ...
 }@args:
 
 let
 
-  packageBuild = fetchurl {
-    url = https://raw.githubusercontent.com/milkypostman/melpa/2b3eb31c077fcaff94b74b757c1ce17650333943/package-build.el;
-    sha256 = "1biwg2pqmmdz5iwqbjdszljazqymvgyyjcnc255nr6qz8mhnx67j";
-  };
-
-  targets = concatStringsSep " " (if files == null then fileSpecs else files);
-
   defaultMeta = {
     homepage = args.src.meta.homepage or "http://melpa.org/#/${pname}";
   };
@@ -37,33 +21,58 @@ let
 in
 
 import ./generic.nix { inherit lib stdenv emacs texinfo; } ({
-  inherit packageBuild;
 
-  buildPhase =
-    if recipeFile == null
-      then ''
-        runHook preBuild
+  melpa = fetchFromGitHub {
+    owner = "melpa";
+    repo = "melpa";
+    rev = "7103313a7c31bb1ebb71419e365cd2e279ee4609";
+    sha256 = "0m10f83ix0mzjk0vjd4kkb1m1p4b8ha0ll2yjsgk9bqjd7fwapqb";
+  };
 
-        export archive=$(emacs --batch -Q -l $packageBuild -l ${./melpa2nix.el} \
-            -f melpa2nix-build-package \
-            ${pname} ${version} ${targets})
+  elpa2nix = ./elpa2nix.el;
+  melpa2nix = ./melpa2nix.el;
 
-        runHook postBuild
-      ''
-      else ''
-        runHook preBuild
+  preUnpack = ''
+    mkdir -p "$NIX_BUILD_TOP/recipes"
+    if [ -n "$recipe" ]; then
+      cp "$recipe" "$NIX_BUILD_TOP/recipes/$pname"
+    fi
 
-        export archive=$(emacs --batch -Q -l $packageBuild -l ${./melpa2nix.el} \
-            -f melpa2nix-build-package-from-recipe \
-            ${recipeFile} ${version})
+    ln -s "$melpa/package-build" "$NIX_BUILD_TOP/package-build"
 
-        runHook postBuild
-      '';
+    mkdir -p "$NIX_BUILD_TOP/packages"
+  '';
+
+  postUnpack = ''
+    mkdir -p "$NIX_BUILD_TOP/working"
+    ln -s "$NIX_BUILD_TOP/$sourceRoot" "$NIX_BUILD_TOP/working/$pname"
+  '';
+
+  buildPhase =
+    ''
+      runHook preBuild
+
+      cd "$NIX_BUILD_TOP"
+
+      emacs --batch -Q \
+          -L "$melpa/package-build" \
+          -l "$melpa2nix" \
+          -f melpa2nix-build-package \
+          $pname $version
+
+      runHook postBuild
+    '';
 
   installPhase = ''
     runHook preInstall
 
-    emacs --batch -Q -l ${./elpa2nix.el} \
+    archive="$NIX_BUILD_TOP/packages/$pname-$version.el"
+    if [ ! -f "$archive" ]; then
+        archive="$NIX_BUILD_TOP/packages/$pname-$version.tar"
+    fi
+
+    emacs --batch -Q \
+        -l "$elpa2nix" \
         -f elpa2nix-install-package \
         "$archive" "$out/share/emacs/site-lisp/elpa"
 
@@ -73,6 +82,4 @@ import ./generic.nix { inherit lib stdenv emacs texinfo; } ({
   meta = defaultMeta // meta;
 }
 
-// removeAttrs args [ "files" "fileSpecs"
-                      "meta"
-                    ])
+// removeAttrs args [ "meta" ])
diff --git a/pkgs/build-support/emacs/melpa2nix.el b/pkgs/build-support/emacs/melpa2nix.el
index 3cd5bbdb954a..99c755e2afcb 100644
--- a/pkgs/build-support/emacs/melpa2nix.el
+++ b/pkgs/build-support/emacs/melpa2nix.el
@@ -1,42 +1,16 @@
 (require 'package)
 (package-initialize)
 
+(require 'package-recipe)
 (require 'package-build)
 
-(setq package-build-working-dir (expand-file-name ".")
-      package-build-archive-dir (expand-file-name "."))
+(setq package-build-working-dir (expand-file-name "working/"))
+(setq package-build-archive-dir (expand-file-name "packages/"))
+(setq package-build-recipes-dir (expand-file-name "recipes/"))
 
 (defun melpa2nix-build-package ()
   (if (not noninteractive)
       (error "`melpa2nix-build-package' is to be used only with -batch"))
   (pcase command-line-args-left
-    (`(,package ,version . ,files)
-     (melpa2nix-package-build-archive package version files))))
-
-(defun melpa2nix-build-package-from-recipe ()
-  (if (not noninteractive)
-      (error "`melpa2nix-build-package' is to be used only with -batch"))
-  (pcase command-line-args-left
-    (`(,recipe-file ,version)
-     (let* ((recipe (package-build--read-from-file recipe-file))
-            (rcp (cdr recipe))
-            (package (car recipe))
-            (files (package-build--config-file-list rcp)))
-       (melpa2nix-package-build-archive package version files)))))
-
-(defun melpa2nix-package-build-archive (name version files)
-  "Build a package archive for package NAME."
-  (package-build--message "\n;;; %s\n" name)
-  (let* ((start-time (current-time))
-         (archive-entry (package-build-package name
-                                               version
-                                               files
-                                               package-build-working-dir
-                                               package-build-archive-dir))
-         (archive-file (package-build--archive-file-name archive-entry)))
-
-    (progn
-      (package-build--message "Built in %.3fs, finished at %s"
-                            (time-to-seconds (time-since start-time))
-                            (current-time-string))
-      (princ (format "%s\n" archive-file)))))
+    (`(,package ,version)
+     (package-build--package (package-recipe-lookup package) version))))
diff --git a/pkgs/build-support/fetchgit/nix-prefetch-git b/pkgs/build-support/fetchgit/nix-prefetch-git
index 3cf4ecc280fe..34dfe67df4bd 100755
--- a/pkgs/build-support/fetchgit/nix-prefetch-git
+++ b/pkgs/build-support/fetchgit/nix-prefetch-git
@@ -185,7 +185,7 @@ init_submodules(){
 
         # checkout each submodule
         hash=$(echo "$l" | awk '{print $1}' | tr -d '-')
-        dir=$(echo "$l" | sed -n 's/^ \{0,1\}[^ ]* \(.*\) ([^ ]*)$/\1/p')
+        dir=$(echo "$l" | sed -n 's/^.[0-9a-f]\+ \(.*[^)]*\)\( (.*)\)\?$/\1/p')
         name=$(
             git config -f .gitmodules --get-regexp submodule\..*\.path |
             sed -n "s,^\(.*\)\.path $dir\$,\\1,p")
diff --git a/pkgs/build-support/fetchpatch/default.nix b/pkgs/build-support/fetchpatch/default.nix
index c185497e6913..40a7675b7ac5 100644
--- a/pkgs/build-support/fetchpatch/default.nix
+++ b/pkgs/build-support/fetchpatch/default.nix
@@ -5,11 +5,15 @@
 # stripLen acts as the -p parameter when applying a patch.
 
 { lib, fetchurl, patchutils }:
-{ stripLen ? 0, extraPrefix ? null, excludes ? [], ... }@args:
+{ stripLen ? 0, extraPrefix ? null, excludes ? [], includes ? [], revert ? false, ... }@args:
 
 fetchurl ({
   postFetch = ''
     tmpfile="$TMPDIR/${args.sha256}"
+    if [ ! -s "$out" ]; then
+      echo "error: Fetched patch file '$out' is empty!" 1>&2
+      exit 1
+    fi
     "${patchutils}/bin/lsdiff" "$out" \
       | sort -u | sed -e 's/[*?]/\\&/g' \
       | xargs -I{} \
@@ -21,10 +25,29 @@ fetchurl ({
            --addnewprefix=b/${extraPrefix} \
         ''} \
         --clean "$out" > "$tmpfile"
+    if [ ! -s "$tmpfile" ]; then
+      echo "error: Normalized patch '$tmpfile' is empty (while the fetched file was not)!" 1>&2
+      echo "Did you maybe fetch a HTML representation of a patch instead of a raw patch?" 1>&2
+      echo "Fetched file was:" 1>&2
+      cat "$out" 1>&2
+      exit 1
+    fi
     ${patchutils}/bin/filterdiff \
       -p1 \
-      ${builtins.toString (builtins.map (x: "-x ${x}") excludes)} \
+      ${builtins.toString (builtins.map (x: "-x ${lib.escapeShellArg x}") excludes)} \
+      ${builtins.toString (builtins.map (x: "-i ${lib.escapeShellArg x}") includes)} \
       "$tmpfile" > "$out"
-    ${args.postFetch or ""}
-  '';
-} // builtins.removeAttrs args ["stripLen" "extraPrefix" "excludes" "postFetch"])
+
+    if [ ! -s "$out" ]; then
+      echo "error: Filtered patch '$out$' is empty (while the original patch file was not)!" 1>&2
+      echo "Check your includes and excludes." 1>&2
+      echo "Normalizd patch file was:" 1>&2
+      cat "$tmpfile" 1>&2
+      exit 1
+    fi
+  '' + lib.optionalString revert ''
+    ${patchutils}/bin/interdiff "$out" /dev/null > "$tmpfile"
+    mv "$tmpfile" "$out"
+  '' + (args.postFetch or "");
+  meta.broken = excludes != [] && includes != [];
+} // builtins.removeAttrs args ["stripLen" "extraPrefix" "excludes" "includes" "revert" "postFetch"])
diff --git a/pkgs/build-support/rust/default-crate-overrides.nix b/pkgs/build-support/rust/default-crate-overrides.nix
index d82a92042307..9d22fcf8be17 100644
--- a/pkgs/build-support/rust/default-crate-overrides.nix
+++ b/pkgs/build-support/rust/default-crate-overrides.nix
@@ -1,5 +1,5 @@
 { stdenv, pkgconfig, curl, darwin, libiconv, libgit2, libssh2,
-  openssl, sqlite, zlib, dbus_libs, dbus-glib, gdk_pixbuf, cairo, python3,
+  openssl, sqlite, zlib, dbus, dbus-glib, gdk_pixbuf, cairo, python3,
   libsodium, postgresql, ... }:
 
 let
@@ -41,10 +41,10 @@ in
   };
 
   dbus = attrs: {
-    buildInputs = [ pkgconfig dbus_libs ];
+    buildInputs = [ pkgconfig dbus ];
   };
   libdbus-sys = attrs: {
-    buildInputs = [ pkgconfig dbus_libs ];
+    buildInputs = [ pkgconfig dbus ];
   };
   gobject-sys = attrs: {
     buildInputs = [ dbus-glib ];
diff --git a/pkgs/build-support/setup-hooks/auto-patchelf.sh b/pkgs/build-support/setup-hooks/auto-patchelf.sh
index f40cdcf4cadf..32fdb1000e27 100644
--- a/pkgs/build-support/setup-hooks/auto-patchelf.sh
+++ b/pkgs/build-support/setup-hooks/auto-patchelf.sh
@@ -172,4 +172,14 @@ autoPatchelf() {
     done
 }
 
-fixupOutputHooks+=(autoPatchelf)
+# XXX: This should ultimately use fixupOutputHooks but we currently don't have
+# a way to enforce the order. If we have $runtimeDependencies set, the setup
+# hook of patchelf is going to ruin everything and strip out those additional
+# RPATHs.
+#
+# So what we do here is basically run in postFixup and emulate the same
+# behaviour as fixupOutputHooks because the setup hook for patchelf is run in
+# fixupOutput and the postFixup hook runs later.
+postFixupHooks+=(
+    'for output in $outputs; do prefix="${!output}" autoPatchelf; done'
+)
diff --git a/pkgs/build-support/vm/default.nix b/pkgs/build-support/vm/default.nix
index 6a6deaa875a7..221e19ca5eda 100644
--- a/pkgs/build-support/vm/default.nix
+++ b/pkgs/build-support/vm/default.nix
@@ -22,7 +22,6 @@ rec {
 
   hd = "vda"; # either "sda" or "vda"
 
-
   initrdUtils = runCommand "initrd-utils"
     { buildInputs = [ nukeReferences ];
       allowedReferences = [ "out" modulesClosure ]; # prevent accidents like glibc being included in the initrd
@@ -35,6 +34,7 @@ rec {
       cp -p ${pkgs.stdenv.glibc.out}/lib/ld-linux*.so.? $out/lib
       cp -p ${pkgs.stdenv.glibc.out}/lib/libc.so.* $out/lib
       cp -p ${pkgs.stdenv.glibc.out}/lib/libm.so.* $out/lib
+      cp -p ${pkgs.stdenv.glibc.out}/lib/libresolv.so.* $out/lib
 
       # Copy BusyBox.
       cp -pd ${pkgs.busybox}/bin/* $out/bin