Skip to content
This repository was archived by the owner on Apr 12, 2021. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nixpkgs-channels
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c7f415b52250
Choose a base ref
...
head repository: NixOS/nixpkgs-channels
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c5f141ff7a64
Choose a head ref
  • 8 commits
  • 18 files changed
  • 4 contributors

Commits on Mar 12, 2018

  1. Verified

    This commit was signed with the committer’s verified signature.
    NeQuissimus Tim Steinbach
    Copy the full SHA
    21126a8 View commit details
  2. nodePackages: fix evaluation

    Introduced in 40e3ad6.
    fpletz committed Mar 12, 2018
    Copy the full SHA
    1bb0ecd View commit details

Commits on Mar 13, 2018

  1. Copy the full SHA
    a0f10b5 View commit details
  2. Copy the full SHA
    b47b4f3 View commit details
  3. Copy the full SHA
    12010f6 View commit details
  4. fetchurl: remove broken samba mirror

    (cherry picked from commit 4f17851)
    fpletz committed Mar 13, 2018
    Copy the full SHA
    f5eea91 View commit details
  5. Copy the full SHA
    8e5814b View commit details
  6. setup-hooks: Add autoPatchelfHook

    I originally wrote this for packaging proprietary games in Vuizvui[1]
    but I thought it would be generally useful as we have a fair amount of
    proprietary software lurking around in nixpkgs, which are a bit tedious
    to maintain, especially when the library dependencies change after an
    update.
    
    So this setup hook searches for all ELF executables and libraries in the
    resulting output paths after install phase and uses patchelf to set the
    RPATH and interpreter according to what dependencies are available
    inside the builder.
    
    For example consider something like this:
    
    stdenv.mkDerivation {
      ...
      nativeBuildInputs = [ autoPatchelfHook ];
      buildInputs = [ mesa zlib ];
      ...
    }
    
    Whenever for example an executable requires mesa or zlib, the RPATH will
    automatically be set to the lib dir of the corresponding dependency.
    
    If the library dependency is required at runtime, an attribute called
    runtimeDependencies can be used to list dependencies that are added to
    all executables that are discovered unconditionally.
    
    Beside this, it also makes initial packaging of proprietary software
    easier, because one no longer has to manually figure out the
    dependencies in the first place.
    
    [1]: https://github.com/openlab-aux/vuizvui
    
    Signed-off-by: aszlig <aszlig@nix.build>
    Closes: #34506
    (cherry picked from commit 1cba74d)
    aszlig authored and bjornfor committed Mar 13, 2018
    Copy the full SHA
    c5f141f View commit details
14 changes: 14 additions & 0 deletions doc/stdenv.xml
Original file line number Diff line number Diff line change
@@ -1481,6 +1481,20 @@ someVar=$(stripHash $name)
disabled or patched to work with PaX.</para></listitem>
</varlistentry>

<varlistentry>
<term>autoPatchelfHook</term>
<listitem><para>This is a special setup hook which helps in packaging
proprietary software in that it automatically tries to find missing shared
library dependencies of ELF files. All packages within the
<envar>runtimeDependencies</envar> environment variable are unconditionally
added to executables, which is useful for programs that use
<citerefentry>
<refentrytitle>dlopen</refentrytitle>
<manvolnum>3</manvolnum>
</citerefentry>
to load libraries at runtime.</para></listitem>
</varlistentry>

</variablelist>

</para>
2 changes: 1 addition & 1 deletion pkgs/build-support/fetchurl/mirrors.nix
Original file line number Diff line number Diff line change
@@ -129,7 +129,7 @@ rec {

samba = [
https://www.samba.org/ftp/
http://ftp.riken.jp/net/samba
http://www.samba.org/ftp/
];

# BitlBee mirrors, see https://www.bitlbee.org/main.php/mirrors.html .
174 changes: 174 additions & 0 deletions pkgs/build-support/setup-hooks/auto-patchelf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
declare -a autoPatchelfLibs

gatherLibraries() {
autoPatchelfLibs+=("$1/lib")
}

addEnvHooks "$targetOffset" gatherLibraries

isExecutable() {
[ "$(file -b -N --mime-type "$1")" = application/x-executable ]
}

findElfs() {
find "$1" -type f -exec "$SHELL" -c '
while [ -n "$1" ]; do
mimeType="$(file -b -N --mime-type "$1")"
if [ "$mimeType" = application/x-executable \
-o "$mimeType" = application/x-sharedlib ]; then
echo "$1"
fi
shift
done
' -- {} +
}

# We cache dependencies so that we don't need to search through all of them on
# every consecutive call to findDependency.
declare -a cachedDependencies

addToDepCache() {
local existing
for existing in "${cachedDependencies[@]}"; do
if [ "$existing" = "$1" ]; then return; fi
done
cachedDependencies+=("$1")
}

declare -gi depCacheInitialised=0
declare -gi doneRecursiveSearch=0
declare -g foundDependency

getDepsFromSo() {
ldd "$1" 2> /dev/null | sed -n -e 's/[^=]*=> *\(.\+\) \+([^)]*)$/\1/p'
}

populateCacheWithRecursiveDeps() {
local so found foundso
for so in "${cachedDependencies[@]}"; do
for found in $(getDepsFromSo "$so"); do
local libdir="${found%/*}"
local base="${found##*/}"
local soname="${base%.so*}"
for foundso in "${found%/*}/$soname".so*; do
addToDepCache "$foundso"
done
done
done
}

getSoArch() {
objdump -f "$1" | sed -ne 's/^architecture: *\([^,]\+\).*/\1/p'
}

# NOTE: If you want to use this function outside of the autoPatchelf function,
# keep in mind that the dependency cache is only valid inside the subshell
# spawned by the autoPatchelf function, so invoking this directly will possibly
# rebuild the dependency cache. See the autoPatchelf function below for more
# information.
findDependency() {
local filename="$1"
local arch="$2"
local lib dep

if [ $depCacheInitialised -eq 0 ]; then
for lib in "${autoPatchelfLibs[@]}"; do
for so in "$lib/"*.so*; do addToDepCache "$so"; done
done
depCacheInitialised=1
fi

for dep in "${cachedDependencies[@]}"; do
if [ "$filename" = "${dep##*/}" ]; then
if [ "$(getSoArch "$dep")" = "$arch" ]; then
foundDependency="$dep"
return 0
fi
fi
done

# Populate the dependency cache with recursive dependencies *only* if we
# didn't find the right dependency so far and afterwards run findDependency
# again, but this time with $doneRecursiveSearch set to 1 so that it won't
# recurse again (and thus infinitely).
if [ $doneRecursiveSearch -eq 0 ]; then
populateCacheWithRecursiveDeps
doneRecursiveSearch=1
findDependency "$filename" "$arch" || return 1
return 0
fi
return 1
}

autoPatchelfFile() {
local dep rpath="" toPatch="$1"

local interpreter="$(< "$NIX_CC/nix-support/dynamic-linker")"
if isExecutable "$toPatch"; then
patchelf --set-interpreter "$interpreter" "$toPatch"
if [ -n "$runtimeDependencies" ]; then
for dep in $runtimeDependencies; do
rpath="$rpath${rpath:+:}$dep/lib"
done
fi
fi

echo "searching for dependencies of $toPatch" >&2

# We're going to find all dependencies based on ldd output, so we need to
# clear the RPATH first.
patchelf --remove-rpath "$toPatch"

local missing="$(
ldd "$toPatch" 2> /dev/null | \
sed -n -e 's/^[\t ]*\([^ ]\+\) => not found.*/\1/p'
)"

# This ensures that we get the output of all missing dependencies instead
# of failing at the first one, because it's more useful when working on a
# new package where you don't yet know its dependencies.
local -i depNotFound=0

for dep in $missing; do
echo -n " $dep -> " >&2
if findDependency "$dep" "$(getSoArch "$toPatch")"; then
rpath="$rpath${rpath:+:}${foundDependency%/*}"
echo "found: $foundDependency" >&2
else
echo "not found!" >&2
depNotFound=1
fi
done

# This makes sure the builder fails if we didn't find a dependency, because
# the stdenv setup script is run with set -e. The actual error is emitted
# earlier in the previous loop.
[ $depNotFound -eq 0 ]

if [ -n "$rpath" ]; then
echo "setting RPATH to: $rpath" >&2
patchelf --set-rpath "$rpath" "$toPatch"
fi
}

