Skip to content

Instantly share code, notes, and snippets.

@stoeffel
Last active December 4, 2019 14:55
Show Gist options
  • Save stoeffel/195e43bf581ed04c41f2354b2fdaf1a0 to your computer and use it in GitHub Desktop.
Save stoeffel/195e43bf581ed04c41f2354b2fdaf1a0 to your computer and use it in GitHub Desktop.
setup nix
pkgs: args:
with pkgs;
let defaultAttrs = rec {
system = builtins.currentSystem;
builder = "${bash}/bin/bash";
args = [ ./builder.sh ];
setup = ./setup.sh;
gcc = clang;
binutils = clang.bintools.bintools_bin;
baseInputs = [
gnutar
gzip
gnumake
coreutils
gawk
gnused
gnugrep
binutils
gcc
findutils
patchelf
];
buildInputs = [];
};
in
derivation ( defaultAttrs // args )
set -e
source $setup
genericBuild
unset PATH
for p in $baseInputs $buildInputs; do
if [ -d $p/bin ]; then
export PATH="$p/bin${PATH:+:}$PATH"
fi
if [ -d $p/include ]; then
export NIX_CFLAGS_COMPILE="-I $p/include${NIX_CFLAGS_COMPILE:+ }$NIX_CFLAGS_COMPILE"
fi
if [ -d $p/lib ]; then
export NIX_LDFLAGS="-rpath $p/lib -L $p/lib${NIX_LDFLAGS:+ }$NIX_LDFLAGS"
fi
done
function unpackPhase() {
tar -xf $src
for d in *; do
if [ -d "$d" ]; then
cd "$d"
break
fi
done
}
function configurePhase() {
./configure --prefix=$out
}
function buildPhase() {
make
}
function installPhase() {
make install
}
function fixupPhase() {
find $out -type f -exec patchelf --shrink-rpath '{}' \; -exec strip '{}' \; 2>/dev/null
}
function genericBuild() {
unpackPhase
configurePhase
buildPhase
installPhase
fixupPhase
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment