Last active
January 13, 2017 23:29
-
-
Save proger/15f5dbfd8a0f5124b1d9 to your computer and use it in GitHub Desktop.
stack2nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs ? import (builtins.fetchTarball https://github.com/nixos/nixpkgs-channels/archive/nixos-unstable.tar.gz) {} }: | |
let | |
yaml = ./stack.yaml; | |
cabal2nix = "${pkgs.cabal2nix}/bin/cabal2nix --no-check --no-haddock"; | |
in | |
pkgs.writeScript "build.sh" '' | |
export NIX_PATH=nixpkgs=${pkgs.path} | |
resolver=$(awk '/resolver:/{print $2}' ${yaml} | sed 's,\.,_,g') | |
echo '{ pkgs ? import (builtins.fetchTarball https://github.com/nixos/nixpkgs-channels/archive/nixos-unstable.tar.gz) {} }:' | |
echo ' | |
let | |
inherit (pkgs) lib; | |
hs = pkgs.haskell.packages.'$resolver'.override { overrides = a: b: removeAttrs (overrides a b) ["process"]; }; | |
overrides = self: super: { | |
' | |
for tuple in $(awk -v OFS='#' '/location:/ {l=1;next} l && /git:/ {git=$2;next} l && /commit:/ {commit=$2;next} git && commit && l { print git, commit; l=0}'< ${yaml}); do | |
_IFS=$IFS | |
IFS='#' | |
set -- $tuple | |
IFS=$_IFS | |
f=$(mktemp) | |
cabal2nix --revision $2 $1 > $f | |
name=$(sed -n '/pname/s/pname = "\(.*\)";$/\1/p' $f) | |
printf "%s = self.callPackage (%s) {};\n" $name "$(cat $f)" | |
rm -f $f | |
done | |
sed -n '/^extra-deps:/,/^[^-]/s|^- \(\(.*\)-\([0-9.]\+\)$\)|printf "%s = self.callPackage (%s) {};\\n" \2 "$(${cabal2nix} cabal://\1)"|p' ${yaml} | sh | |
echo '}; | |
this = | |
' | |
${cabal2nix} . | |
echo '; | |
in pkgs.stdenv.lib.overrideDerivation | |
(hs.callPackage this { process = (overrides hs {}).process; }) | |
(drv: { | |
configurePhase = | |
# allow mixing process-1.2 and process-1.3 | |
builtins.replaceStrings ["exit 1"] [": exit 1"] drv.configurePhase; | |
}) | |
' | |
'' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: