on iko/ghcjs-patch-master help sign in
Fix restricted eval mode issue with mkCacheFile (#392)
43fdc4dHamish Mackenzie
lib/call-stack-to-nix.nix+1−1
@@ -35,7 +35,7 @@ let
35 } (''
35 } (''
36 mkdir -p $out
36 mkdir -p $out
37 '' + pkgs.lib.optionalString (cache != null) ''
37 '' + pkgs.lib.optionalString (cache != null) ''
38− cp ${mkCacheFile cache} $out/.stack-to-nix.cache
38+ cp ${mkCacheFile cache}/.stack-to-nix.cache* $out
39 '' + ''
39 '' + ''
40 (cd $out && stack-to-nix ${stackToNixArgs})
40 (cd $out && stack-to-nix ${stackToNixArgs})
41
41
overlays/haskell.nix+21−5
@@ -285,18 +285,34 @@ self: super: {
285
285
286 sha256String = if isNull sha256 then self.buildPackages.lib.fakeSha256 else sha256;
286 sha256String = if isNull sha256 then self.buildPackages.lib.fakeSha256 else sha256;
287
287
288+ in {
288− in "${url} ${rev} ${subdir} ${sha256String} ${name} ${nix-expr}";
289+ line = "${url} ${rev} ${subdir} ${sha256String} ${name}";
290+ inherit nix-expr;
291+ };
289
292
290 # Given a list of repos:
293 # Given a list of repos:
291 # [ { name = ...; url = ...; rev = ...; ref = ...; sha256 = ...; cabal-file = ...; type = ...; is-private = ...; } ]
294 # [ { name = ...; url = ...; rev = ...; ref = ...; sha256 = ...; cabal-file = ...; type = ...; is-private = ...; } ]
292 # produce a cache file that can be used for
295 # produce a cache file that can be used for
293 # stack-to-nix or plan-to-nix to prevent them
296 # stack-to-nix or plan-to-nix to prevent them
294 # from needing network access.
297 # from needing network access.
298+ # The cache contains only local paths to nix files so that it can
299+ # the results of `stack-to-nix` can be imported in restrected eval
300+ # mode.
295 mkCacheFile = repos:
301 mkCacheFile = repos:
296− self.buildPackages.pkgs.writeTextFile {
302+ self.buildPackages.pkgs.runCommand "cache-file" {} ''
297− name = "cache-file";
303+ mkdir -p $out
298− text = self.buildPackages.lib.concatMapStringsSep "\n" mkCacheLine repos;
304+ touch $out/.stack-to-nix.cache
305+ ${self.lib.concatStrings (
306+ self.lib.lists.zipListsWith (n: repo:
307+ let l = mkCacheLine repo;
308+ in ''
309+ cp ${l.nix-expr} $out/.stack-to-nix.cache.${toString n}
310+ echo ${l.line} .stack-to-nix.cache.${toString n} >> $out/.stack-to-nix.cache
311+ '')
312+ (self.lib.lists.range 0 ((builtins.length repos) - 1))
313+ repos)
314+ }
299− };
315+ '';
300
316
301 mkCacheModule = cache:
317 mkCacheModule = cache:
302 # for each item in the `cache`, set
318 # for each item in the `cache`, set
test/default.nix+1
@@ -40,6 +40,7 @@ in pkgs.recurseIntoAttrs {
40 ghc-options-cabal = haskell-nix.callPackage ./ghc-options/cabal.nix {};
40 ghc-options-cabal = haskell-nix.callPackage ./ghc-options/cabal.nix {};
41 ghc-options-stack = haskell-nix.callPackage ./ghc-options/stack.nix {};
41 ghc-options-stack = haskell-nix.callPackage ./ghc-options/stack.nix {};
42 exe-only = haskell-nix.callPackage ./exe-only { inherit util; };
42 exe-only = haskell-nix.callPackage ./exe-only { inherit util; };
43+ stack-source-repo = haskell-nix.callPackage ./stack-source-repo {};
43
44
44 # Run unit tests with: nix-instantiate --eval --strict -A unit.tests
45 # Run unit tests with: nix-instantiate --eval --strict -A unit.tests
45 # An empty list means success.
46 # An empty list means success.
test/stack-source-repo/.gitignorenew file+2
@@ -0,0 +1,2 @@
1+/.stack-work/
2+/*.cabal
test/stack-source-repo/default.nixnew file+15
@@ -0,0 +1,15 @@
1+{ stackProject', recurseIntoAttrs }:
2+
3+let
4+ project = stackProject' {
5+ src = ./.;
6+ cache = [ { is-private = false; name = "cabal-simple"; rev = "bc01ebc05a8105035c9449943046b46c8364b932"; sha256 = "003lm3pm024vhbfmii7xcdd9v2rczpflxf7gdl2pyxia7p014i8z"; subdir = "test/cabal-simple"; url = "https://github.com/input-output-hk/haskell.nix.git"; } ];
7+ };
8+ packages = project.hsPkgs;
9+
10+in recurseIntoAttrs {
11+ ifdInputs = {
12+ inherit (project) stack-nix;
13+ };
14+ inherit (packages.stack-source-repo.components) library;
15+}
test/stack-source-repo/package.yamlnew file+8
@@ -0,0 +1,8 @@
1+name: stack-source-repo
2+
3+dependencies:
4+- base
5+- cabal-simple
6+
7+library:
8+ source-dirs: src
test/stack-source-repo/src/Lib.hsnew file+6
@@ -0,0 +1,6 @@
1+module Lib
2+ ( someFunc
3+ ) where
4+
5+someFunc :: IO ()
6+someFunc = putStrLn "someFunc"
test/stack-source-repo/stack.yamlnew file+11
@@ -0,0 +1,11 @@
1+resolver: lts-14.13
2+
3+packages:
4+- .
5+
6+extra-deps:
7+- git: https://github.com/input-output-hk/haskell.nix.git
8+ commit: bc01ebc05a8105035c9449943046b46c8364b932
9+ subdirs:
10+ - test/cabal-simple
11+