Skip to content

Commit d215a47

Browse files
authored
Fix mkFlakeApps and mkFlakePackages after input-output-hk#1993 (input-output-hk#2003)
* Fix project mkFlake after input-output-hk#1993 Rewrite mkFlakeApps, mkFlakeChecks and mkFlakePackages * Lint * Use pre-existing removeRecurseForDerivations
1 parent 75cae0a commit d215a47

File tree

5 files changed

+56
-49
lines changed

5 files changed

+56
-49
lines changed

flake.nix

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
traceNames = prefix: builtins.mapAttrs (n: v:
7474
if builtins.isAttrs v
7575
then if v ? type && v.type == "derivation"
76-
then __trace (prefix + n) v
76+
then builtins.trace (prefix + n) v
7777
else traceNames (prefix + n + ".") v
7878
else v);
7979

@@ -103,7 +103,7 @@
103103
# flake outputs so that we can incorporate the args passed
104104
# to the compat layer (e.g. sourcesOverride).
105105
overlays = [ allOverlays.combined ]
106-
++ (if checkMaterialization == true then
106+
++ (if checkMaterialization then
107107
[
108108
(final: prev: {
109109
haskell-nix = prev.haskell-nix // {
@@ -161,7 +161,7 @@
161161
# Exposed so that buildkite can check that `allow-import-from-derivation=false` works for core of haskell.nix
162162
roots = legacyPackagesUnstable.haskell-nix.roots compiler;
163163

164-
packages = ((self.internal.compat { inherit system; }).hix).apps;
164+
packages = (self.internal.compat { inherit system; }).hix.apps;
165165

166166
allJobs =
167167
let
@@ -180,15 +180,14 @@
180180
let nixpkgsJobs = allJobs.${nixpkgsVer};
181181
in lib.concatMap (compiler-nix-name:
182182
let ghcJobs = nixpkgsJobs.${compiler-nix-name};
183-
in (
184-
builtins.map (crossPlatform: {
183+
in builtins.map (crossPlatform: {
185184
name = "required-${nixpkgsVer}-${compiler-nix-name}-${crossPlatform}";
186185
value = legacyPackages.releaseTools.aggregate {
187186
name = "haskell.nix-${nixpkgsVer}-${compiler-nix-name}-${crossPlatform}";
188187
meta.description = "All ${nixpkgsVer} ${compiler-nix-name} ${crossPlatform} jobs";
189-
constituents = lib.collect (d: lib.isDerivation d) ghcJobs.${crossPlatform};
188+
constituents = lib.collect lib.isDerivation ghcJobs.${crossPlatform};
190189
};
191-
}) (names ghcJobs))
190+
}) (names ghcJobs)
192191
) (names nixpkgsJobs)
193192
) (names allJobs));
194193

hix/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ let
9090
echo "Updating $FLAKE/flake.nix and deleting old $FLAKE/flake.lock"
9191
rm $FLAKE/flake.lock
9292
else
93-
echo "Updating $FLAKE/flake.nix"
93+
echo "Updating $FLAKE/flake.nix"
9494
fi
9595
cp $HIX_FLAKE $FLAKE/flake.nix
9696
chmod +w $FLAKE/flake.nix

hix/project/default.nix

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@ let
3030
then []
3131
else [{ inherit name; value = commandArgs.${name}; }]
3232
) (builtins.attrNames commandArgs));
33-
defaultArgs = {
34-
nixpkgsPin = "nixpkgs-unstable";
35-
};
3633
importDefaults = src:
37-
if src == null || !(__pathExists src)
34+
if src == null || !(builtins.pathExists src)
3835
then {}
3936
else import src;
4037
userDefaults = importDefaults (commandArgs.userDefaults or null);
@@ -64,7 +61,7 @@ let
6461
commandArgs'
6562
({config, ...}: {
6663
src =
67-
if __pathExists (toString (src.origSrcSubDir or src) + "/.git")
64+
if builtins.pathExists (toString (src.origSrcSubDir or src) + "/.git")
6865
then config.evalPackages.haskell-nix.haskellLib.cleanGit {
6966
inherit src name;
7067
}
@@ -73,5 +70,5 @@ let
7370
];
7471
})
7572
];
76-
}).config) project shell;
73+
}).config) project;
7774
in project

lib/default.nix

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,19 @@ in {
3939

4040
foldComponents = tys: f: z: conf:
4141
let
42-
comps = conf.components or {};
42+
comps = conf.components or { };
4343
# ensure that comps.library exists and is not null.
44-
libComp = acc: if (comps.library or null) != null then f comps.library acc else acc;
44+
libComp = acc:
45+
if comps ? library then f comps.library acc else acc;
4546
subComps = acc:
4647
lib.foldr
47-
(ty: acc': foldrAttrVals f acc' (comps.${ty} or {}))
48+
(ty: acc': foldrAttrVals f acc' (comps.${ty} or { }))
4849
acc
4950
tys;
50-
in libComp (subComps z);
51+
in
52+
libComp (subComps z);
5153

52-
getAllComponents = foldComponents subComponentTypes (c: acc: [c] ++ acc) [];
54+
getAllComponents = foldComponents subComponentTypes (c: acc: [ c ] ++ acc) [ ];
5355

5456
componentPrefix = {
5557
sublibs = "lib";
@@ -211,7 +213,7 @@ in {
211213
#
212214
# See docs/user-guide/clean-git.md for details of how to use this
213215
# with `cabalProject`.
214-
cleanGits = { src, gitDirs, name ? null, caller ? "cleanGits" }@args:
216+
cleanGits = { src, gitDirs, name ? null, caller ? "cleanGits" }:
215217
let
216218
# List of filters, one for each git directory.
217219
filters = builtins.map (subDir:
@@ -424,36 +426,46 @@ in {
424426
}]) (packageNames coverageProject));
425427

426428
# Flake package names that are flat and match the cabal component names.
427-
mkFlakePackages = haskellPackages: builtins.listToAttrs (
428-
lib.concatLists (lib.mapAttrsToList (packageName: package:
429-
builtins.groupBy
430-
(c: c.passthru.identifier.component-id)
431-
((lib.optional (package.components ? library) package.components.library)
432-
++ package.components.sublibs
433-
++ package.components.exes
434-
++ package.components.tests
435-
++ package.components.benchmarks)
436-
) haskellPackages));
429+
mkFlakePackages =
430+
foldrAttrVals
431+
(package: acc:
432+
foldComponents
433+
subComponentTypes
434+
(component: a: a // {
435+
${component.passthru.identifier.component-id} = component;
436+
})
437+
acc
438+
package)
439+
{ };
437440

438441
# Flake package names that are flat and match the cabal component names.
439-
mkFlakeApps = haskellPackages: builtins.listToAttrs (
440-
lib.concatLists (lib.mapAttrsToList (packageName: package:
441-
builtins.groupBy
442-
(c: c.passthru.identifier.component-id)
443-
(package.components.exes
444-
++ package.components.tests
445-
++ package.components.benchmarks)
446-
) haskellPackages));
442+
mkFlakeApps =
443+
foldrAttrVals
444+
(package: acc:
445+
foldComponents
446+
[ "exes" "tests" "benchmarks" ]
447+
(component: a: a // {
448+
${component.passthru.identifier.component-id} = {
449+
type = "app";
450+
program = component.exePath;
451+
};
452+
})
453+
acc
454+
package)
455+
{ };
447456

448457
# Flatten the result of collectChecks or collectChecks' for use in flake `checks`
449-
mkFlakeChecks = allChecks: builtins.listToAttrs (
450-
lib.concatLists (lib.mapAttrsToList (packageName: checks:
451-
# Avoid `recurseForDerivations` issues
452-
lib.optionals (lib.isAttrs checks) (
453-
lib.mapAttrsToList (n: v:
454-
{ name = "${packageName}:test:${n}"; value = v; })
455-
(lib.filterAttrs (_: lib.isDerivation) checks))
456-
) allChecks));
458+
mkFlakeChecks = allChecks:
459+
foldrAttrVals
460+
(package: acc:
461+
foldrAttrVals
462+
(check: a: a // {
463+
${check.passthru.identifier.component-id} = check;
464+
})
465+
acc
466+
package)
467+
{ }
468+
(removeRecurseForDerivations allChecks);
457469

458470
removeRecurseForDerivations = x:
459471
let clean = builtins.removeAttrs x ["recurseForDerivations"];

overlays/hix.nix

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ final: prev: { haskell-nix = prev.haskell-nix // { hix = {
99
, ...}@commandArgs:
1010
let
1111
inherit (final) lib;
12-
hixDefaults = { compiler-nix-name = lib.mkDefault "ghc8107"; };
1312
inherit ((lib.evalModules {
1413
modules = [
1514
(import ../modules/project-common.nix)
@@ -31,7 +30,7 @@ final: prev: { haskell-nix = prev.haskell-nix // { hix = {
3130
else [{ inherit name; value = commandArgs.${name}; }]
3231
) (builtins.attrNames commandArgs));
3332
importDefaults = src:
34-
if src == null || !(__pathExists src)
33+
if src == null || !(builtins.pathExists src)
3534
then {}
3635
else import src;
3736
projectDefaults = importDefaults (toString (src.origSrcSubDir or src) + "/nix/hix.nix");
@@ -41,7 +40,7 @@ final: prev: { haskell-nix = prev.haskell-nix // { hix = {
4140
commandArgs'
4241
({config, ...}: {
4342
src =
44-
if __pathExists (toString (src.origSrcSubDir or src) + "/.git")
43+
if builtins.pathExists (toString (src.origSrcSubDir or src) + "/.git")
4544
then config.evalPackages.haskell-nix.haskellLib.cleanGit {
4645
inherit src name;
4746
}

0 commit comments

Comments
 (0)