File tree 2 files changed +51
-4
lines changed
2 files changed +51
-4
lines changed Original file line number Diff line number Diff line change
1
+ # Generate cache entries for dependencies of package defined in `src`
2
+
3
+ { pkgs } :
4
+ { src , stackYaml ? "stack.yaml" } :
5
+ let
6
+ s2n = import "${ pkgs . fetchFromGitHub {
7
+ owner = "serokell" ;
8
+ repo = "stack-to-nix" ;
9
+ rev = "28e690d3eddd47c59982c7fbf4f950320ff7ff69" ;
10
+ sha256 = "1xnx5baj3k29iy8ccppn28ayf4483zddrvq6fikfpvblzp5zrnaj" ;
11
+ } } /lib.nix" pkgs ;
12
+
13
+ deps = ( s2n . importYAML "${ src } /${ stackYaml } " ) . extra-deps or [ ] ;
14
+ hashPath = path :
15
+ builtins . readFile ( pkgs . runCommand "hash-path" { preferLocalBuild = true ; }
16
+ "echo -n $(${ pkgs . nix } /bin/nix-hash --type sha256 --base32 ${ path } ) > $out" ) ;
17
+ in with pkgs . lib ;
18
+ concatMap ( dep :
19
+ if ! builtins . isAttrs dep then
20
+ [ ]
21
+ else
22
+ let
23
+ pkgsrc = builtins . fetchGit {
24
+ url = dep . git ;
25
+ ref = "*" ;
26
+ rev = dep . commit ;
27
+ } ;
28
+ in map ( subdir :
29
+ {
30
+ name = s2n . cabalPackageName "${ pkgsrc } /${ subdir } " ;
31
+ rev = dep . commit ;
32
+ url = dep . git ;
33
+ sha256 = hashPath pkgsrc ;
34
+ } // ( optionalAttrs ( subdir != "" ) { inherit subdir ; } ) )
35
+ ( dep . subdirs or [ "" ] ) ) deps
Original file line number Diff line number Diff line change @@ -240,6 +240,10 @@ self: super: {
240
240
text = self . buildPackages . lib . concatMapStringsSep "\n " f repos ;
241
241
} ;
242
242
243
+ genStackCache = import ../lib/stack-cache-generator.nix {
244
+ inherit ( self . buildPackages ) pkgs ;
245
+ } ;
246
+
243
247
mkCacheModule = cache :
244
248
# for each item in the `cache`, set
245
249
# packages.$name.src = fetchgit ...
@@ -337,13 +341,21 @@ self: super: {
337
341
338
342
stackProject' =
339
343
{ ... } @args :
340
- let stack = importAndFilterProject ( callStackToNix args ) ;
344
+ let stack = importAndFilterProject ( callStackToNix ( { inherit cache ; } // args ) ) ;
345
+ cache = if args ? cache
346
+ then builtins . trace
347
+ "warning: passing `cache' to `stackProject' is deprecated. See #335 #358"
348
+ args . cache
349
+ else genStackCache {
350
+ inherit ( args ) src ;
351
+ stackYaml = args . stackYaml or "stack.yaml" ;
352
+ } ;
341
353
in let pkg-set = mkStackPkgSet
342
354
{ stack-pkgs = stack . pkgs ;
343
355
pkg-def-extras = ( args . pkg-def-extras or [ ] ) ;
344
- modules = ( args . modules or [ ] )
345
- ++ self . lib . optional ( args ? ghc ) { ghc . package = args . ghc ; }
346
- ++ self . lib . optional ( args ? cache ) ( mkCacheModule args . cache ) ;
356
+ modules = self . lib . singleton ( mkCacheModule cache )
357
+ ++ ( args . modules or [ ] )
358
+ ++ self . lib . optional ( args ? ghc ) { ghc . package = args . ghc ; } ;
347
359
} ;
348
360
in { inherit ( pkg-set . config ) hsPkgs ; stack-nix = stack . nix ; } ;
349
361
You can’t perform that action at this time.
0 commit comments