Skip to content

Instantly share code, notes, and snippets.

@tfc
Forked from lucabrunox/autotools.nix
Last active May 11, 2024 18:59
Show Gist options
  • Save tfc/ca800a444b029e85a14e530c25f8e872 to your computer and use it in GitHub Desktop.
Save tfc/ca800a444b029e85a14e530c25f8e872 to your computer and use it in GitHub Desktop.
Nix pill 12
pkgs: attrs:
with pkgs;
let defaultAttrs = {
builder = "${bash}/bin/bash";
args = [ ./builder.sh ];
setup = ./setup.sh;
baseInputs = [ gnutar gzip gnumake gcc binutils-unwrapped coreutils gawk gnused gnugrep patchelf findutils ];
buildInputs = [];
system = builtins.currentSystem;
};
in
derivation (defaultAttrs // attrs)
set -e
source $setup
genericBuild
let
pkgs = import <nixpkgs> {};
mkDerivation = import ./autotools.nix pkgs;
in with pkgs; {
hello = import ./hello.nix { inherit mkDerivation; };
graphviz = import ./graphviz.nix { inherit mkDerivation lib gd pkg-config; };
graphvizCore = import ./graphviz.nix {
inherit mkDerivation lib gd pkg-config;
gdSupport = false;
};
}
{ mkDerivation, lib, gdSupport ? true, gd, pkg-config }:
mkDerivation {
name = "graphviz";
src = ./graphviz-2.49.3.tar.gz;
buildInputs =
if gdSupport
then [
pkg-config
(lib.getLib gd)
(lib.getDev gd)
]
else [];
}
{ mkDerivation }:
mkDerivation {
name = "hello";
src = ./hello-2.10.tar.gz;
}
unset PATH
for p in $baseInputs $buildInputs; do
if [ -d $p/bin ]; then
export PATH="$p/bin${PATH:+:}$PATH"
fi
if [ -d $p/lib/pkgconfig ]; then
export PKG_CONFIG_PATH="$p/lib/pkgconfig${PKG_CONFIG_PATH:+:}$PKG_CONFIG_PATH"
fi
done
function unpackPhase() {
tar -xzf $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
}
@lexun
Copy link

lexun commented Sep 18, 2022

For folks on a mac that just want to get through the examples, an alternative to a mac adaptation would be just running it in docker. I found this to work:

docker run -it -v $(pwd):/pills nixos/nix:master bash
cd pills
nix-build -A hello
result/bin/hello

@unennhexium
Copy link

I can't check if this launch successfully on Mac, but for the reference. The 8th pill contains recommendations for Darwin (MacOS) users. In accordance with it, you need at least to change autotools.nix as follows:

  • replace gcc with clang
  • replace binutils-unwrapped with clang.bintools.bintools_bin):
pkgs: attrs:
  with pkgs;
  let defaultAttrs = {
    builder = "${bash}/bin/bash";
    args = [ ./builder.sh ];
    setup = ./setup.sh;
    baseInputs = [
        gnutar gzip gawk
        gnused gnugrep
        gnumake coreutils
        patchelf findutils
    ];
    gcc = pkgs.clang;
    bintools = pkgs.clang.bintools.bintools_bin;
    buildInputs = [];
    system = builtins.currentSystem;
  };
  in
  derivation (defaultAttrs // attrs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment