on iko/ghcjs-patch-master help sign in
Some smalls improvements (#1271)

* Use builtins.fetchGit{allRefs=true;} if no ref provided. this allows to not being explicit about non-default branches. * Pass buildProject as arg to first level project modules, so that it can be used in, eg., shell definition. * Add hsPkgs to projects modules config. * Add benchmarks to generated project.flake packages

commit1205c42154647bd09aaa72b8c25cf02e58514055 authorJean-Baptiste Giraudeau <jean-baptiste.giraudeau@iohk.io> dateFri 22 Oct 2021, 03:23 (5 years ago) parent42e270c
4 files changed+26−5
lib/default.nix+7−2 lib/stack-cache-generator.nix+5−1 modules/project-common.nix+3 overlays/haskell.nix+11−2
lib/default.nix+7−2
@@ -334,20 +334,25 @@ in {
334334 # Run evalModules passing the project function argument (m) as a module along with
335335 # the the a projectType module (../modules/cabal-project.nix or ../modules/stack-project.nix).
336336 # The resulting config is then passed to the project function's implementation.
337− evalProjectModule = projectType: m: f: f
337+ evalProjectModule = projectType: m: f:
338+ let project = f
338339 (lib.evalModules {
339340 modules = (if builtins.isList m then m else [m]) ++ [
340341 # Include ../modules/cabal-project.nix or ../modules/stack-project.nix
341342 (import ../modules/project-common.nix)
342343 (import projectType)
343− # Pass the pkgs to the modules
344+ # Pass the pkgs and the buildProject to the modules
344345 ({ config, lib, ... }: {
345346 _module.args = {
346347 inherit pkgs;
348+ # to make it easy to depends on build packages in, eg., shell definition:
349+ inherit (project) buildProject;
347350 };
351+ inherit (project) hsPkgs;
348352 })
349353 ];
350354 }).config;
355+ in project;
351356
352357 # Converts from a `compoent.depends` value to a library derivation.
353358 # In the case of sublibs the `depends` value should already be the derivation.
lib/stack-cache-generator.nix+5−1
@@ -103,7 +103,11 @@ concatMap (dep:
103103 }
104104 else builtins.fetchGit ({
105105 inherit (dep) url rev;
106− } // pkgs.lib.optionalAttrs (branch != null) { ref = branch; });
106+ } // (if branch != null
107+ then { ref = branch; }
108+ # Don't fail if rev not in default branch:
109+ else { allRefs = true; })
110+ );
107111 in map (subdir: {
108112 name = cabalName "${pkgsrc}/${subdir}";
109113 inherit (dep) url rev;
modules/project-common.nix+3
@@ -24,5 +24,8 @@ with lib.types;
2424 shell = { tools.cabal = {}; crossPlatforms = p: [ p.ghcjs ]; }
2525 '';
2626 };
27+ hsPkgs = lib.mkOption {
28+ type = lib.types.unspecified;
29+ };
2730 };
2831}
overlays/haskell.nix+11−2
@@ -308,7 +308,10 @@ final: prev: {
308308 assert isNull sha256;
309309 builtins.fetchGit
310310 ({ inherit url rev; } //
311− final.buildPackages.lib.optionalAttrs (ref != null) { inherit ref; }
311+ (if ref != null
312+ then { inherit ref; }
313+ # Don't fail if rev not in default branch:
314+ else { allRefs = true; })
312315 )
313316 else
314317 # Non-private repos must have sha256 set.
@@ -402,7 +405,10 @@ final: prev: {
402405 then
403406 builtins.fetchGit
404407 ({ inherit url rev; } //
405− final.buildPackages.lib.optionalAttrs (ref != null) { inherit ref; }
408+ (if ref != null
409+ then { inherit ref; }
410+ # don't fail if rev not in default branch:
411+ else { allRefs = true; })
406412 )
407413 else
408414 final.evalPackages.fetchgit { inherit url rev sha256; };
@@ -725,6 +731,9 @@ final: prev: {
725731 ++ final.lib.mapAttrsToList (n: v:
726732 { name = "${prefix}${packageName}:test:${n}"; value = v; })
727733 (package.components.tests)
734+ ++ final.lib.mapAttrsToList (n: v:
735+ { name = "${prefix}${packageName}:benchmarks:${n}"; value = v; })
736+ (package.components.benchmarks)
728737 ) (packageNames project);
729738 checksForProject = prefix: project:
730739 final.lib.concatMap (packageName: