From 48fa8dd410b865588416b2e9d026b1eb56ec986e Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Mon, 17 Jul 2023 21:49:57 +0800 Subject: [PATCH 1/3] Fix project mkFlake after #1993 Rewrite mkFlakeApps, mkFlakeChecks and mkFlakePackages --- lib/default.nix | 75 +++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/lib/default.nix b/lib/default.nix index 4dc1358917..4531f25497 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -39,17 +39,19 @@ in { foldComponents = tys: f: z: conf: let - comps = conf.components or {}; + comps = conf.components or { }; # ensure that comps.library exists and is not null. - libComp = acc: if (comps.library or null) != null then f comps.library acc else acc; + libComp = acc: + if comps ? library then f comps.library acc else acc; subComps = acc: lib.foldr - (ty: acc': foldrAttrVals f acc' (comps.${ty} or {})) + (ty: acc': foldrAttrVals f acc' (comps.${ty} or { })) acc tys; - in libComp (subComps z); + in + libComp (subComps z); - getAllComponents = foldComponents subComponentTypes (c: acc: [c] ++ acc) []; + getAllComponents = foldComponents subComponentTypes (c: acc: [ c ] ++ acc) [ ]; componentPrefix = { sublibs = "lib"; @@ -424,36 +426,47 @@ in { }]) (packageNames coverageProject)); # Flake package names that are flat and match the cabal component names. - mkFlakePackages = haskellPackages: builtins.listToAttrs ( - lib.concatLists (lib.mapAttrsToList (packageName: package: - builtins.groupBy - (c: c.passthru.identifier.component-id) - ((lib.optional (package.components ? library) package.components.library) - ++ package.components.sublibs - ++ package.components.exes - ++ package.components.tests - ++ package.components.benchmarks) - ) haskellPackages)); + mkFlakePackages = + foldrAttrVals + (package: acc: + foldComponents + subComponentTypes + (component: a: a // { + ${component.passthru.identifier.component-id} = component; + }) + acc + package) + { }; # Flake package names that are flat and match the cabal component names. - mkFlakeApps = haskellPackages: builtins.listToAttrs ( - lib.concatLists (lib.mapAttrsToList (packageName: package: - builtins.groupBy - (c: c.passthru.identifier.component-id) - (package.components.exes - ++ package.components.tests - ++ package.components.benchmarks) - ) haskellPackages)); + mkFlakeApps = + foldrAttrVals + (package: acc: + foldComponents + [ "exes" "tests" "benchmarks" ] + (component: a: a // { + ${component.passthru.identifier.component-id} = { + type = "app"; + program = component.exePath; + }; + }) + acc + package) + { }; # Flatten the result of collectChecks or collectChecks' for use in flake `checks` - mkFlakeChecks = allChecks: builtins.listToAttrs ( - lib.concatLists (lib.mapAttrsToList (packageName: checks: - # Avoid `recurseForDerivations` issues - lib.optionals (lib.isAttrs checks) ( - lib.mapAttrsToList (n: v: - { name = "${packageName}:test:${n}"; value = v; }) - (lib.filterAttrs (_: lib.isDerivation) checks)) - ) allChecks)); + mkFlakeChecks = allChecks: + foldrAttrVals + (package: acc: + foldrAttrVals + (check: a: a // { + ${check.passthru.identifier.component-id} = check; + }) + acc + package) + { } + # Remove `recurseForDerivations` + (lib.filterAttrsRecursive (n: v: n != "recurseForDerivations") allChecks); removeRecurseForDerivations = x: let clean = builtins.removeAttrs x ["recurseForDerivations"]; From cfb53bafad3a9d505159434548e013ca7b1f7e65 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Mon, 17 Jul 2023 21:59:32 +0800 Subject: [PATCH 2/3] Lint --- flake.nix | 13 ++++++------- hix/default.nix | 2 +- hix/project/default.nix | 9 +++------ lib/default.nix | 2 +- overlays/hix.nix | 5 ++--- 5 files changed, 13 insertions(+), 18 deletions(-) diff --git a/flake.nix b/flake.nix index 581cabeef0..ee8aac6b0f 100644 --- a/flake.nix +++ b/flake.nix @@ -73,7 +73,7 @@ traceNames = prefix: builtins.mapAttrs (n: v: if builtins.isAttrs v then if v ? type && v.type == "derivation" - then __trace (prefix + n) v + then builtins.trace (prefix + n) v else traceNames (prefix + n + ".") v else v); @@ -103,7 +103,7 @@ # flake outputs so that we can incorporate the args passed # to the compat layer (e.g. sourcesOverride). overlays = [ allOverlays.combined ] - ++ (if checkMaterialization == true then + ++ (if checkMaterialization then [ (final: prev: { haskell-nix = prev.haskell-nix // { @@ -161,7 +161,7 @@ # Exposed so that buildkite can check that `allow-import-from-derivation=false` works for core of haskell.nix roots = legacyPackagesUnstable.haskell-nix.roots compiler; - packages = ((self.internal.compat { inherit system; }).hix).apps; + packages = (self.internal.compat { inherit system; }).hix.apps; allJobs = let @@ -180,15 +180,14 @@ let nixpkgsJobs = allJobs.${nixpkgsVer}; in lib.concatMap (compiler-nix-name: let ghcJobs = nixpkgsJobs.${compiler-nix-name}; - in ( - builtins.map (crossPlatform: { + in builtins.map (crossPlatform: { name = "required-${nixpkgsVer}-${compiler-nix-name}-${crossPlatform}"; value = legacyPackages.releaseTools.aggregate { name = "haskell.nix-${nixpkgsVer}-${compiler-nix-name}-${crossPlatform}"; meta.description = "All ${nixpkgsVer} ${compiler-nix-name} ${crossPlatform} jobs"; - constituents = lib.collect (d: lib.isDerivation d) ghcJobs.${crossPlatform}; + constituents = lib.collect lib.isDerivation ghcJobs.${crossPlatform}; }; - }) (names ghcJobs)) + }) (names ghcJobs) ) (names nixpkgsJobs) ) (names allJobs)); diff --git a/hix/default.nix b/hix/default.nix index 5b9cc97467..c23123f914 100644 --- a/hix/default.nix +++ b/hix/default.nix @@ -90,7 +90,7 @@ let echo "Updating $FLAKE/flake.nix and deleting old $FLAKE/flake.lock" rm $FLAKE/flake.lock else - echo "Updating $FLAKE/flake.nix" + echo "Updating $FLAKE/flake.nix" fi cp $HIX_FLAKE $FLAKE/flake.nix chmod +w $FLAKE/flake.nix diff --git a/hix/project/default.nix b/hix/project/default.nix index 785119046f..1f1db532c3 100644 --- a/hix/project/default.nix +++ b/hix/project/default.nix @@ -30,11 +30,8 @@ let then [] else [{ inherit name; value = commandArgs.${name}; }] ) (builtins.attrNames commandArgs)); - defaultArgs = { - nixpkgsPin = "nixpkgs-unstable"; - }; importDefaults = src: - if src == null || !(__pathExists src) + if src == null || !(builtins.pathExists src) then {} else import src; userDefaults = importDefaults (commandArgs.userDefaults or null); @@ -64,7 +61,7 @@ let commandArgs' ({config, ...}: { src = - if __pathExists (toString (src.origSrcSubDir or src) + "/.git") + if builtins.pathExists (toString (src.origSrcSubDir or src) + "/.git") then config.evalPackages.haskell-nix.haskellLib.cleanGit { inherit src name; } @@ -73,5 +70,5 @@ let ]; }) ]; - }).config) project shell; + }).config) project; in project diff --git a/lib/default.nix b/lib/default.nix index 4531f25497..6cd3fd474f 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -213,7 +213,7 @@ in { # # See docs/user-guide/clean-git.md for details of how to use this # with `cabalProject`. - cleanGits = { src, gitDirs, name ? null, caller ? "cleanGits" }@args: + cleanGits = { src, gitDirs, name ? null, caller ? "cleanGits" }: let # List of filters, one for each git directory. filters = builtins.map (subDir: diff --git a/overlays/hix.nix b/overlays/hix.nix index 7432283196..97d5c1c368 100644 --- a/overlays/hix.nix +++ b/overlays/hix.nix @@ -9,7 +9,6 @@ final: prev: { haskell-nix = prev.haskell-nix // { hix = { , ...}@commandArgs: let inherit (final) lib; - hixDefaults = { compiler-nix-name = lib.mkDefault "ghc8107"; }; inherit ((lib.evalModules { modules = [ (import ../modules/project-common.nix) @@ -31,7 +30,7 @@ final: prev: { haskell-nix = prev.haskell-nix // { hix = { else [{ inherit name; value = commandArgs.${name}; }] ) (builtins.attrNames commandArgs)); importDefaults = src: - if src == null || !(__pathExists src) + if src == null || !(builtins.pathExists src) then {} else import src; projectDefaults = importDefaults (toString (src.origSrcSubDir or src) + "/nix/hix.nix"); @@ -41,7 +40,7 @@ final: prev: { haskell-nix = prev.haskell-nix // { hix = { commandArgs' ({config, ...}: { src = - if __pathExists (toString (src.origSrcSubDir or src) + "/.git") + if builtins.pathExists (toString (src.origSrcSubDir or src) + "/.git") then config.evalPackages.haskell-nix.haskellLib.cleanGit { inherit src name; } From aa5d7b14e94110816fb2f4be0771c90e47a740e3 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Tue, 18 Jul 2023 00:12:02 +0800 Subject: [PATCH 3/3] Use pre-existing removeRecurseForDerivations --- lib/default.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/default.nix b/lib/default.nix index 6cd3fd474f..5d491e5c82 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -465,8 +465,7 @@ in { acc package) { } - # Remove `recurseForDerivations` - (lib.filterAttrsRecursive (n: v: n != "recurseForDerivations") allChecks); + (removeRecurseForDerivations allChecks); removeRecurseForDerivations = x: let clean = builtins.removeAttrs x ["recurseForDerivations"];