autoPatchelf() {
echo "automatically fixing dependencies for ELF files" >&2

# Add all shared objects of the current output path to the start of
# cachedDependencies so that it's choosen first in findDependency.
cachedDependencies+=(
$(find "$prefix" \! -type d \( -name '*.so' -o -name '*.so.*' \))
)
local elffile

# Here we actually have a subshell, which also means that
# $cachedDependencies is final at this point, so whenever we want to run
# findDependency outside of this, the dependency cache needs to be rebuilt
# from scratch, so keep this in mind if you want to run findDependency
# outside of this function.
findElfs "$prefix" | while read -r elffile; do
autoPatchelfFile "$elffile"
done
}

fixupOutputHooks+=(autoPatchelf)
3 changes: 2 additions & 1 deletion pkgs/development/node-packages/composition-v4.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file has been generated by node2nix 1.5.2. Do not edit!
# This file has been generated by node2nix 1.5.3. Do not edit!

{pkgs ? import <nixpkgs> {
inherit system;
@@ -8,6 +8,7 @@ let
nodeEnv = import ./node-env.nix {
inherit (pkgs) stdenv python2 utillinux runCommand writeTextFile;
inherit nodejs;
libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null;
};
in
import ./node-packages-v4.nix {
3 changes: 2 additions & 1 deletion pkgs/development/node-packages/composition-v6.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file has been generated by node2nix 1.5.2. Do not edit!
# This file has been generated by node2nix 1.5.3. Do not edit!

{pkgs ? import <nixpkgs> {
inherit system;
@@ -8,6 +8,7 @@ let
nodeEnv = import ./node-env.nix {
inherit (pkgs) stdenv python2 utillinux runCommand writeTextFile;
inherit nodejs;
libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null;
};
in
import ./node-packages-v6.nix {
3 changes: 2 additions & 1 deletion pkgs/development/node-packages/composition-v8.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file has been generated by node2nix 1.5.2. Do not edit!
# This file has been generated by node2nix 1.5.3. Do not edit!

{pkgs ? import <nixpkgs> {
inherit system;
@@ -8,6 +8,7 @@ let
nodeEnv = import ./node-env.nix {
inherit (pkgs) stdenv python2 utillinux runCommand writeTextFile;
inherit nodejs;
libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null;
};
in
import ./node-packages-v8.nix {
12 changes: 9 additions & 3 deletions pkgs/development/node-packages/node-env.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file originates from node2nix

{stdenv, nodejs, python2, utillinux, runCommand, writeTextFile}:
{stdenv, nodejs, python2, utillinux, libtool, runCommand, writeTextFile}:

let
python = if nodejs ? python then nodejs.python else python2;
@@ -316,7 +316,10 @@ let
in
stdenv.lib.makeOverridable stdenv.mkDerivation (builtins.removeAttrs args [ "dependencies" ] // {
name = "node-${name}-${version}";
buildInputs = [ tarWrapper python nodejs ] ++ stdenv.lib.optional (stdenv.isLinux) utillinux ++ args.buildInputs or [];
buildInputs = [ tarWrapper python nodejs ]
++ stdenv.lib.optional (stdenv.isLinux) utillinux
++ stdenv.lib.optional (stdenv.isDarwin) libtool
++ args.buildInputs or [];
dontStrip = args.dontStrip or true; # Striping may fail a build for some package deployments

inherit dontNpmInstall preRebuild;
@@ -413,7 +416,10 @@ let
nodeDependencies = stdenv.mkDerivation {
name = "node-dependencies-${name}-${version}";

buildInputs = [ tarWrapper python nodejs ] ++ stdenv.lib.optional (stdenv.isLinux) utillinux ++ args.buildInputs or [];
buildInputs = [ tarWrapper python nodejs ]
++ stdenv.lib.optional (stdenv.isLinux) utillinux
++ stdenv.lib.optional (stdenv.isDarwin) libtool
++ args.buildInputs or [];

includeScript = includeDependencies { inherit dependencies; };
pinpointDependenciesScript = pinpointDependenciesOfPackage args;
Loading