From 8901a019310bb5471024a5a9a4a4756a85dc1f96 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Tue, 7 May 2019 14:06:17 +1200 Subject: [PATCH 01/12] Add cabalProjectToNix --- default.nix | 37 ++++++++++++++++++++++++++++++++----- lib/cabalProjectToNix.nix | 28 ++++++++++++++++++++++++++++ lib/callHackageToNix.nix | 5 +++++ lib/hackageIndex.nix | 16 ++++++++++++++++ 4 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 lib/cabalProjectToNix.nix create mode 100644 lib/callHackageToNix.nix create mode 100644 lib/hackageIndex.nix diff --git a/default.nix b/default.nix index 20c57fd093..fa43afce22 100644 --- a/default.nix +++ b/default.nix @@ -6,6 +6,8 @@ # It's also possible to override these sources with NIX_PATH. , hackageSourceJSON ? ./hackage-src.json , stackageSourceJSON ? ./stackage-src.json +, hackageIndexState ? null +, recentNixpkgs ? import {} }: let @@ -38,12 +40,24 @@ let # overridden with NIX_PATH. fetchExternal = import ./lib/fetch-external.nix; + hackageIndex = import ./lib/hackageIndex.nix { + inherit (pkgs) runCommand; + inherit (recentNixpkgs) cabal-install; + indexState = hackageIndexState; + }; + # All packages from Hackage as Nix expressions - hackage = import (fetchExternal { - name = "hackage-exprs-source"; - specJSON = hackageSourceJSON; - override = "hackage"; - }); + hackage = if hackageIndexState == null + then import (fetchExternal { + name = "hackage-exprs-source"; + specJSON = hackageSourceJSON; + override = "hackage"; + }) + else import (import ./lib/callHackageToNix.nix { + inherit (pkgs) runCommand; + inherit (import ./. {}) nix-tools; + inherit hackageIndex; + }); # The set of all Stackage snapshots stackage = import (fetchExternal { @@ -123,6 +137,19 @@ let update-stackage = self.callPackage ./scripts/update-stackage.nix {}; update-pins = self.callPackage ./scripts/update-pins.nix {}; }; + + # Make this handy overridable fetch function available. + inherit fetchExternal; + + # Takes a haskell src directory runs cabal new-configure and plan-to-nix. + # Resulting nix files are added to nix-plan subdirectory. + cabalProjectToNix = import ./lib/cabalProjectToNix.nix { + inherit pkgs hackageIndex; + inherit (pkgs) runCommand; + inherit (recentNixpkgs) cabal-install ghc; + inherit (recentNixpkgs.haskellPackages) hpack; + inherit (import ./. {}) nix-tools; + }; }); in diff --git a/lib/cabalProjectToNix.nix b/lib/cabalProjectToNix.nix new file mode 100644 index 0000000000..ad0556e71a --- /dev/null +++ b/lib/cabalProjectToNix.nix @@ -0,0 +1,28 @@ +{ pkgs, runCommand, nix-tools, cabal-install +, hackageIndex, ghc, hpack +} : +{src} : +let + cabalFiles = + builtins.filterSource (path: type: + type == "directory" || + pkgs.lib.any (i: (pkgs.lib.hasSuffix i path)) [ ".project" ".cabal" "package.yaml" ]) + src; + plan = runCommand "plan" { + buildInputs = [ ghc hpack ]; + } '' + tmp=$(mktemp -d) + cd $tmp + cp -r ${cabalFiles}/* . + chmod +w -R . + find . -name package.yaml -exec hpack "{}" \; + HOME=${hackageIndex} ${cabal-install}/bin/cabal new-configure + HOME=$out ${nix-tools}/bin/plan-to-nix --plan-json dist-newstyle/cache/plan.json -o nix-plan + cp -r nix-plan $out + ''; +in + runCommand "plan-and-src" {} '' + mkdir $out + cp -r ${src}/* $out + ln -sf ${plan} $out/nix-plan + '' diff --git a/lib/callHackageToNix.nix b/lib/callHackageToNix.nix new file mode 100644 index 0000000000..4011ff0161 --- /dev/null +++ b/lib/callHackageToNix.nix @@ -0,0 +1,5 @@ +{ runCommand, nix-tools +, hackageIndex +} : runCommand "hackage-nix" {} '' + HOME=${hackageIndex} ${nix-tools}/bin/hackage-to-nix $out + '' diff --git a/lib/hackageIndex.nix b/lib/hackageIndex.nix new file mode 100644 index 0000000000..d2bc0718a4 --- /dev/null +++ b/lib/hackageIndex.nix @@ -0,0 +1,16 @@ +{ runCommand, cabal-install +, indexState ? "2019-04-24T21:34:04Z" +} : +let + # To avoid downloading more data than necessary this will provide a base. + cachedState = runCommand "hackage-${builtins.substring 0 4 indexState}" {} '' + mkdir -p $out + HOME=$out ${cabal-install}/bin/cabal new-update 'hackage.haskell.org,${builtins.substring 0 4 indexState}-01-01T00:00:00Z' + ''; +in runCommand "hackage-${builtins.replaceStrings [":"] [""] indexState}" {} '' + mkdir -p $out + cp -r ${cachedState}/.cabal $out + chmod +w -R $out/.cabal + sed -i.back -e "s|${cachedState}|$out|g" $out/.cabal/config + HOME=$out ${cabal-install}/bin/cabal new-update 'hackage.haskell.org,${indexState}' + '' From 9c101cfd178076583e863bbd486ffbda7e21b47c Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Mon, 13 May 2019 15:21:24 +0800 Subject: [PATCH 02/12] Cleanup cabalProjectToNix - remove recentNixpkgs (this should rely on the provided (pinned) nixpkgs only. - parameterize callProjectToNix over the indexState. This prevents us from pulling it through the arguments and inheriting it evrywhere. - keep hackage as the one from the hackageSourceJSON. The reason being that we want a consistent hackage, and we periodically update it. As such having a second way to generate this will increase the compexity of haskell.nix. The indexState will almost always be behind the upstream hackageSourceJSON and as such generating the hackage nix expressions over just updating the hackageSourceJSON seems less beneficial. --- default.nix | 39 +++++++++++++++------------------------ lib/callHackageToNix.nix | 5 ----- 2 files changed, 15 insertions(+), 29 deletions(-) delete mode 100644 lib/callHackageToNix.nix diff --git a/default.nix b/default.nix index fa43afce22..838ef5d390 100644 --- a/default.nix +++ b/default.nix @@ -6,8 +6,6 @@ # It's also possible to override these sources with NIX_PATH. , hackageSourceJSON ? ./hackage-src.json , stackageSourceJSON ? ./stackage-src.json -, hackageIndexState ? null -, recentNixpkgs ? import {} }: let @@ -40,24 +38,17 @@ let # overridden with NIX_PATH. fetchExternal = import ./lib/fetch-external.nix; - hackageIndex = import ./lib/hackageIndex.nix { - inherit (pkgs) runCommand; - inherit (recentNixpkgs) cabal-install; - indexState = hackageIndexState; + mkHackageIndex = indexState: import ./lib/hackageIndex.nix { + inherit (pkgs) runCommand cabal-install; + inherit indexState; }; - + # All packages from Hackage as Nix expressions - hackage = if hackageIndexState == null - then import (fetchExternal { - name = "hackage-exprs-source"; - specJSON = hackageSourceJSON; - override = "hackage"; - }) - else import (import ./lib/callHackageToNix.nix { - inherit (pkgs) runCommand; - inherit (import ./. {}) nix-tools; - inherit hackageIndex; - }); + hackage = import (fetchExternal { + name = "hackage-exprs-source"; + specJSON = hackageSourceJSON; + override = "hackage"; + }); # The set of all Stackage snapshots stackage = import (fetchExternal { @@ -143,12 +134,12 @@ let # Takes a haskell src directory runs cabal new-configure and plan-to-nix. # Resulting nix files are added to nix-plan subdirectory. - cabalProjectToNix = import ./lib/cabalProjectToNix.nix { - inherit pkgs hackageIndex; - inherit (pkgs) runCommand; - inherit (recentNixpkgs) cabal-install ghc; - inherit (recentNixpkgs.haskellPackages) hpack; - inherit (import ./. {}) nix-tools; + cabalProjectToNix = hackageIndexState: import ./lib/cabalProjectToNix.nix { + hackageIndex = mkHackageIndex hackageIndexState; + inherit pkgs; + inherit (pkgs) runCommand cabal-install ghc; + inherit (pkgs.haskellPackages) hpack; + inherit (self) nix-tools; }; }); diff --git a/lib/callHackageToNix.nix b/lib/callHackageToNix.nix deleted file mode 100644 index 4011ff0161..0000000000 --- a/lib/callHackageToNix.nix +++ /dev/null @@ -1,5 +0,0 @@ -{ runCommand, nix-tools -, hackageIndex -} : runCommand "hackage-nix" {} '' - HOME=${hackageIndex} ${nix-tools}/bin/hackage-to-nix $out - '' From e2f44a785230490cbe86354939f14fdd64a68609 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Mon, 13 May 2019 17:10:05 +0800 Subject: [PATCH 03/12] Move even more into the cabalProjectToNix expression --- default.nix | 4 ++-- lib/cabalProjectToNix.nix | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/default.nix b/default.nix index 838ef5d390..731a9478da 100644 --- a/default.nix +++ b/default.nix @@ -134,8 +134,8 @@ let # Takes a haskell src directory runs cabal new-configure and plan-to-nix. # Resulting nix files are added to nix-plan subdirectory. - cabalProjectToNix = hackageIndexState: import ./lib/cabalProjectToNix.nix { - hackageIndex = mkHackageIndex hackageIndexState; + cabalProjectToNix = import ./lib/cabalProjectToNix.nix { + inherit mkHackageIndex; inherit pkgs; inherit (pkgs) runCommand cabal-install ghc; inherit (pkgs.haskellPackages) hpack; diff --git a/lib/cabalProjectToNix.nix b/lib/cabalProjectToNix.nix index ad0556e71a..3d9fd5d1ce 100644 --- a/lib/cabalProjectToNix.nix +++ b/lib/cabalProjectToNix.nix @@ -1,7 +1,5 @@ -{ pkgs, runCommand, nix-tools, cabal-install -, hackageIndex, ghc, hpack -} : -{src} : +{ mkHackageIndex, pkgs, runCommand, nix-tools, cabal-install, ghc, hpack }: +{ hackageIndexState, src }: let cabalFiles = builtins.filterSource (path: type: @@ -16,7 +14,7 @@ let cp -r ${cabalFiles}/* . chmod +w -R . find . -name package.yaml -exec hpack "{}" \; - HOME=${hackageIndex} ${cabal-install}/bin/cabal new-configure + HOME=${mkHackageIndex hackageIndexState} ${cabal-install}/bin/cabal new-configure HOME=$out ${nix-tools}/bin/plan-to-nix --plan-json dist-newstyle/cache/plan.json -o nix-plan cp -r nix-plan $out ''; From 64e2bb377474096f555494c93606fab636520b06 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Tue, 14 May 2019 16:44:29 +0800 Subject: [PATCH 04/12] Allow parameterizing `ghc` --- lib/cabalProjectToNix.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cabalProjectToNix.nix b/lib/cabalProjectToNix.nix index 3d9fd5d1ce..af06eaa613 100644 --- a/lib/cabalProjectToNix.nix +++ b/lib/cabalProjectToNix.nix @@ -1,5 +1,5 @@ { mkHackageIndex, pkgs, runCommand, nix-tools, cabal-install, ghc, hpack }: -{ hackageIndexState, src }: +{ hackageIndexState, src, ghc ? ghc }: let cabalFiles = builtins.filterSource (path: type: From 55dcd72dd20e3eb7f0e3048ad2d741df1b437caf Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Thu, 16 May 2019 19:10:06 +1200 Subject: [PATCH 05/12] Fix infinite recursion issue --- lib/cabalProjectToNix.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/cabalProjectToNix.nix b/lib/cabalProjectToNix.nix index af06eaa613..ede7738f67 100644 --- a/lib/cabalProjectToNix.nix +++ b/lib/cabalProjectToNix.nix @@ -1,5 +1,6 @@ { mkHackageIndex, pkgs, runCommand, nix-tools, cabal-install, ghc, hpack }: -{ hackageIndexState, src, ghc ? ghc }: +let defaultGhc = ghc; +in { hackageIndexState, src, ghc ? defaultGhc }: let cabalFiles = builtins.filterSource (path: type: From 696a0363e0ba7ffa667b9d71e260b831bc05b376 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Fri, 17 May 2019 15:18:46 +1200 Subject: [PATCH 06/12] Use cleanSourceWith as it can compose --- lib/cabalProjectToNix.nix | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/cabalProjectToNix.nix b/lib/cabalProjectToNix.nix index ede7738f67..1cfc7de077 100644 --- a/lib/cabalProjectToNix.nix +++ b/lib/cabalProjectToNix.nix @@ -3,10 +3,12 @@ let defaultGhc = ghc; in { hackageIndexState, src, ghc ? defaultGhc }: let cabalFiles = - builtins.filterSource (path: type: - type == "directory" || - pkgs.lib.any (i: (pkgs.lib.hasSuffix i path)) [ ".project" ".cabal" "package.yaml" ]) - src; + pkgs.lib.cleanSourceWith { + inherit src; + filter = path: type: + type == "directory" || + pkgs.lib.any (i: (pkgs.lib.hasSuffix i path)) [ ".project" ".cabal" "package.yaml" ]; + }; plan = runCommand "plan" { buildInputs = [ ghc hpack ]; } '' From 7c45574aedbb86192c7a48cb95fab6c3ed3d7113 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Fri, 17 May 2019 15:19:34 +1200 Subject: [PATCH 07/12] Use `cabal update` as it works with older versions --- lib/hackageIndex.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/hackageIndex.nix b/lib/hackageIndex.nix index d2bc0718a4..14d6d4b460 100644 --- a/lib/hackageIndex.nix +++ b/lib/hackageIndex.nix @@ -5,12 +5,12 @@ let # To avoid downloading more data than necessary this will provide a base. cachedState = runCommand "hackage-${builtins.substring 0 4 indexState}" {} '' mkdir -p $out - HOME=$out ${cabal-install}/bin/cabal new-update 'hackage.haskell.org,${builtins.substring 0 4 indexState}-01-01T00:00:00Z' + HOME=$out ${cabal-install}/bin/cabal update --index-state='${builtins.substring 0 4 indexState}-01-01T00:00:00Z' ''; in runCommand "hackage-${builtins.replaceStrings [":"] [""] indexState}" {} '' mkdir -p $out cp -r ${cachedState}/.cabal $out chmod +w -R $out/.cabal sed -i.back -e "s|${cachedState}|$out|g" $out/.cabal/config - HOME=$out ${cabal-install}/bin/cabal new-update 'hackage.haskell.org,${indexState}' + HOME=$out ${cabal-install}/bin/cabal update --index-state='${indexState}' '' From 2e9a90a9da2893f1940e226587add936b1a97ad4 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Fri, 17 May 2019 15:20:19 +1200 Subject: [PATCH 08/12] Allow cabal-install to be overridden --- lib/cabalProjectToNix.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/cabalProjectToNix.nix b/lib/cabalProjectToNix.nix index 1cfc7de077..c261c460d0 100644 --- a/lib/cabalProjectToNix.nix +++ b/lib/cabalProjectToNix.nix @@ -1,6 +1,7 @@ { mkHackageIndex, pkgs, runCommand, nix-tools, cabal-install, ghc, hpack }: let defaultGhc = ghc; -in { hackageIndexState, src, ghc ? defaultGhc }: + defaultCabalInstall = cabal-install; +in { hackageIndexState, src, ghc ? defaultGhc, cabal-install ? defaultCabalInstall }: let cabalFiles = pkgs.lib.cleanSourceWith { From fbdf1b2d59716831ca985f3b97588f6e25048946 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Sat, 18 May 2019 14:29:38 +0800 Subject: [PATCH 09/12] Cleanup cabal-project-to-nix --- default.nix | 1 + lib/cabalProjectToNix.nix | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/default.nix b/default.nix index 731a9478da..2e6ce1b93b 100644 --- a/default.nix +++ b/default.nix @@ -140,6 +140,7 @@ let inherit (pkgs) runCommand cabal-install ghc; inherit (pkgs.haskellPackages) hpack; inherit (self) nix-tools; + inherit (pkgs) symlinkJoin; }; }); diff --git a/lib/cabalProjectToNix.nix b/lib/cabalProjectToNix.nix index c261c460d0..9b81c39dad 100644 --- a/lib/cabalProjectToNix.nix +++ b/lib/cabalProjectToNix.nix @@ -1,4 +1,4 @@ -{ mkHackageIndex, pkgs, runCommand, nix-tools, cabal-install, ghc, hpack }: +{ mkHackageIndex, pkgs, runCommand, nix-tools, cabal-install, ghc, hpack, symlinkJoin }: let defaultGhc = ghc; defaultCabalInstall = cabal-install; in { hackageIndexState, src, ghc ? defaultGhc, cabal-install ? defaultCabalInstall }: @@ -10,7 +10,10 @@ let type == "directory" || pkgs.lib.any (i: (pkgs.lib.hasSuffix i path)) [ ".project" ".cabal" "package.yaml" ]; }; - plan = runCommand "plan" { + plan = if (builtins.compareVersions cabal-install.version "2.4.0.0") < 0 + # cabal-install versions before 2.4 will generate insufficient plan information. + then throw "cabal-install (current version: ${cabal-install.version}) needs to be at least 2.4 for plan-to-nix to work without cabal-to-nix" + else runCommand "plan" { buildInputs = [ ghc hpack ]; } '' tmp=$(mktemp -d) @@ -19,12 +22,34 @@ let chmod +w -R . find . -name package.yaml -exec hpack "{}" \; HOME=${mkHackageIndex hackageIndexState} ${cabal-install}/bin/cabal new-configure - HOME=$out ${nix-tools}/bin/plan-to-nix --plan-json dist-newstyle/cache/plan.json -o nix-plan - cp -r nix-plan $out + + export LANG=C.utf8 # Needed or stack-to-nix will die on unicode inputs + mkdir -p $out + + # ensure we have all our .cabal files (also those generated from package.yaml) files. + # otherwise we'd need to be careful about putting the `cabal-generator = hpack` into + # the nix expression. As we already called `hpack` on all `package.yaml` files we can + # skip that step and just package the .cabal files up as well. + # + # This is also important as `plan-to-nix` will look for the .cabal files when generating + # the relevant `pkgs.nix` file with the local .cabal expressions. + ${pkgs.rsync}/bin/rsync -a --prune-empty-dirs --include '*/' --include '*.cabal' --exclude '*' $tmp/ $out/ + + # make sure the path's in the plan.json are relative to $out instead of $tmp + # this is necessary so that plan-to-nix relative path logic can work. + substituteInPlace $tmp/dist-newstyle/cache/plan.json --replace "$tmp" "$out" + + # run `plan-to-nix` in $out. This should produce files right there with the + # proper relative paths. + (cd $out && ${nix-tools}/bin/plan-to-nix --plan-json $tmp/dist-newstyle/cache/plan.json -o .) + + # move pkgs.nix to default.nix ensure we can just nix `import` the result. + mv $out/pkgs.nix $out/default.nix ''; in runCommand "plan-and-src" {} '' mkdir $out - cp -r ${src}/* $out - ln -sf ${plan} $out/nix-plan + # todo: should we clean `src` to drop any .git, .nix, ... other irelevant files? + ${pkgs.xorg.lndir}/bin/lndir -silent "${src}" "$out" + ${pkgs.rsync}/bin/rsync -a ${plan}/ $out/ '' From 46be234994ba0a6963544d45381f125ddbc694c7 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Sat, 18 May 2019 14:40:49 +0800 Subject: [PATCH 10/12] use nativeBuildInputs --- lib/cabalProjectToNix.nix | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/cabalProjectToNix.nix b/lib/cabalProjectToNix.nix index 9b81c39dad..a31d4a6d3c 100644 --- a/lib/cabalProjectToNix.nix +++ b/lib/cabalProjectToNix.nix @@ -14,14 +14,14 @@ let # cabal-install versions before 2.4 will generate insufficient plan information. then throw "cabal-install (current version: ${cabal-install.version}) needs to be at least 2.4 for plan-to-nix to work without cabal-to-nix" else runCommand "plan" { - buildInputs = [ ghc hpack ]; + nativeBuildInputs = [ nix-tools ghc hpack cabal-install pkgs.rsync ]; } '' tmp=$(mktemp -d) cd $tmp cp -r ${cabalFiles}/* . chmod +w -R . find . -name package.yaml -exec hpack "{}" \; - HOME=${mkHackageIndex hackageIndexState} ${cabal-install}/bin/cabal new-configure + HOME=${mkHackageIndex hackageIndexState} cabal new-configure export LANG=C.utf8 # Needed or stack-to-nix will die on unicode inputs mkdir -p $out @@ -33,7 +33,7 @@ let # # This is also important as `plan-to-nix` will look for the .cabal files when generating # the relevant `pkgs.nix` file with the local .cabal expressions. - ${pkgs.rsync}/bin/rsync -a --prune-empty-dirs --include '*/' --include '*.cabal' --exclude '*' $tmp/ $out/ + rsync -a --prune-empty-dirs --include '*/' --include '*.cabal' --exclude '*' $tmp/ $out/ # make sure the path's in the plan.json are relative to $out instead of $tmp # this is necessary so that plan-to-nix relative path logic can work. @@ -41,15 +41,15 @@ let # run `plan-to-nix` in $out. This should produce files right there with the # proper relative paths. - (cd $out && ${nix-tools}/bin/plan-to-nix --plan-json $tmp/dist-newstyle/cache/plan.json -o .) + (cd $out && plan-to-nix --plan-json $tmp/dist-newstyle/cache/plan.json -o .) # move pkgs.nix to default.nix ensure we can just nix `import` the result. mv $out/pkgs.nix $out/default.nix ''; in - runCommand "plan-and-src" {} '' + runCommand "plan-and-src" { nativeBuildInputs = [ pkgs.xorg.lndir pkgs.rsync ]; } '' mkdir $out # todo: should we clean `src` to drop any .git, .nix, ... other irelevant files? - ${pkgs.xorg.lndir}/bin/lndir -silent "${src}" "$out" - ${pkgs.rsync}/bin/rsync -a ${plan}/ $out/ + lndir -silent "${src}" "$out" + rsync -a ${plan}/ $out/ '' From 1ecd24ed860579fcb3c1004a8674b7eab8abec37 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Sat, 18 May 2019 17:39:28 +0800 Subject: [PATCH 11/12] Adds tests --- default.nix | 2 +- test/default.nix | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/default.nix b/default.nix index 2e6ce1b93b..b612e796cb 100644 --- a/default.nix +++ b/default.nix @@ -134,7 +134,7 @@ let # Takes a haskell src directory runs cabal new-configure and plan-to-nix. # Resulting nix files are added to nix-plan subdirectory. - cabalProjectToNix = import ./lib/cabalProjectToNix.nix { + callCabalProjectToNix = import ./lib/cabalProjectToNix.nix { inherit mkHackageIndex; inherit pkgs; inherit (pkgs) runCommand cabal-install ghc; diff --git a/test/default.nix b/test/default.nix index 0789f84ab3..601339fe4d 100644 --- a/test/default.nix +++ b/test/default.nix @@ -16,6 +16,7 @@ in { builder-haddock = haskell.callPackage ./builder-haddock {}; stack-simple = haskell.callPackage ./stack-simple {}; callStackToNix = haskell.callPackage ./callStackToNix {}; + callCabalProjectToNix = haskell.callPackage ./call-cabal-project-to-nix {}; # Run unit tests with: nix-instantiate --eval --strict -A unit # An empty list means success. From ac86540c85720ab44a65f3061da0ce8e0a11abcb Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Sat, 18 May 2019 18:03:29 +0800 Subject: [PATCH 12/12] Minor fixes --- lib/cabalProjectToNix.nix | 9 +++++- test/call-cabal-project-to-nix/default.nix | 33 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 test/call-cabal-project-to-nix/default.nix diff --git a/lib/cabalProjectToNix.nix b/lib/cabalProjectToNix.nix index a31d4a6d3c..26fd5da044 100644 --- a/lib/cabalProjectToNix.nix +++ b/lib/cabalProjectToNix.nix @@ -20,6 +20,10 @@ let cd $tmp cp -r ${cabalFiles}/* . chmod +w -R . + # warning: this may not generate the proper cabal file. + # hpack allows globbing, and turns that into module lists + # without the source available (we cleaneSourceWith'd it), + # this may not produce the right result. find . -name package.yaml -exec hpack "{}" \; HOME=${mkHackageIndex hackageIndexState} cabal new-configure @@ -33,7 +37,10 @@ let # # This is also important as `plan-to-nix` will look for the .cabal files when generating # the relevant `pkgs.nix` file with the local .cabal expressions. - rsync -a --prune-empty-dirs --include '*/' --include '*.cabal' --exclude '*' $tmp/ $out/ + rsync -a --prune-empty-dirs \ + --include '*/' --include '*.cabal' --include 'package.yaml' \ + --exclude '*' \ + $tmp/ $out/ # make sure the path's in the plan.json are relative to $out instead of $tmp # this is necessary so that plan-to-nix relative path logic can work. diff --git a/test/call-cabal-project-to-nix/default.nix b/test/call-cabal-project-to-nix/default.nix new file mode 100644 index 0000000000..c18b6a3363 --- /dev/null +++ b/test/call-cabal-project-to-nix/default.nix @@ -0,0 +1,33 @@ +{ stdenv, mkCabalProjectPkgSet, callCabalProjectToNix }: + +with stdenv.lib; + +let + pkgSet = mkCabalProjectPkgSet { + plan-pkgs = import (callCabalProjectToNix { + hackageIndexState = "2019-04-24T21:34:04Z"; + # reuse the cabal-simple test project + src = ../cabal-simple; + }); + }; + packages = pkgSet.config.hsPkgs; +in + stdenv.mkDerivation { + name = "callStackToNix-test"; + + buildCommand = '' + exe="${packages.cabal-simple.components.exes.cabal-simple}/bin/cabal-simple" + + printf "checking whether executable runs... " >& 2 + $exe + + touch $out + ''; + + meta.platforms = platforms.all; + + passthru = { + # Attributes used for debugging with nix repl + inherit pkgSet packages; + }; + }