From 8ae8b5a198a7dd8b82070deea4fff035c90c1780 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Thu, 14 Nov 2019 14:15:33 +1300 Subject: [PATCH 01/46] Add collectRunComponents. Move checkPhase to .run In order to make it easier to run tests this change adds a collectRunComponents function (like collectComponents but with it returns the `passthru.run` derivation for each component). This change also disables `checkPhase` for all components to avoid running the tests twice. To run a test or benchmark you now have to use the the `passthru.run` derivation. --- builder/comp-builder.nix | 58 +++++++++++++++++++++++++++++++--------- lib/default.nix | 17 ++++++++++-- 2 files changed, 61 insertions(+), 14 deletions(-) diff --git a/builder/comp-builder.nix b/builder/comp-builder.nix index 9134510db3..0fbe498175 100644 --- a/builder/comp-builder.nix +++ b/builder/comp-builder.nix @@ -132,7 +132,10 @@ stdenv.mkDerivation ({ src = cleanSrc; - inherit doCheck doCrossCheck dontPatchELF dontStrip; + doCheck = false; + doCrossCheck = false; + + inherit dontPatchELF dontStrip; passthru = { inherit (package) identifier; @@ -143,9 +146,46 @@ stdenv.mkDerivation ({ # The directory containing the haddock documentation. # `null' if no haddock documentation was built. haddockDir = if doHaddock' then "${docdir drv.doc}/html" else null; - run = runCommand (fullName + "-run") {} '' - ${toString component.testWrapper} ${drv}/${installedExe} | tee $out - ''; + run = stdenv.mkDerivation ({ + name = (fullName + "-run"); + + src = drv; + + passthru = { + inherit (package) identifier; + config = component; + inherit configFiles executableToolDepends cleanSrc; + env = shellWrappers; + }; + + meta = { + homepage = package.homepage; + description = package.synopsis; + license = + let + license-map = import ../lib/cabal-licenses.nix lib; + in license-map.${package.license} or + (builtins.trace "WARNING: license \"${package.license}\" not found" license-map.LicenseRef-OtherLicense); + platforms = if component.platforms == null then stdenv.lib.platforms.all else component.platforms; + }; + + LANG = "en_US.UTF-8"; # GHC needs the locale configured during the Haddock phase. + LC_ALL = "en_US.UTF-8"; + + inherit doCheck doCrossCheck; + + phases = ["checkPhase"]; + + checkPhase = '' + runHook preCheck + + ${toString component.testWrapper} $src/${installedExe} ${lib.concatStringsSep " " component.testFlags} | tee $out + + runHook postCheck + ''; + } // haskellLib.optionalHooks { + inherit preCheck postCheck; + }); }; meta = { @@ -206,13 +246,7 @@ stdenv.mkDerivation ({ runHook postBuild ''; - checkPhase = '' - runHook preCheck - - ${toString component.testWrapper} ${testExecutable} ${lib.concatStringsSep " " component.testFlags} - - runHook postCheck - ''; + checkPhase = ""; haddockPhase = '' runHook preHaddock @@ -305,7 +339,7 @@ stdenv.mkDerivation ({ // lib.optionalAttrs (patches != []) { patches = map (p: if builtins.isFunction p then p { inherit (package.identifier) version; inherit revision; } else p) patches; } // haskellLib.optionalHooks { inherit preUnpack postUnpack preConfigure postConfigure - preBuild postBuild preCheck postCheck + preBuild postBuild preInstall postInstall preHaddock postHaddock; } // lib.optionalAttrs (stdenv.buildPlatform.libc == "glibc"){ LOCALE_ARCHIVE = "${buildPackages.glibcLocales}/lib/locale/locale-archive"; } diff --git a/lib/default.nix b/lib/default.nix index ed95685cf7..43aaa1a0d3 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -123,7 +123,7 @@ with haskellLib; # Extracts a selection of components from a Haskell package set. # # This can be used to filter out all test suites or benchmarks of - # your project, so that they can be built in Hydra. + # your project, so that they can be built and run in Hydra. # # For example: # @@ -133,11 +133,24 @@ with haskellLib; # from: hsPkgs.mypackage.components.tests.unit-tests # to: tests.mypackage.unit-tests # - collectComponents = group: packageSel: haskellPackages: + # Note: To build, but not run the components use `collectBuildComponents` + collectRunComponents = group: packageSel: haskellPackages: + collectRunDerivations (collectBuildComponents group packageSel haskellPackages); + + # TODO maybe add warning + collectComponents = collectBuildComponents; + + # Like `collectRunComponents`, but does not build the `run` derivation + # (so your benchmark or test will be built, but not run). + collectBuildComponents = group: packageSel: haskellPackages: (lib.mapAttrs (_: package: package.components.${group} // { recurseForDerivations = true; }) (lib.filterAttrs (name: package: (package.isHaskell or false) && packageSel package) haskellPackages)) // { recurseForDerivations = true; }; + # If a derivation has a passthru.run derivation this will map to that + collectRunDerivations = + lib.mapAttrsRecursiveCond (d: !(lib.isDerivation d)) (_: d: d.run or d); + # Replacement for lib.cleanSourceWith that has a subDir argument. inherit (import ./clean-source-with.nix { inherit lib; }) cleanSourceWith canCleanSource; From 349abfad6b5472c2ca63e2dfd5fd81c8e4979ffe Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Thu, 14 Nov 2019 14:27:45 +1300 Subject: [PATCH 02/46] Reduce duplicate code --- builder/comp-builder.nix | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/builder/comp-builder.nix b/builder/comp-builder.nix index 0fbe498175..16f73a0ee5 100644 --- a/builder/comp-builder.nix +++ b/builder/comp-builder.nix @@ -158,19 +158,7 @@ stdenv.mkDerivation ({ env = shellWrappers; }; - meta = { - homepage = package.homepage; - description = package.synopsis; - license = - let - license-map = import ../lib/cabal-licenses.nix lib; - in license-map.${package.license} or - (builtins.trace "WARNING: license \"${package.license}\" not found" license-map.LicenseRef-OtherLicense); - platforms = if component.platforms == null then stdenv.lib.platforms.all else component.platforms; - }; - - LANG = "en_US.UTF-8"; # GHC needs the locale configured during the Haddock phase. - LC_ALL = "en_US.UTF-8"; + inherit (drv) meta LANG LC_ALL; inherit doCheck doCrossCheck; From cfb1699990db8d7f9bef1fcaee2226afbcdade31 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Thu, 14 Nov 2019 14:33:23 +1300 Subject: [PATCH 03/46] Add comment for passthru.run --- builder/comp-builder.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/builder/comp-builder.nix b/builder/comp-builder.nix index 16f73a0ee5..9655e43bd2 100644 --- a/builder/comp-builder.nix +++ b/builder/comp-builder.nix @@ -146,6 +146,10 @@ stdenv.mkDerivation ({ # The directory containing the haddock documentation. # `null' if no haddock documentation was built. haddockDir = if doHaddock' then "${docdir drv.doc}/html" else null; + + # This run derivation can be used to execute test, benchmark (or even + # exe) components. The $out of the derivation is a file containing + # the resulting stdout output. run = stdenv.mkDerivation ({ name = (fullName + "-run"); From de8c4adc0515538ee895100571a8a94a91fc7bbd Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Thu, 14 Nov 2019 14:40:34 +1300 Subject: [PATCH 04/46] Update docs for collectRunComponents --- docs/reference/library.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/reference/library.md b/docs/reference/library.md index 67e293acf7..48e88a8c00 100644 --- a/docs/reference/library.md +++ b/docs/reference/library.md @@ -247,15 +247,17 @@ Assorted functions for operating on [Haskell.nix][] data. This is distinct from `pkgs.haskell.lib` in the current Nixpkgs Haskell Infrastructure. -### collectComponents +### collectRunComponents and collectBuildComponents -Extracts a selection of components from a Haskell [package set](#package-set). +Extracts a selection of derivations to run components from a Haskell [package set](#package-set). -This can be used to filter out all test suites or benchmarks of -your project, so that they can be built in Hydra. +`collectRunComponents` can be used to filter out all test suites or benchmarks of +your project, so that they can be built and run in Hydra. + +`collectBuildComponents` can be used to just build the components. ``` -collectComponents = +collectRunComponents = group: packageSel: haskellPackages: ... ``` @@ -271,10 +273,10 @@ collectComponents = **Example**: ```nix -tests = collectComponents "tests" (package: package.identifier.name == "mypackage") hsPkgs; +tests = collectRunComponents "tests" (package: package.identifier.name == "mypackage") hsPkgs; ``` -Will result in moving derivations from `hsPkgs.mypackage.components.tests.unit-tests` +Will result in moving derivations from `hsPkgs.mypackage.components.tests.unit-tests.run` to `tests.mypackage.unit-tests`. #### subComponentTypes From b29de0052c38173b201d601c9a2e69a890838848 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Thu, 14 Nov 2019 20:07:09 +1300 Subject: [PATCH 05/46] Update builder/comp-builder.nix Co-Authored-By: Rodney Lorrimar --- builder/comp-builder.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/comp-builder.nix b/builder/comp-builder.nix index 9655e43bd2..af8da058de 100644 --- a/builder/comp-builder.nix +++ b/builder/comp-builder.nix @@ -238,7 +238,7 @@ stdenv.mkDerivation ({ runHook postBuild ''; - checkPhase = ""; + checkPhase = "notice: Tests are only executed by building the .run sub-derivation of this component."; haddockPhase = '' runHook preHaddock From 47e0bb7095393631563200ca3045c426468ff598 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Thu, 14 Nov 2019 20:20:51 +1300 Subject: [PATCH 06/46] `collectBuildComponents` to `collectComponents` --- docs/reference/library.md | 4 ++-- lib/default.nix | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/docs/reference/library.md b/docs/reference/library.md index 48e88a8c00..875ae8a4ea 100644 --- a/docs/reference/library.md +++ b/docs/reference/library.md @@ -247,14 +247,14 @@ Assorted functions for operating on [Haskell.nix][] data. This is distinct from `pkgs.haskell.lib` in the current Nixpkgs Haskell Infrastructure. -### collectRunComponents and collectBuildComponents +### collectRunComponents and collectComponents Extracts a selection of derivations to run components from a Haskell [package set](#package-set). `collectRunComponents` can be used to filter out all test suites or benchmarks of your project, so that they can be built and run in Hydra. -`collectBuildComponents` can be used to just build the components. +`collectComponents` can be used to just build the components. ``` collectRunComponents = diff --git a/lib/default.nix b/lib/default.nix index 43aaa1a0d3..812e4cc0b1 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -133,16 +133,13 @@ with haskellLib; # from: hsPkgs.mypackage.components.tests.unit-tests # to: tests.mypackage.unit-tests # - # Note: To build, but not run the components use `collectBuildComponents` + # Note: To build, but not run the components use `collectComponents` collectRunComponents = group: packageSel: haskellPackages: - collectRunDerivations (collectBuildComponents group packageSel haskellPackages); - - # TODO maybe add warning - collectComponents = collectBuildComponents; + collectRunDerivations (collectComponents group packageSel haskellPackages); # Like `collectRunComponents`, but does not build the `run` derivation # (so your benchmark or test will be built, but not run). - collectBuildComponents = group: packageSel: haskellPackages: + collectComponents = group: packageSel: haskellPackages: (lib.mapAttrs (_: package: package.components.${group} // { recurseForDerivations = true; }) (lib.filterAttrs (name: package: (package.isHaskell or false) && packageSel package) haskellPackages)) // { recurseForDerivations = true; }; From cee580c60ca24e9f6fe50643bfe208eeb3a19c38 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Mon, 18 Nov 2019 17:15:10 +1300 Subject: [PATCH 07/46] Relocate binary for benchmarks/tests (not in all) --- builder/comp-builder.nix | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/builder/comp-builder.nix b/builder/comp-builder.nix index af8da058de..b6dfd71e46 100644 --- a/builder/comp-builder.nix +++ b/builder/comp-builder.nix @@ -117,10 +117,10 @@ let exeExt = lib.optionalString stdenv.hostPlatform.isWindows ".exe"; testExecutable = "dist/build/${componentId.cname}/${componentId.cname}${exeExt}"; - # exe components are in /bin, but test and benchmarks are not. Perhaps to avoid - # them being from being added to the PATH when the all component added to an env. - # TODO revist this to find out why and document or maybe change this. - installedExeDir = if haskellLib.isTest componentId || haskellLib.isBenchmark componentId + # Avoid issues with tests and benchmarks winding up unexpectedly in the `PATH`. + # For example if a package had a test called `gcc` and the `.all` component + # was used as a buildInput, the test would replace `gcc` in the `PATH`. + installedExeDir = if (haskellLib.isTest componentId || haskellLib.isBenchmark componentId) && haskellLib.isAll componentId then name else "bin"; installedExe = "${installedExeDir}/${componentId.cname}${exeExt}"; @@ -296,9 +296,9 @@ stdenv.mkDerivation ({ fi ''} ${(lib.optionalString (haskellLib.isTest componentId || haskellLib.isBenchmark componentId || haskellLib.isAll componentId) '' - mkdir -p $out/${name} + mkdir -p $out/${installedExeDir} if [ -f ${testExecutable} ]; then - cp ${testExecutable} $out/${name}/ + cp ${testExecutable} $out/${installedExeDir}/ fi '') # In case `setup copy` did not creat this From 42c7cce55f95babe4021e8cea511adbd36b79fc4 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Mon, 18 Nov 2019 17:16:36 +1300 Subject: [PATCH 08/46] Add package.run.(exes/tests/benchmaks).${name} --- builder/hspkg-builder.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/builder/hspkg-builder.nix b/builder/hspkg-builder.nix index d5e2656821..1a9b64702e 100644 --- a/builder/hspkg-builder.nix +++ b/builder/hspkg-builder.nix @@ -57,8 +57,10 @@ let ; }; -in { +in rec { components = haskellLib.applyComponents buildComp config; + run = builtins.mapAttrs (_: es: builtins.mapAttrs (_: d: d.run) es) + { inherit (components) exes tests benchmarks; }; inherit (package) identifier detailLevel isLocal; inherit setup cabalFile; isHaskell = true; From a51248c7a59c458df0952dcaee1a9f44e15e7446 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Mon, 18 Nov 2019 17:18:29 +1300 Subject: [PATCH 09/46] Try ln -s instead of cp for DLLs --- builder/comp-builder.nix | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/builder/comp-builder.nix b/builder/comp-builder.nix index b6dfd71e46..b9ddab886b 100644 --- a/builder/comp-builder.nix +++ b/builder/comp-builder.nix @@ -304,17 +304,17 @@ stdenv.mkDerivation ({ # In case `setup copy` did not creat this + (lib.optionalString enableSeparateDataOutput "mkdir -p $data") + (lib.optionalString (stdenv.hostPlatform.isWindows && (haskellLib.mayHaveExecutable componentId)) '' - echo "Copying libffi and gmp .dlls ..." + echo "Symlink libffi and gmp .dlls ..." for p in ${lib.concatStringsSep " " [ libffi gmp ]}; do - find "$p" -iname '*.dll' -exec cp {} $out/${installedExeDir} \; + find "$p" -iname '*.dll' -exec ln -s {} $out/${installedExeDir} \; done - # copy all .dlls into the local directory. + # symlink all .dlls into the local directory. # we ask ghc-pkg for *all* dynamic-library-dirs and then iterate over the unique set - # to copy over dlls as needed. - echo "Copying library dependencies..." + # to symlink over dlls as needed. + echo "Symlink library dependencies..." for libdir in $(x86_64-pc-mingw32-ghc-pkg --package-db=$packageConfDir field "*" dynamic-library-dirs --simple-output|xargs|sed 's/ /\n/g'|sort -u); do if [ -d "$libdir" ]; then - find "$libdir" -iname '*.dll' -exec cp {} $out/${installedExeDir} \; + find "$libdir" -iname '*.dll' -exec ln -s {} $out/${installedExeDir} \; fi done '') From 848c395eb2c3de7c68ba4cb06be302ced0e8ed74 Mon Sep 17 00:00:00 2001 From: Richard Wallace Date: Tue, 19 Nov 2019 17:05:09 -0700 Subject: [PATCH 10/46] improve speed of make-config-files (#318) caches `configure-flags`, `cabal.config`, and `ghc-environment` files per library in the nix store, so the `make-config-files` script just has to append them into the same named files for the package being built instead of using `ghc-pkg dump` and `ghc-pkg register` for each dependency, copies the `.conf` files from the dependencies `package.conf.d` directory and then uses a single `ghc-pkg recache` eliminate the call of `ghc-pkg check` suppress some output of `ghc-pkg` (not related to speed improvements, I'm flexible on rolling this bit back) in my tests, the make-config-files scripts now only take seconds, even for packages that have many many dependencies - prior to this change, this script took more than a minute for such packages --- builder/make-config-files.nix | 71 ++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/builder/make-config-files.nix b/builder/make-config-files.nix index 2289cdc8c2..b4f593a522 100644 --- a/builder/make-config-files.nix +++ b/builder/make-config-files.nix @@ -1,4 +1,4 @@ -{ stdenv, lib, haskellLib, ghc, nonReinstallablePkgs, runCommand }: +{ stdenv, lib, haskellLib, ghc, nonReinstallablePkgs, runCommand, writeText, writeScript }: let flagsAndConfig = field: xs: lib.optionalString (xs != []) '' @@ -6,6 +6,8 @@ let echo "${field}: ${lib.concatStringsSep " " xs}" >> $out/cabal.config ''; + target-pkg = "${ghc.targetPrefix}ghc-pkg"; + # This is a bit of a hack. So we'll have a slightly longer explaination here: # exactDep will pass --exact-configuration to the `SETUP_HS confiugre` command. # This requires us to pass --dependency={dep name}={pkg id}. The dependency @@ -20,38 +22,57 @@ let # sublib name to exactDep, as we don't have access to it at the call-site, # we resort to a bit of globbing, which (as pkg db's should contain only # a single package) work. - exactDep = pdbArg: p: '' - if id=$(target-pkg ${pdbArg} field ${p} id --simple-output); then + exactDep = pdbArg: p: nativeBuildInputs: runCommand "${p}-exactdep" { inherit nativeBuildInputs; } '' + mkdir -p $out + touch $out/configure-flags + touch $out/cabal.config + + if id=$(${target-pkg} ${pdbArg} field ${p} id --simple-output); then echo "--dependency=${p}=$id" >> $out/configure-flags - elif id=$(target-pkg ${pdbArg} field "z-${p}-z-*" id --simple-output); then - name=$(target-pkg ${pdbArg} field "z-${p}-z-*" name --simple-output) + elif id=$(${target-pkg} ${pdbArg} field "z-${p}-z-*" id --simple-output); then + name=$(${target-pkg} ${pdbArg} field "z-${p}-z-*" name --simple-output) # so we are dealing with a sublib. As we build sublibs separately, the above # query should be safe. echo "--dependency=''${name#z-${p}-z-}=$id" >> $out/configure-flags fi - if ver=$(target-pkg ${pdbArg} field ${p} version --simple-output); then + if ver=$(${target-pkg} ${pdbArg} field ${p} version --simple-output); then echo "constraint: ${p} == $ver" >> $out/cabal.config echo "constraint: ${p} installed" >> $out/cabal.config fi ''; - envDep = pdbArg: p: '' - if id=$(target-pkg ${pdbArg} field ${p} id --simple-output); then - echo "package-id $id" >> $out/ghc-environment + catExactDep = dep: '' + cat ${dep}/configure-flags >> $out/configure-flags + cat ${dep}/cabal.config >> $out/cabal.config + ''; + + catPkgExactDep = p: + catExactDep (exactDep (packageDb p) p.identifier.name [ghc (p.components.library or p)]); + + catGhcPkgExactDep = p: catExactDep (exactDep "" p [ghc]); + + envDep = pdbArg: p: nativeBuildInputs: runCommand "${p}-envdep" { inherit nativeBuildInputs; } '' + touch $out + if id=$(${target-pkg} ${pdbArg} field ${p} id --simple-output); then + echo "package-id $id" >> $out fi ''; -in { identifier, component, fullName, flags ? {} }: + catEnvDep = ghcEnv: '' + cat ${ghcEnv} >> $out/ghc-environment + ''; + + catPkgEnvDep = p: + catEnvDep (envDep (packageDb p) p.identifier.name [ghc (p.components.library or p)]); + + catGhcPkgEnvDep = p: catEnvDep (envDep "" p [ghc]); + packageDb = p: "--package-db ${p.components.library or p}/package.conf.d"; +in { identifier, component, fullName, flags ? {} }: runCommand "${fullName}-config" { nativeBuildInputs = [ghc]; } ('' mkdir -p $out - # Calls ghc-pkg for the target platform - target-pkg() { - ${ghc.targetPrefix}ghc-pkg "$@" - } - - target-pkg init $out/package.conf.d + ${target-pkg} init $out/package.conf.d ${lib.concatStringsSep "\n" (lib.mapAttrsToList flagsAndConfig { "extra-lib-dirs" = map (p: "${lib.getLib p}/lib") component.libs; @@ -60,14 +81,12 @@ in { identifier, component, fullName, flags ? {} }: })} # Copy over the nonReinstallablePkgs from the global package db. - # Note: we need to use --global-package-db with ghc-pkg to prevent it - # from looking into the implicit global package db when registering the package. ${lib.concatMapStringsSep "\n" (p: '' - target-pkg describe ${p} | target-pkg --force --global-package-db $out/package.conf.d register - || true + find ${ghc}/lib/${ghc.name}/package.conf.d -name '${p}*.conf' -exec cp -f {} $out/package.conf.d \; '') nonReinstallablePkgs} ${lib.concatMapStringsSep "\n" (p: '' - target-pkg --package-db ${p}/package.conf.d dump | target-pkg --force --package-db $out/package.conf.d register - + cp -f "${p}/package.conf.d/"*.conf $out/package.conf.d '') (haskellLib.flatLibDepends component)} # Note: we pass `clear` first to ensure that we never consult the implicit global package db. @@ -82,16 +101,16 @@ in { identifier, component, fullName, flags ? {} }: cat > $out/ghc-environment <> $out/configure-flags echo "allow-newer: ${identifier.name}:*" >> $out/cabal.config echo "allow-older: ${identifier.name}:*" >> $out/cabal.config - ${lib.concatMapStringsSep "\n" (p: exactDep "--package-db ${p.components.library or p}/package.conf.d" p.identifier.name) component.depends} - ${lib.concatMapStringsSep "\n" (exactDep "") nonReinstallablePkgs} + ${lib.concatMapStringsSep "\n" catPkgExactDep component.depends} + ${lib.concatMapStringsSep "\n" catGhcPkgExactDep nonReinstallablePkgs} '' # This code originates in the `generic-builder.nix` from nixpkgs. However GHC has been fixed @@ -124,7 +143,5 @@ in { identifier, component, fullName, flags ? {} }: sed -i "s,dynamic-library-dirs: .*,dynamic-library-dirs: $dynamicLinksDir," $f done '' + '' - target-pkg --package-db $out/package.conf.d recache - '' + '' - target-pkg --package-db $out/package.conf.d check + ${target-pkg} -v0 --package-db $out/package.conf.d recache '') From b68c60ea454b68a25659d572eb1853be74e7c4f4 Mon Sep 17 00:00:00 2001 From: Richard Wallace Date: Wed, 20 Nov 2019 11:03:43 -0700 Subject: [PATCH 11/46] use ld.gold by default on linux --- builder/comp-builder.nix | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/builder/comp-builder.nix b/builder/comp-builder.nix index 15191c6922..65afa99c8a 100644 --- a/builder/comp-builder.nix +++ b/builder/comp-builder.nix @@ -66,13 +66,24 @@ let "--with-ghc-pkg=${ghc.targetPrefix}ghc-pkg" "--with-hsc2hs=${ghc.targetPrefix}hsc2hs" ] ++ lib.optionals (stdenv.cc != null) - [ # CC - "--with-gcc=${stdenv.cc.targetPrefix}cc" + ( # CC + [ "--with-gcc=${stdenv.cc.targetPrefix}cc" + ] ++ # BINTOOLS - "--with-ld=${stdenv.cc.bintools.targetPrefix}ld" - "--with-ar=${stdenv.cc.bintools.targetPrefix}ar" - "--with-strip=${stdenv.cc.bintools.targetPrefix}strip" - ] ++ [ # other flags + (if stdenv.hostPlatform.isLinux + # use gold as the linker on linux to improve link times + then [ + "--with-ld=${stdenv.cc.bintools.targetPrefix}ld.gold" + "--ghc-option=-optl-fuse-ld=gold" + "--ld-option=-fuse-ld=gold" + ] else [ + "--with-ld=${stdenv.cc.bintools.targetPrefix}ld" + ] + ) ++ [ + "--with-ar=${stdenv.cc.bintools.targetPrefix}ar" + "--with-strip=${stdenv.cc.bintools.targetPrefix}strip" + ] + ) ++ [ # other flags (if dontStrip then "--disable-executable-stripping" else "--enable-executable-stripping") (if dontStrip then "--disable-library-stripping" else "--enable-library-stripping") (if enableLibraryProfiling then "--enable-library-profiling" else "--disable-library-profiling" ) From 4d619a7a6236ace0920ec50923bddb1e65d75b73 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Thu, 21 Nov 2019 14:34:45 +1300 Subject: [PATCH 12/46] Just include checks for compontent.tests This is what most people will want and it means using collecting all the derivations with `release-lib.nix` will work without having to filter out `exes` and `benchmarks`. --- builder/hspkg-builder.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/builder/hspkg-builder.nix b/builder/hspkg-builder.nix index 1a9b64702e..87bda9b5e1 100644 --- a/builder/hspkg-builder.nix +++ b/builder/hspkg-builder.nix @@ -59,8 +59,7 @@ let in rec { components = haskellLib.applyComponents buildComp config; - run = builtins.mapAttrs (_: es: builtins.mapAttrs (_: d: d.run) es) - { inherit (components) exes tests benchmarks; }; + checks = builtins.mapAttrs (_: d: d.run) components.tests; inherit (package) identifier detailLevel isLocal; inherit setup cabalFile; isHaskell = true; From 9b9fa135463c4a0a5c4dfe06476508e46bae62e5 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Wed, 20 Nov 2019 17:09:44 +1300 Subject: [PATCH 13/46] Add ifdInputsOnly and set it to true in relase.nix --- build.nix | 7 ++++--- release.nix | 2 ++ test/default.nix | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/build.nix b/build.nix index 7acf14bad4..3682ce8df8 100644 --- a/build.nix +++ b/build.nix @@ -9,6 +9,7 @@ , crossSystem ? null , config ? {} , nixpkgsArgs ? { inherit system crossSystem; } +, ifdInputsOnly ? false }: let @@ -28,9 +29,9 @@ let })]; } // nixpkgsArgs); haskell = pkgs.haskell-nix; -in rec { - tests = import ./test/default.nix { inherit nixpkgs nixpkgsArgs; }; - +in { + tests = import ./test/default.nix { inherit nixpkgs nixpkgsArgs ifdInputsOnly; }; +} // pkgs.lib.optionalAttrs (!ifdInputsOnly) rec { # Scripts for keeping Hackage and Stackage up to date, and CI tasks. # The dontRecurseIntoAttrs prevents these from building on hydra # as not all of them can work in restricted eval mode (as they diff --git a/release.nix b/release.nix index 6b75de73e2..b7ef66aa4f 100644 --- a/release.nix +++ b/release.nix @@ -2,6 +2,7 @@ , scrubJobs ? true , haskell-nix ? { outPath = ./.; rev = "abcdef"; } , nixpkgsArgs ? {} +, ifdInputsOnly ? true }: let defaultNixpkgs = import ./nixpkgs {}; in @@ -31,6 +32,7 @@ let , ...}@args: import (haskell-nix + /build.nix) (args // { nixpkgsArgs = nixpkgsArgs // { inherit nixpkgs-pin; }; + inherit ifdInputsOnly; }); }); diff --git a/test/default.nix b/test/default.nix index cbed52242a..fbf0b0b1be 100644 --- a/test/default.nix +++ b/test/default.nix @@ -1,6 +1,7 @@ { pkgs ? import nixpkgs ((import ../.) // nixpkgsArgs) , nixpkgs ? ../nixpkgs , nixpkgsArgs ? { } +, ifdInputsOnly ? false }: with pkgs; @@ -9,6 +10,7 @@ let util = import ./util.nix { inherit (pkgs.haskell-nix) cabal-install; }; in pkgs.recurseIntoAttrs { inherit (haskell-nix) haskellNixRoots; +} // pkgs.lib.optionalAttrs (!ifdInputsOnly) { cabal-simple = haskell-nix.callPackage ./cabal-simple { inherit util; }; cabal-simple-prof = haskell-nix.callPackage ./cabal-simple-prof { inherit util; }; cabal-sublib = haskell-nix.callPackage ./cabal-sublib { inherit util; }; From a43d302a56ac9c699e084762507381bf9aff9dea Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Thu, 21 Nov 2019 15:26:19 +1300 Subject: [PATCH 14/46] Reduce CI times by excluding older ghc versions --- overlays/haskell.nix | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/overlays/haskell.nix b/overlays/haskell.nix index 54f1b82904..b9cd084070 100644 --- a/overlays/haskell.nix +++ b/overlays/haskell.nix @@ -378,10 +378,13 @@ self: super: { happy-plan-nix = withInputs self.buildPackages.haskell-nix.bootstrap.packages.happy-project.plan-nix; hscolour-plan-nix = withInputs self.buildPackages.haskell-nix.bootstrap.packages.hscolour-project.plan-nix; ghc-extra-projects = builtins.mapAttrs (_: proj: self.recurseIntoAttrs (withInputs proj.plan-nix)) - (self.lib.filterAttrs (n: _: n != "ghc844" && n != "ghc861" && n != "ghc862" - # There is an issue with GHC 8.6.4 and nixpkgs 19.09, so only build it for 19.03 for now - && (n != "ghc864" || super.lib.versions.majorMinor super.lib.version == "19.03") - ) self.ghc-extra-projects); + (self.lib.filterAttrs (n: _: + n != "ghc844" + && n != "ghc861" + && n != "ghc862" + && n != "ghc863" + && n != "ghc864" + ) self.ghc-extra-projects); }); }; } From a9d867d36ceea21df930950ca379d4693e8fe088 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Thu, 21 Nov 2019 10:10:20 +1300 Subject: [PATCH 15/46] Enable all tests again --- release.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release.nix b/release.nix index b7ef66aa4f..7220561e5f 100644 --- a/release.nix +++ b/release.nix @@ -2,7 +2,7 @@ , scrubJobs ? true , haskell-nix ? { outPath = ./.; rev = "abcdef"; } , nixpkgsArgs ? {} -, ifdInputsOnly ? true +, ifdInputsOnly ? false }: let defaultNixpkgs = import ./nixpkgs {}; in From c54a0392df2f58d7cf7845ebf6c8f9d1c72cdfa8 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Thu, 21 Nov 2019 19:52:45 +1300 Subject: [PATCH 16/46] Test IFD inputs only --- release.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release.nix b/release.nix index 7220561e5f..b7ef66aa4f 100644 --- a/release.nix +++ b/release.nix @@ -2,7 +2,7 @@ , scrubJobs ? true , haskell-nix ? { outPath = ./.; rev = "abcdef"; } , nixpkgsArgs ? {} -, ifdInputsOnly ? false +, ifdInputsOnly ? true }: let defaultNixpkgs = import ./nixpkgs {}; in From d8314a7fd3da63c71176f7a4d8e822afeaca3c67 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Fri, 22 Nov 2019 06:28:48 +1300 Subject: [PATCH 17/46] haskellLib.check instead of passthru.run --- builder/comp-builder.nix | 52 +++------------------- builder/hspkg-builder.nix | 2 +- lib/check.nix | 34 ++++++++++++++ lib/default.nix | 7 ++- overlays/haskell.nix | 2 +- package-set.nix | 2 +- test/buildable/default.nix | 2 +- test/cabal-22/default.nix | 6 +-- test/cabal-simple/default.nix | 2 +- test/cabal-source-repo/default.nix | 4 +- test/cabal-sublib/default.nix | 2 +- test/call-cabal-project-to-nix/default.nix | 4 +- test/call-stack-to-nix/default.nix | 4 +- test/exe-only/default.nix | 4 +- test/ghc-options/cabal.nix | 4 +- test/ghc-options/stack.nix | 4 +- test/project-flags/cabal.nix | 4 +- test/project-flags/stack.nix | 4 +- test/stack-simple/default.nix | 6 +-- 19 files changed, 74 insertions(+), 75 deletions(-) create mode 100644 lib/check.nix diff --git a/builder/comp-builder.nix b/builder/comp-builder.nix index b9ddab886b..f753cb0b89 100644 --- a/builder/comp-builder.nix +++ b/builder/comp-builder.nix @@ -20,8 +20,6 @@ , preHaddock ? component.preHaddock , postHaddock ? component.postHaddock , shellHook ? "" -, doCheck ? component.doCheck || haskellLib.isTest componentId -, doCrossCheck ? component.doCrossCheck || false , dontPatchELF ? true , dontStrip ? true @@ -117,13 +115,7 @@ let exeExt = lib.optionalString stdenv.hostPlatform.isWindows ".exe"; testExecutable = "dist/build/${componentId.cname}/${componentId.cname}${exeExt}"; - # Avoid issues with tests and benchmarks winding up unexpectedly in the `PATH`. - # For example if a package had a test called `gcc` and the `.all` component - # was used as a buildInput, the test would replace `gcc` in the `PATH`. - installedExeDir = if (haskellLib.isTest componentId || haskellLib.isBenchmark componentId) && haskellLib.isAll componentId - then name - else "bin"; - installedExe = "${installedExeDir}/${componentId.cname}${exeExt}"; + installedExe = "bin/${componentId.cname}${exeExt}"; in stdenv.lib.fix (drv: @@ -140,44 +132,12 @@ stdenv.mkDerivation ({ passthru = { inherit (package) identifier; config = component; - inherit configFiles executableToolDepends cleanSrc; + inherit configFiles executableToolDepends cleanSrc installedExe; env = shellWrappers; # The directory containing the haddock documentation. # `null' if no haddock documentation was built. haddockDir = if doHaddock' then "${docdir drv.doc}/html" else null; - - # This run derivation can be used to execute test, benchmark (or even - # exe) components. The $out of the derivation is a file containing - # the resulting stdout output. - run = stdenv.mkDerivation ({ - name = (fullName + "-run"); - - src = drv; - - passthru = { - inherit (package) identifier; - config = component; - inherit configFiles executableToolDepends cleanSrc; - env = shellWrappers; - }; - - inherit (drv) meta LANG LC_ALL; - - inherit doCheck doCrossCheck; - - phases = ["checkPhase"]; - - checkPhase = '' - runHook preCheck - - ${toString component.testWrapper} $src/${installedExe} ${lib.concatStringsSep " " component.testFlags} | tee $out - - runHook postCheck - ''; - } // haskellLib.optionalHooks { - inherit preCheck postCheck; - }); }; meta = { @@ -296,9 +256,9 @@ stdenv.mkDerivation ({ fi ''} ${(lib.optionalString (haskellLib.isTest componentId || haskellLib.isBenchmark componentId || haskellLib.isAll componentId) '' - mkdir -p $out/${installedExeDir} + mkdir -p $out/bin if [ -f ${testExecutable} ]; then - cp ${testExecutable} $out/${installedExeDir}/ + cp ${testExecutable} $out/bin/ fi '') # In case `setup copy` did not creat this @@ -306,7 +266,7 @@ stdenv.mkDerivation ({ + (lib.optionalString (stdenv.hostPlatform.isWindows && (haskellLib.mayHaveExecutable componentId)) '' echo "Symlink libffi and gmp .dlls ..." for p in ${lib.concatStringsSep " " [ libffi gmp ]}; do - find "$p" -iname '*.dll' -exec ln -s {} $out/${installedExeDir} \; + find "$p" -iname '*.dll' -exec ln -s {} $out/bin \; done # symlink all .dlls into the local directory. # we ask ghc-pkg for *all* dynamic-library-dirs and then iterate over the unique set @@ -314,7 +274,7 @@ stdenv.mkDerivation ({ echo "Symlink library dependencies..." for libdir in $(x86_64-pc-mingw32-ghc-pkg --package-db=$packageConfDir field "*" dynamic-library-dirs --simple-output|xargs|sed 's/ /\n/g'|sort -u); do if [ -d "$libdir" ]; then - find "$libdir" -iname '*.dll' -exec ln -s {} $out/${installedExeDir} \; + find "$libdir" -iname '*.dll' -exec ln -s {} $out/bin \; fi done '') diff --git a/builder/hspkg-builder.nix b/builder/hspkg-builder.nix index 87bda9b5e1..7b8573f691 100644 --- a/builder/hspkg-builder.nix +++ b/builder/hspkg-builder.nix @@ -59,7 +59,7 @@ let in rec { components = haskellLib.applyComponents buildComp config; - checks = builtins.mapAttrs (_: d: d.run) components.tests; + checks = builtins.mapAttrs (_: d: haskellLib.check d) components.tests; inherit (package) identifier detailLevel isLocal; inherit setup cabalFile; isHaskell = true; diff --git a/lib/check.nix b/lib/check.nix new file mode 100644 index 0000000000..d346a980fe --- /dev/null +++ b/lib/check.nix @@ -0,0 +1,34 @@ +{ stdenv, lib, haskellLib }: +drv: + +let + component = drv.config; + +# This derivation can be used to execute test component. +# The $out of the derivation is a file containing the resulting +# stdout output. +in stdenv.mkDerivation ({ + name = (drv.name + "-run"); + + src = drv; + + passthru = { + inherit (drv) identifier config configFiles executableToolDepends cleanSrc env; + }; + + inherit (drv) meta LANG LC_ALL; + + inherit (component) doCheck doCrossCheck; + + phases = ["checkPhase"]; + + checkPhase = '' + runHook preCheck + + ${toString component.testWrapper} $src/${drv.installedExe} ${lib.concatStringsSep " " component.testFlags} | tee $out + + runHook postCheck + ''; +} // haskellLib.optionalHooks { + inherit (component) preCheck postCheck; +}) diff --git a/lib/default.nix b/lib/default.nix index 812e4cc0b1..1483a468d4 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,4 +1,4 @@ -{ lib, haskellLib, runCommand, git }: +{ stdenv, lib, haskellLib, runCommand, git }: with haskellLib; @@ -159,4 +159,9 @@ with haskellLib; cleanGit = import ./clean-git.nix { inherit lib runCommand git cleanSourceWith; }; + + # Check a test component + check = import ./check.nix { + inherit stdenv lib haskellLib; + }; } diff --git a/overlays/haskell.nix b/overlays/haskell.nix index b9cd084070..c5cee55b72 100644 --- a/overlays/haskell.nix +++ b/overlays/haskell.nix @@ -59,7 +59,7 @@ self: super: { # Utility functions for working with the component builder. haskellLib = let hl = import ../lib { - inherit (self) lib runCommand; + inherit (self) stdenv lib runCommand; inherit (self.buildPackages) git; haskellLib = hl; }; in hl; diff --git a/package-set.nix b/package-set.nix index b8f2ea9859..6836752c29 100644 --- a/package-set.nix +++ b/package-set.nix @@ -7,7 +7,7 @@ in pkgs.lib.evalModules { _module.args = { # this is *not* the hasekllLib from nixpkgs; it is rather our own # library from haskell.nix - haskellLib = let hl = import ./lib { inherit lib; inherit (pkgs) runCommand git; haskellLib = hl; }; in hl; + haskellLib = let hl = import ./lib { inherit lib; inherit (pkgs) stdenv runCommand git; haskellLib = hl; }; in hl; # The package descriptions depend on pkgs, which are used to resolve system package dependencies # as well as pkgconfPkgs, which are used to resolve pkgconfig name to nixpkgs names. We simply diff --git a/test/buildable/default.nix b/test/buildable/default.nix index b7e703c438..a96d643ef3 100644 --- a/test/buildable/default.nix +++ b/test/buildable/default.nix @@ -19,7 +19,7 @@ in recurseIntoAttrs { buildCommand = (concatStrings (mapAttrsToList (name: value: '' printf "checking whether executable runs... " >& 2 - cat ${value.run} + cat ${haskellLib.check value} '') packages.buildable-test.components.exes)) + '' touch $out ''; diff --git a/test/cabal-22/default.nix b/test/cabal-22/default.nix index 4e1a7d2d55..8bbfe63ad2 100644 --- a/test/cabal-22/default.nix +++ b/test/cabal-22/default.nix @@ -24,7 +24,7 @@ in recurseIntoAttrs { # fixme: run on target platform when cross-compiled printf "checking whether executable rans... " >& 2 - cat ${packages.project.components.exes.project.run} + cat ${haskellLib.check packages.project.components.exes.project} printf "checking that executable is dynamically linked to system libraries... " >& 2 '' + optionalString stdenv.isLinux '' @@ -50,10 +50,10 @@ in recurseIntoAttrs { touch $out printf "checking whether benchmark ran... " >& 2 - cat ${packages.project.components.benchmarks.project-bench.run} + cat ${haskellLib.check packages.project.components.benchmarks.project-bench} printf "checking whether tests ran... " >& 2 - cat ${packages.project.components.tests.unit.run} + cat ${haskellLib.check packages.project.components.tests.unit} ''; meta.platforms = platforms.all; diff --git a/test/cabal-simple/default.nix b/test/cabal-simple/default.nix index deaa452e31..d9b6b32db7 100644 --- a/test/cabal-simple/default.nix +++ b/test/cabal-simple/default.nix @@ -51,7 +51,7 @@ in recurseIntoAttrs { # fixme: run on target platform when cross-compiled printf "checking whether executable runs... " >& 2 - cat ${packages.cabal-simple.components.exes.cabal-simple.run} + cat ${haskellLib.check packages.cabal-simple.components.exes.cabal-simple} '' + (if stdenv.hostPlatform.isMusl then '' printf "checking that executable is statically linked... " >& 2 (ldd $exe 2>&1 || true) | grep -i "not a" diff --git a/test/cabal-source-repo/default.nix b/test/cabal-source-repo/default.nix index 14d97e4c4f..69f98f3303 100644 --- a/test/cabal-source-repo/default.nix +++ b/test/cabal-source-repo/default.nix @@ -1,4 +1,4 @@ -{ stdenv, cabalProject', recurseIntoAttrs }: +{ stdenv, cabalProject', recurseIntoAttrs, haskellLib }: with stdenv.lib; @@ -18,7 +18,7 @@ in recurseIntoAttrs { exe="${packages.use-cabal-simple.components.exes.use-cabal-simple}/bin/use-cabal-simple${stdenv.hostPlatform.extensions.executable}" printf "checking whether executable runs... " >& 2 - cat ${packages.use-cabal-simple.components.exes.use-cabal-simple.run} + cat ${haskellLib.check packages.use-cabal-simple.components.exes.use-cabal-simple} touch $out ''; diff --git a/test/cabal-sublib/default.nix b/test/cabal-sublib/default.nix index 7b2fa79822..8896a98ae3 100644 --- a/test/cabal-sublib/default.nix +++ b/test/cabal-sublib/default.nix @@ -34,7 +34,7 @@ in recurseIntoAttrs { # fixme: run on target platform when cross-compiled printf "checking whether executable runs... " >& 2 - cat ${packages.cabal-sublib.components.exes.cabal-sublib.run} + cat ${haskellLib.check packages.cabal-sublib.components.exes.cabal-sublib} printf "checking that executable is dynamically linked to system libraries... " >& 2 '' + optionalString stdenv.isLinux '' diff --git a/test/call-cabal-project-to-nix/default.nix b/test/call-cabal-project-to-nix/default.nix index 5d3dadbd97..418cd84074 100644 --- a/test/call-cabal-project-to-nix/default.nix +++ b/test/call-cabal-project-to-nix/default.nix @@ -1,4 +1,4 @@ -{ stdenv, mkCabalProjectPkgSet, callCabalProjectToNix, importAndFilterProject, recurseIntoAttrs }: +{ stdenv, mkCabalProjectPkgSet, callCabalProjectToNix, importAndFilterProject, recurseIntoAttrs, haskellLib }: with stdenv.lib; @@ -25,7 +25,7 @@ in recurseIntoAttrs { exe="${packages.cabal-simple.components.exes.cabal-simple}/bin/cabal-simple${stdenv.hostPlatform.extensions.executable}" printf "checking whether executable runs... " >& 2 - cat ${packages.cabal-simple.components.exes.cabal-simple.run} + cat ${haskellLib.check packages.cabal-simple.components.exes.cabal-simple} touch $out ''; diff --git a/test/call-stack-to-nix/default.nix b/test/call-stack-to-nix/default.nix index 2bacfea781..6dba3998ed 100644 --- a/test/call-stack-to-nix/default.nix +++ b/test/call-stack-to-nix/default.nix @@ -1,4 +1,4 @@ -{ stdenv, mkStackPkgSet, callStackToNix, importAndFilterProject, recurseIntoAttrs }: +{ stdenv, mkStackPkgSet, callStackToNix, importAndFilterProject, recurseIntoAttrs, haskellLib }: with stdenv.lib; @@ -22,7 +22,7 @@ in recurseIntoAttrs { exe="${packages.stack-simple.components.exes.stack-simple-exe}/bin/stack-simple-exe${stdenv.hostPlatform.extensions.executable}" printf "checking whether executable runs... " >& 2 - cat ${packages.stack-simple.components.exes.stack-simple-exe.run} + cat ${haskellLib.check packages.stack-simple.components.exes.stack-simple-exe} touch $out ''; diff --git a/test/exe-only/default.nix b/test/exe-only/default.nix index baaf91dfca..55d10a9c70 100644 --- a/test/exe-only/default.nix +++ b/test/exe-only/default.nix @@ -1,5 +1,5 @@ # Test a package set -{ stdenv, util, haskell-nix, recurseIntoAttrs }: +{ stdenv, util, haskell-nix, recurseIntoAttrs, haskellLib }: with stdenv.lib; @@ -24,7 +24,7 @@ in recurseIntoAttrs { # fixme: run on target platform when cross-compiled printf "checking whether executable ran... " >& 2 - cat ${packages.exe-only.components.exes.exe-only.run} + cat ${haskellLib.check packages.exe-only.components.exes.exe-only} '' + (if stdenv.hostPlatform.isMusl then '' printf "checking that executable is statically linked... " >& 2 (ldd $exe 2>&1 || true) | grep -i "not a" diff --git a/test/ghc-options/cabal.nix b/test/ghc-options/cabal.nix index 6569ab2321..4dbcb06423 100644 --- a/test/ghc-options/cabal.nix +++ b/test/ghc-options/cabal.nix @@ -1,4 +1,4 @@ -{ stdenv, cabalProject', recurseIntoAttrs }: +{ stdenv, cabalProject', recurseIntoAttrs, haskellLib }: with stdenv.lib; @@ -19,7 +19,7 @@ in recurseIntoAttrs { buildCommand = '' printf "checking whether executable runs... " >& 2 - cat ${packages.test-ghc-options.components.exes.test-ghc-options-exe.run} + cat ${haskellLib.check packages.test-ghc-options.components.exes.test-ghc-options-exe} touch $out ''; diff --git a/test/ghc-options/stack.nix b/test/ghc-options/stack.nix index 9b3bdc16b5..f981d4e2c2 100644 --- a/test/ghc-options/stack.nix +++ b/test/ghc-options/stack.nix @@ -1,4 +1,4 @@ -{ stdenv, stackProject', recurseIntoAttrs }: +{ stdenv, stackProject', recurseIntoAttrs, haskellLib }: with stdenv.lib; @@ -15,7 +15,7 @@ in recurseIntoAttrs { buildCommand = '' printf "checking whether executable runs... " >& 2 - cat ${packages.test-ghc-options.components.exes.test-ghc-options-exe.run} + cat ${haskellLib.check packages.test-ghc-options.components.exes.test-ghc-options-exe} touch $out ''; diff --git a/test/project-flags/cabal.nix b/test/project-flags/cabal.nix index 76c7fc1cf2..9b218de547 100644 --- a/test/project-flags/cabal.nix +++ b/test/project-flags/cabal.nix @@ -1,4 +1,4 @@ -{ stdenv, cabalProject', recurseIntoAttrs }: +{ stdenv, cabalProject', recurseIntoAttrs, haskellLib }: with stdenv.lib; @@ -19,7 +19,7 @@ in recurseIntoAttrs { exe="${packages.test-project-flags.components.exes.test-project-flags-exe}/bin/test-project-flags-exe${stdenv.hostPlatform.extensions.executable}" printf "checking whether executable runs... " >& 2 - cat ${packages.test-project-flags.components.exes.test-project-flags-exe.run} + cat ${haskellLib.check packages.test-project-flags.components.exes.test-project-flags-exe} touch $out ''; diff --git a/test/project-flags/stack.nix b/test/project-flags/stack.nix index de16d6e1ed..00ee0cb71f 100644 --- a/test/project-flags/stack.nix +++ b/test/project-flags/stack.nix @@ -1,4 +1,4 @@ -{ stdenv, stackProject', recurseIntoAttrs }: +{ stdenv, stackProject', recurseIntoAttrs, haskellLib }: with stdenv.lib; @@ -17,7 +17,7 @@ in recurseIntoAttrs { exe="${packages.test-project-flags.components.exes.test-project-flags-exe}/bin/test-project-flags-exe${stdenv.hostPlatform.extensions.executable}" printf "checking whether executable runs... " >& 2 - cat ${packages.test-project-flags.components.exes.test-project-flags-exe.run} + cat ${haskellLib.check packages.test-project-flags.components.exes.test-project-flags-exe} touch $out ''; diff --git a/test/stack-simple/default.nix b/test/stack-simple/default.nix index 56ab1c361f..40bca92b4c 100644 --- a/test/stack-simple/default.nix +++ b/test/stack-simple/default.nix @@ -1,4 +1,4 @@ -{ stdenv, pkgs, mkStackPkgSet }: +{ stdenv, pkgs, mkStackPkgSet, haskellLib }: with stdenv.lib; @@ -14,9 +14,9 @@ let packages = pkgSet.config.hsPkgs; in pkgs.recurseIntoAttrs { - stack-simple-exe = packages.stack-simple.components.exes.stack-simple-exe.run // { + stack-simple-exe = (haskellLib.check packages.stack-simple.components.exes.stack-simple-exe) // { # Attributes used for debugging with nix repl inherit pkgSet packages; }; - stack-simple-test = packages.stack-simple.components.tests.stack-simple-test.run; + stack-simple-test = haskellLib.check packages.stack-simple.components.tests.stack-simple-test; } From b6975b5acb21c561a389539d7c27f4801b2b550e Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Fri, 22 Nov 2019 10:29:34 +1300 Subject: [PATCH 18/46] Enable all tests again --- release.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release.nix b/release.nix index b7ef66aa4f..7220561e5f 100644 --- a/release.nix +++ b/release.nix @@ -2,7 +2,7 @@ , scrubJobs ? true , haskell-nix ? { outPath = ./.; rev = "abcdef"; } , nixpkgsArgs ? {} -, ifdInputsOnly ? true +, ifdInputsOnly ? false }: let defaultNixpkgs = import ./nixpkgs {}; in From cf15c36868a20fd9becca5aa41abdb8a9fe0527c Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Fri, 22 Nov 2019 13:03:33 +1300 Subject: [PATCH 19/46] Default doCheck=true. Filter checks on doCheck --- builder/hspkg-builder.nix | 4 +++- lib/check.nix | 10 ++++++++-- modules/plan.nix | 2 +- test/stack-simple/default.nix | 3 ++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/builder/hspkg-builder.nix b/builder/hspkg-builder.nix index 7b8573f691..b244cde960 100644 --- a/builder/hspkg-builder.nix +++ b/builder/hspkg-builder.nix @@ -59,7 +59,9 @@ let in rec { components = haskellLib.applyComponents buildComp config; - checks = builtins.mapAttrs (_: d: haskellLib.check d) components.tests; + checks = pkgs.recurseIntoAttrs (builtins.mapAttrs + (_: d: haskellLib.check d) + (lib.filterAttrs (_: d: d.config.doCheck) components.tests)); inherit (package) identifier detailLevel isLocal; inherit setup cabalFile; isHaskell = true; diff --git a/lib/check.nix b/lib/check.nix index d346a980fe..6b5e1ea0b3 100644 --- a/lib/check.nix +++ b/lib/check.nix @@ -8,7 +8,7 @@ let # The $out of the derivation is a file containing the resulting # stdout output. in stdenv.mkDerivation ({ - name = (drv.name + "-run"); + name = (drv.name + "-check"); src = drv; @@ -20,7 +20,13 @@ in stdenv.mkDerivation ({ inherit (component) doCheck doCrossCheck; - phases = ["checkPhase"]; + phases = ["buildPhase" "checkPhase"]; + + # If doCheck or doCrossCheck are false we may still build this + # component and we want it to quietly succeed. + buildPhase = '' + touch $out + ''; checkPhase = '' runHook preCheck diff --git a/modules/plan.nix b/modules/plan.nix index e2755ddafc..d604b1d7cb 100644 --- a/modules/plan.nix +++ b/modules/plan.nix @@ -81,7 +81,7 @@ let }; doCheck = mkOption { type = bool; - default = (def.doCheck or false); + default = (def.doCheck or true); }; doCrossCheck = mkOption { description = "Run doCheck also in cross compilation settings. This can be tricky as the test logic must know how to run the tests on the target."; diff --git a/test/stack-simple/default.nix b/test/stack-simple/default.nix index 40bca92b4c..f476347a2f 100644 --- a/test/stack-simple/default.nix +++ b/test/stack-simple/default.nix @@ -18,5 +18,6 @@ in pkgs.recurseIntoAttrs { # Attributes used for debugging with nix repl inherit pkgSet packages; }; - stack-simple-test = haskellLib.check packages.stack-simple.components.tests.stack-simple-test; + stack-simple-test = packages.stack-simple.checks.stack-simple-test; + stack-simple-checks = packages.stack-simple.checks; } From d07ffb0f90af4e1c45b3b9b4732ca73c3af584c3 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Wed, 20 Nov 2019 17:09:44 +1300 Subject: [PATCH 20/46] Add ifdInputsOnly and set it to true in relase.nix --- build.nix | 7 ++++--- release.nix | 2 ++ test/default.nix | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/build.nix b/build.nix index 7acf14bad4..3682ce8df8 100644 --- a/build.nix +++ b/build.nix @@ -9,6 +9,7 @@ , crossSystem ? null , config ? {} , nixpkgsArgs ? { inherit system crossSystem; } +, ifdInputsOnly ? false }: let @@ -28,9 +29,9 @@ let })]; } // nixpkgsArgs); haskell = pkgs.haskell-nix; -in rec { - tests = import ./test/default.nix { inherit nixpkgs nixpkgsArgs; }; - +in { + tests = import ./test/default.nix { inherit nixpkgs nixpkgsArgs ifdInputsOnly; }; +} // pkgs.lib.optionalAttrs (!ifdInputsOnly) rec { # Scripts for keeping Hackage and Stackage up to date, and CI tasks. # The dontRecurseIntoAttrs prevents these from building on hydra # as not all of them can work in restricted eval mode (as they diff --git a/release.nix b/release.nix index 6b75de73e2..b7ef66aa4f 100644 --- a/release.nix +++ b/release.nix @@ -2,6 +2,7 @@ , scrubJobs ? true , haskell-nix ? { outPath = ./.; rev = "abcdef"; } , nixpkgsArgs ? {} +, ifdInputsOnly ? true }: let defaultNixpkgs = import ./nixpkgs {}; in @@ -31,6 +32,7 @@ let , ...}@args: import (haskell-nix + /build.nix) (args // { nixpkgsArgs = nixpkgsArgs // { inherit nixpkgs-pin; }; + inherit ifdInputsOnly; }); }); diff --git a/test/default.nix b/test/default.nix index cbed52242a..fbf0b0b1be 100644 --- a/test/default.nix +++ b/test/default.nix @@ -1,6 +1,7 @@ { pkgs ? import nixpkgs ((import ../.) // nixpkgsArgs) , nixpkgs ? ../nixpkgs , nixpkgsArgs ? { } +, ifdInputsOnly ? false }: with pkgs; @@ -9,6 +10,7 @@ let util = import ./util.nix { inherit (pkgs.haskell-nix) cabal-install; }; in pkgs.recurseIntoAttrs { inherit (haskell-nix) haskellNixRoots; +} // pkgs.lib.optionalAttrs (!ifdInputsOnly) { cabal-simple = haskell-nix.callPackage ./cabal-simple { inherit util; }; cabal-simple-prof = haskell-nix.callPackage ./cabal-simple-prof { inherit util; }; cabal-sublib = haskell-nix.callPackage ./cabal-sublib { inherit util; }; From 013c0fda27b65933c121ccae10e194e32f94fb00 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Thu, 21 Nov 2019 15:26:19 +1300 Subject: [PATCH 21/46] Reduce CI times by excluding older ghc versions --- overlays/haskell.nix | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/overlays/haskell.nix b/overlays/haskell.nix index 54f1b82904..b9cd084070 100644 --- a/overlays/haskell.nix +++ b/overlays/haskell.nix @@ -378,10 +378,13 @@ self: super: { happy-plan-nix = withInputs self.buildPackages.haskell-nix.bootstrap.packages.happy-project.plan-nix; hscolour-plan-nix = withInputs self.buildPackages.haskell-nix.bootstrap.packages.hscolour-project.plan-nix; ghc-extra-projects = builtins.mapAttrs (_: proj: self.recurseIntoAttrs (withInputs proj.plan-nix)) - (self.lib.filterAttrs (n: _: n != "ghc844" && n != "ghc861" && n != "ghc862" - # There is an issue with GHC 8.6.4 and nixpkgs 19.09, so only build it for 19.03 for now - && (n != "ghc864" || super.lib.versions.majorMinor super.lib.version == "19.03") - ) self.ghc-extra-projects); + (self.lib.filterAttrs (n: _: + n != "ghc844" + && n != "ghc861" + && n != "ghc862" + && n != "ghc863" + && n != "ghc864" + ) self.ghc-extra-projects); }); }; } From 896854b700dd60c1296a3b1b8f8ae63aed272c6f Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Fri, 22 Nov 2019 10:29:34 +1300 Subject: [PATCH 22/46] Enable all tests again --- release.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release.nix b/release.nix index b7ef66aa4f..7220561e5f 100644 --- a/release.nix +++ b/release.nix @@ -2,7 +2,7 @@ , scrubJobs ? true , haskell-nix ? { outPath = ./.; rev = "abcdef"; } , nixpkgsArgs ? {} -, ifdInputsOnly ? true +, ifdInputsOnly ? false }: let defaultNixpkgs = import ./nixpkgs {}; in From 64afed97657b65df935ddada8a0622407dfe3108 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sat, 23 Nov 2019 23:10:42 +1300 Subject: [PATCH 23/46] Improve ifdInputsOnly to include more ifd inputs --- release.nix | 2 +- test/buildable/default.nix | 4 +++- test/cabal-22/default.nix | 4 +++- test/cabal-simple-prof/default.nix | 4 +++- test/cabal-simple/default.nix | 4 +++- test/cabal-source-repo/default.nix | 4 +++- test/cabal-sublib/default.nix | 4 +++- test/call-cabal-project-to-nix/default.nix | 4 +++- test/call-stack-to-nix/default.nix | 4 +++- test/default.nix | 4 +++- test/exe-only/default.nix | 4 +++- test/fully-static/default.nix | 6 ++++-- test/ghc-options/stack.nix | 4 +++- test/project-flags/cabal.nix | 4 +++- test/project-flags/stack.nix | 4 +++- test/setup-deps/default.nix | 4 +++- test/shell-for-setup-deps/default.nix | 4 +++- 17 files changed, 50 insertions(+), 18 deletions(-) diff --git a/release.nix b/release.nix index 7220561e5f..b7ef66aa4f 100644 --- a/release.nix +++ b/release.nix @@ -2,7 +2,7 @@ , scrubJobs ? true , haskell-nix ? { outPath = ./.; rev = "abcdef"; } , nixpkgsArgs ? {} -, ifdInputsOnly ? false +, ifdInputsOnly ? true }: let defaultNixpkgs = import ./nixpkgs {}; in diff --git a/test/buildable/default.nix b/test/buildable/default.nix index b7e703c438..fd990ca0b1 100644 --- a/test/buildable/default.nix +++ b/test/buildable/default.nix @@ -12,7 +12,9 @@ let packages = project.hsPkgs; in recurseIntoAttrs { - inherit (project) plan-nix; + ifdInputs = recurseIntoAttrs { + inherit (project) plan-nix; + }; run = stdenv.mkDerivation { name = "buildable-test"; diff --git a/test/cabal-22/default.nix b/test/cabal-22/default.nix index 4e1a7d2d55..8b6b7af756 100644 --- a/test/cabal-22/default.nix +++ b/test/cabal-22/default.nix @@ -11,7 +11,9 @@ let packages = project.hsPkgs; in recurseIntoAttrs { - inherit (project) plan-nix; + ifdInputs = recurseIntoAttrs { + inherit (project) plan-nix; + }; shell = util.addCabalInstall packages.project.components.all; run = stdenv.mkDerivation { name = "cabal-22-test"; diff --git a/test/cabal-simple-prof/default.nix b/test/cabal-simple-prof/default.nix index 39c03c84bc..2cbfd78363 100644 --- a/test/cabal-simple-prof/default.nix +++ b/test/cabal-simple-prof/default.nix @@ -24,7 +24,9 @@ let packages = project.hsPkgs; in recurseIntoAttrs { - inherit (project) plan-nix; + ifdInputs = recurseIntoAttrs { + inherit (project) plan-nix; + }; run = stdenv.mkDerivation { name = "cabal-simple-prof-test"; diff --git a/test/cabal-simple/default.nix b/test/cabal-simple/default.nix index deaa452e31..f76771ec84 100644 --- a/test/cabal-simple/default.nix +++ b/test/cabal-simple/default.nix @@ -34,7 +34,9 @@ let packages = project.hsPkgs; in recurseIntoAttrs { - inherit (project) plan-nix; + ifdInputs = recurseIntoAttrs { + inherit (project) plan-nix; + }; # Used for testing externally with nix-shell (../tests.sh). # This just adds cabal-install to the existing shells. diff --git a/test/cabal-source-repo/default.nix b/test/cabal-source-repo/default.nix index 14d97e4c4f..dd582e5de7 100644 --- a/test/cabal-source-repo/default.nix +++ b/test/cabal-source-repo/default.nix @@ -10,7 +10,9 @@ let }; packages = project.hsPkgs; in recurseIntoAttrs { - inherit (project) plan-nix; + ifdInputs = recurseIntoAttrs { + inherit (project) plan-nix; + }; run = stdenv.mkDerivation { name = "call-cabal-project-to-nix-test"; diff --git a/test/cabal-sublib/default.nix b/test/cabal-sublib/default.nix index 7b2fa79822..307a19d6a2 100644 --- a/test/cabal-sublib/default.nix +++ b/test/cabal-sublib/default.nix @@ -22,7 +22,9 @@ let packages = project.hsPkgs; in recurseIntoAttrs { - inherit (project) plan-nix; + ifdInputs = recurseIntoAttrs { + inherit (project) plan-nix; + }; run = stdenv.mkDerivation { name = "cabal-sublib-test"; diff --git a/test/call-cabal-project-to-nix/default.nix b/test/call-cabal-project-to-nix/default.nix index 5d3dadbd97..d8ed73b2e1 100644 --- a/test/call-cabal-project-to-nix/default.nix +++ b/test/call-cabal-project-to-nix/default.nix @@ -17,7 +17,9 @@ let packages = pkgSet.config.hsPkgs; in recurseIntoAttrs { - plan-nix = plan.nix; + ifdInputs = recurseIntoAttrs { + plan-nix = plan.nix; + }; run = stdenv.mkDerivation { name = "call-cabal-project-to-nix-test"; diff --git a/test/call-stack-to-nix/default.nix b/test/call-stack-to-nix/default.nix index 2bacfea781..1e779f14e1 100644 --- a/test/call-stack-to-nix/default.nix +++ b/test/call-stack-to-nix/default.nix @@ -14,7 +14,9 @@ let packages = pkgSet.config.hsPkgs; in recurseIntoAttrs { - stack-nix = stack.nix; + ifdInputs = recurseIntoAttrs { + stack-nix = stack.nix; + }; run = stdenv.mkDerivation { name = "callStackToNix-test"; diff --git a/test/default.nix b/test/default.nix index fbf0b0b1be..09d263aea5 100644 --- a/test/default.nix +++ b/test/default.nix @@ -10,7 +10,9 @@ let util = import ./util.nix { inherit (pkgs.haskell-nix) cabal-install; }; in pkgs.recurseIntoAttrs { inherit (haskell-nix) haskellNixRoots; -} // pkgs.lib.optionalAttrs (!ifdInputsOnly) { +} // (if ifdInputsOnly + then builtins.mapAttrs (_: d: d.filterAttrs (n: _: n == ifdInputs) + else x: x) { cabal-simple = haskell-nix.callPackage ./cabal-simple { inherit util; }; cabal-simple-prof = haskell-nix.callPackage ./cabal-simple-prof { inherit util; }; cabal-sublib = haskell-nix.callPackage ./cabal-sublib { inherit util; }; diff --git a/test/exe-only/default.nix b/test/exe-only/default.nix index baaf91dfca..81fcdbe660 100644 --- a/test/exe-only/default.nix +++ b/test/exe-only/default.nix @@ -12,7 +12,9 @@ let packages = project.hsPkgs; in recurseIntoAttrs { - inherit (project) plan-nix; + ifdInputs = recurseIntoAttrs { + inherit (project) plan-nix; + }; run = stdenv.mkDerivation { name = "exe-only-test"; diff --git a/test/fully-static/default.nix b/test/fully-static/default.nix index 44ae613627..a81fae613f 100644 --- a/test/fully-static/default.nix +++ b/test/fully-static/default.nix @@ -53,8 +53,10 @@ let packagesIntegerSimple = (project { gpl = false; }).hsPkgs; in recurseIntoAttrs { - stack-nix-gmp = (project { gpl = true; }).stack-nix; - stack-nix-simple = (project { gpl = false; }).stack-nix; + ifdInputs = recurseIntoAttrs { + stack-nix-gmp = (project { gpl = true; }).stack-nix; + stack-nix-simple = (project { gpl = false; }).stack-nix; + }; run = stdenv.mkDerivation { name = "fully-static-test"; diff --git a/test/ghc-options/stack.nix b/test/ghc-options/stack.nix index 9b3bdc16b5..6a151058eb 100644 --- a/test/ghc-options/stack.nix +++ b/test/ghc-options/stack.nix @@ -9,7 +9,9 @@ let packages = project.hsPkgs; in recurseIntoAttrs { - inherit (project) stack-nix; + ifdInputs = recurseIntoAttrs { + inherit (project) stack-nix; + }; run = stdenv.mkDerivation { name = "callStackToNix-test"; diff --git a/test/project-flags/cabal.nix b/test/project-flags/cabal.nix index 76c7fc1cf2..084f286b2f 100644 --- a/test/project-flags/cabal.nix +++ b/test/project-flags/cabal.nix @@ -11,7 +11,9 @@ let packages = project.hsPkgs; in recurseIntoAttrs { - inherit (project) plan-nix; + ifdInputs = recurseIntoAttrs { + inherit (project) plan-nix; + }; run = stdenv.mkDerivation { name = "call-cabal-project-to-nix-test"; diff --git a/test/project-flags/stack.nix b/test/project-flags/stack.nix index de16d6e1ed..be4a3417b6 100644 --- a/test/project-flags/stack.nix +++ b/test/project-flags/stack.nix @@ -9,7 +9,9 @@ let packages = project.hsPkgs; in recurseIntoAttrs { - inherit (project) stack-nix; + ifdInputs = recurseIntoAttrs { + inherit (project) stack-nix; + }; run = stdenv.mkDerivation { name = "callStackToNix-test"; diff --git a/test/setup-deps/default.nix b/test/setup-deps/default.nix index 995c98f29b..c66bf919f4 100644 --- a/test/setup-deps/default.nix +++ b/test/setup-deps/default.nix @@ -27,7 +27,9 @@ in recurseIntoAttrs (if stdenv.hostPlatform.isWindows run = skip; } else { - inherit (project) plan-nix; + ifdInputs = recurseIntoAttrs { + inherit (project) plan-nix; + }; run = pkgs.stdenv.mkDerivation { name = "setup-deps-test"; diff --git a/test/shell-for-setup-deps/default.nix b/test/shell-for-setup-deps/default.nix index d6cb710edc..57946f8700 100644 --- a/test/shell-for-setup-deps/default.nix +++ b/test/shell-for-setup-deps/default.nix @@ -27,7 +27,9 @@ in recurseIntoAttrs (if stdenv.hostPlatform.isWindows run = skip; } else { - inherit (project) plan-nix; + ifdInputs = recurseIntoAttrs { + inherit (project) plan-nix; + }; inherit env; run = stdenv.mkDerivation { name = "shell-for-test"; From 3ce1b29aef835d45cc639d4f332c01a784573041 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sun, 24 Nov 2019 00:12:03 +1300 Subject: [PATCH 24/46] Improve ifdInputsOnly to include more ifd inputs --- test/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/default.nix b/test/default.nix index 09d263aea5..4a8c972f44 100644 --- a/test/default.nix +++ b/test/default.nix @@ -11,7 +11,7 @@ let in pkgs.recurseIntoAttrs { inherit (haskell-nix) haskellNixRoots; } // (if ifdInputsOnly - then builtins.mapAttrs (_: d: d.filterAttrs (n: _: n == ifdInputs) + then builtins.mapAttrs (_: d: pkgs.lib.filterAttrs (n: _: n == ifdInputs) d) else x: x) { cabal-simple = haskell-nix.callPackage ./cabal-simple { inherit util; }; cabal-simple-prof = haskell-nix.callPackage ./cabal-simple-prof { inherit util; }; From 64689a4650cd3045945374978ac4f6515369ca9a Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sun, 24 Nov 2019 00:13:44 +1300 Subject: [PATCH 25/46] Improve ifdInputsOnly to include more ifd inputs --- test/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/default.nix b/test/default.nix index 4a8c972f44..295a7d9261 100644 --- a/test/default.nix +++ b/test/default.nix @@ -11,7 +11,7 @@ let in pkgs.recurseIntoAttrs { inherit (haskell-nix) haskellNixRoots; } // (if ifdInputsOnly - then builtins.mapAttrs (_: d: pkgs.lib.filterAttrs (n: _: n == ifdInputs) d) + then builtins.mapAttrs (_: d: pkgs.lib.filterAttrs (n: _: n == "ifdInputs") d) else x: x) { cabal-simple = haskell-nix.callPackage ./cabal-simple { inherit util; }; cabal-simple-prof = haskell-nix.callPackage ./cabal-simple-prof { inherit util; }; From bf5dc775ad13d1b58c96da9b294e96a9101cf538 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sun, 24 Nov 2019 00:19:36 +1300 Subject: [PATCH 26/46] Improve ifdInputsOnly to include more ifd inputs --- test/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/default.nix b/test/default.nix index 295a7d9261..b2b26bfbb2 100644 --- a/test/default.nix +++ b/test/default.nix @@ -11,7 +11,7 @@ let in pkgs.recurseIntoAttrs { inherit (haskell-nix) haskellNixRoots; } // (if ifdInputsOnly - then builtins.mapAttrs (_: d: pkgs.lib.filterAttrs (n: _: n == "ifdInputs") d) + then builtins.mapAttrs (_: d: pkgs.recurseIntoAttrs (pkgs.lib.filterAttrs (n: _: n == "ifdInputs") d)) else x: x) { cabal-simple = haskell-nix.callPackage ./cabal-simple { inherit util; }; cabal-simple-prof = haskell-nix.callPackage ./cabal-simple-prof { inherit util; }; From 79a7f9fe813b35546a309b7e44be30185641ac21 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sun, 24 Nov 2019 00:24:23 +1300 Subject: [PATCH 27/46] Improve ifdInputsOnly to include more ifd inputs --- test/setup-deps/default.nix | 2 +- test/shell-for-setup-deps/default.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/setup-deps/default.nix b/test/setup-deps/default.nix index c66bf919f4..736eb5d6e3 100644 --- a/test/setup-deps/default.nix +++ b/test/setup-deps/default.nix @@ -23,7 +23,7 @@ in recurseIntoAttrs (if stdenv.hostPlatform.isWindows touch $out ''; in { - plan-nix = skip; + ifdInputs = recurseIntoAttrs { plan-nix = skip; }; run = skip; } else { diff --git a/test/shell-for-setup-deps/default.nix b/test/shell-for-setup-deps/default.nix index 57946f8700..47286ca33c 100644 --- a/test/shell-for-setup-deps/default.nix +++ b/test/shell-for-setup-deps/default.nix @@ -22,7 +22,7 @@ in recurseIntoAttrs (if stdenv.hostPlatform.isWindows touch $out ''; in { - plan-nix = skip; + ifdInputs = recurseIntoAttrs { plan-nix = skip; }; env = skip; run = skip; } From ec4a4ebba596f85ac9a967fba08cbd5ac2c1c3ac Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sun, 24 Nov 2019 10:22:29 +1300 Subject: [PATCH 28/46] Enable all tests again --- release.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release.nix b/release.nix index b7ef66aa4f..7220561e5f 100644 --- a/release.nix +++ b/release.nix @@ -2,7 +2,7 @@ , scrubJobs ? true , haskell-nix ? { outPath = ./.; rev = "abcdef"; } , nixpkgsArgs ? {} -, ifdInputsOnly ? true +, ifdInputsOnly ? false }: let defaultNixpkgs = import ./nixpkgs {}; in From e8fae601737cbade1f7a1007f4158ee397cb1053 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sun, 24 Nov 2019 12:08:44 +1300 Subject: [PATCH 29/46] ifdInputs only --- release.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release.nix b/release.nix index 7220561e5f..b7ef66aa4f 100644 --- a/release.nix +++ b/release.nix @@ -2,7 +2,7 @@ , scrubJobs ? true , haskell-nix ? { outPath = ./.; rev = "abcdef"; } , nixpkgsArgs ? {} -, ifdInputsOnly ? false +, ifdInputsOnly ? true }: let defaultNixpkgs = import ./nixpkgs {}; in From c6ab443375526b339212246eb87e67035b8b923f Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sun, 24 Nov 2019 12:47:36 +1300 Subject: [PATCH 30/46] Include build inputs of ifd nix derivations --- overlays/haskell.nix | 4 ++-- test/buildable/default.nix | 2 +- test/cabal-22/default.nix | 2 +- test/cabal-simple-prof/default.nix | 2 +- test/cabal-simple/default.nix | 2 +- test/cabal-source-repo/default.nix | 2 +- test/cabal-sublib/default.nix | 2 +- test/call-cabal-project-to-nix/default.nix | 2 +- test/call-stack-to-nix/default.nix | 2 +- test/default.nix | 8 ++++++-- test/exe-only/default.nix | 2 +- test/fully-static/default.nix | 2 +- test/ghc-options/cabal.nix | 4 +++- test/ghc-options/stack.nix | 2 +- test/project-flags/cabal.nix | 2 +- test/project-flags/stack.nix | 2 +- test/setup-deps/default.nix | 4 ++-- test/shell-for-setup-deps/default.nix | 4 ++-- 18 files changed, 28 insertions(+), 22 deletions(-) diff --git a/overlays/haskell.nix b/overlays/haskell.nix index c5cee55b72..5d200bb01c 100644 --- a/overlays/haskell.nix +++ b/overlays/haskell.nix @@ -361,13 +361,13 @@ self: super: { # project = cabalProject' {...}; # In your tests module add something that is effectively # testProjectPlan = withInputs project.plan-nix; - withInputs = derivation: builtins.mapAttrs (_: self.recurseIntoAttrs) { + withInputs = derivation: self.recurseIntoAttrs (builtins.mapAttrs (_: self.recurseIntoAttrs) { inherit derivation; inputs = builtins.listToAttrs ( builtins.concatMap (i: if i == null then [] else [ { name = builtins.replaceStrings ["." (self.stdenv.hostPlatform.config + "-")] ["_" ""] i.name; value = i; } ]) derivation.nativeBuildInputs); - }; + }); # Add this to your tests to make all the dependencies of haskell.nix # are tested and cached. diff --git a/test/buildable/default.nix b/test/buildable/default.nix index a27444b1aa..c06d072fe0 100644 --- a/test/buildable/default.nix +++ b/test/buildable/default.nix @@ -12,7 +12,7 @@ let packages = project.hsPkgs; in recurseIntoAttrs { - ifdInputs = recurseIntoAttrs { + ifdInputs = { inherit (project) plan-nix; }; run = stdenv.mkDerivation { diff --git a/test/cabal-22/default.nix b/test/cabal-22/default.nix index 4ee2c467c2..777ba0e743 100644 --- a/test/cabal-22/default.nix +++ b/test/cabal-22/default.nix @@ -11,7 +11,7 @@ let packages = project.hsPkgs; in recurseIntoAttrs { - ifdInputs = recurseIntoAttrs { + ifdInputs = { inherit (project) plan-nix; }; shell = util.addCabalInstall packages.project.components.all; diff --git a/test/cabal-simple-prof/default.nix b/test/cabal-simple-prof/default.nix index 2cbfd78363..d0dad6fbe2 100644 --- a/test/cabal-simple-prof/default.nix +++ b/test/cabal-simple-prof/default.nix @@ -24,7 +24,7 @@ let packages = project.hsPkgs; in recurseIntoAttrs { - ifdInputs = recurseIntoAttrs { + ifdInputs = { inherit (project) plan-nix; }; run = stdenv.mkDerivation { diff --git a/test/cabal-simple/default.nix b/test/cabal-simple/default.nix index 294a76f6aa..82eaeb142d 100644 --- a/test/cabal-simple/default.nix +++ b/test/cabal-simple/default.nix @@ -34,7 +34,7 @@ let packages = project.hsPkgs; in recurseIntoAttrs { - ifdInputs = recurseIntoAttrs { + ifdInputs = { inherit (project) plan-nix; }; diff --git a/test/cabal-source-repo/default.nix b/test/cabal-source-repo/default.nix index 86b25dd66d..22289a7eb6 100644 --- a/test/cabal-source-repo/default.nix +++ b/test/cabal-source-repo/default.nix @@ -10,7 +10,7 @@ let }; packages = project.hsPkgs; in recurseIntoAttrs { - ifdInputs = recurseIntoAttrs { + ifdInputs = { inherit (project) plan-nix; }; run = stdenv.mkDerivation { diff --git a/test/cabal-sublib/default.nix b/test/cabal-sublib/default.nix index 50f0b62402..bc23264897 100644 --- a/test/cabal-sublib/default.nix +++ b/test/cabal-sublib/default.nix @@ -22,7 +22,7 @@ let packages = project.hsPkgs; in recurseIntoAttrs { - ifdInputs = recurseIntoAttrs { + ifdInputs = { inherit (project) plan-nix; }; run = stdenv.mkDerivation { diff --git a/test/call-cabal-project-to-nix/default.nix b/test/call-cabal-project-to-nix/default.nix index 327e8eec8f..73fbab1fcd 100644 --- a/test/call-cabal-project-to-nix/default.nix +++ b/test/call-cabal-project-to-nix/default.nix @@ -17,7 +17,7 @@ let packages = pkgSet.config.hsPkgs; in recurseIntoAttrs { - ifdInputs = recurseIntoAttrs { + ifdInputs = { plan-nix = plan.nix; }; run = stdenv.mkDerivation { diff --git a/test/call-stack-to-nix/default.nix b/test/call-stack-to-nix/default.nix index e2b16ebd1e..c0701da065 100644 --- a/test/call-stack-to-nix/default.nix +++ b/test/call-stack-to-nix/default.nix @@ -14,7 +14,7 @@ let packages = pkgSet.config.hsPkgs; in recurseIntoAttrs { - ifdInputs = recurseIntoAttrs { + ifdInputs = { stack-nix = stack.nix; }; run = stdenv.mkDerivation { diff --git a/test/default.nix b/test/default.nix index b2b26bfbb2..a54e17ad06 100644 --- a/test/default.nix +++ b/test/default.nix @@ -7,10 +7,14 @@ with pkgs; let + withIfdInputs = builtins.mapAttrs (n: x: + if n == "ifdInputs" + then pkgs.recurseIntoAttrs (builtins.mapAttrs (_: pkgs.haskell-nix.withInputs) x) + else x); util = import ./util.nix { inherit (pkgs.haskell-nix) cabal-install; }; in pkgs.recurseIntoAttrs { inherit (haskell-nix) haskellNixRoots; -} // (if ifdInputsOnly +} // builtins.mapAttrs (_: y: withIfdInputs y) ((if ifdInputsOnly then builtins.mapAttrs (_: d: pkgs.recurseIntoAttrs (pkgs.lib.filterAttrs (n: _: n == "ifdInputs") d)) else x: x) { cabal-simple = haskell-nix.callPackage ./cabal-simple { inherit util; }; @@ -42,7 +46,7 @@ in pkgs.recurseIntoAttrs { in runCommand "unit-tests" { passthru = { inherit tests; }; } (lib.concatMapStringsSep "\n" (t: "echo ${t.name} failed") tests + (if builtins.length tests == 0 then "\ntouch $out" else "\nexit 1")); -} +}) ## more possible test cases # 1. fully static linking diff --git a/test/exe-only/default.nix b/test/exe-only/default.nix index 37e9e724b8..356d7f8f9f 100644 --- a/test/exe-only/default.nix +++ b/test/exe-only/default.nix @@ -12,7 +12,7 @@ let packages = project.hsPkgs; in recurseIntoAttrs { - ifdInputs = recurseIntoAttrs { + ifdInputs = { inherit (project) plan-nix; }; run = stdenv.mkDerivation { diff --git a/test/fully-static/default.nix b/test/fully-static/default.nix index a81fae613f..8320a45f4c 100644 --- a/test/fully-static/default.nix +++ b/test/fully-static/default.nix @@ -53,7 +53,7 @@ let packagesIntegerSimple = (project { gpl = false; }).hsPkgs; in recurseIntoAttrs { - ifdInputs = recurseIntoAttrs { + ifdInputs = { stack-nix-gmp = (project { gpl = true; }).stack-nix; stack-nix-simple = (project { gpl = false; }).stack-nix; }; diff --git a/test/ghc-options/cabal.nix b/test/ghc-options/cabal.nix index 4dbcb06423..d5ba605f66 100644 --- a/test/ghc-options/cabal.nix +++ b/test/ghc-options/cabal.nix @@ -13,7 +13,9 @@ let packages = project.hsPkgs; in recurseIntoAttrs { - inherit (project) plan-nix; + ifdInputs = { + inherit (project) plan-nix; + }; run = stdenv.mkDerivation { name = "call-cabal-project-to-nix-test"; diff --git a/test/ghc-options/stack.nix b/test/ghc-options/stack.nix index 9674fa7beb..55f0bf79c7 100644 --- a/test/ghc-options/stack.nix +++ b/test/ghc-options/stack.nix @@ -9,7 +9,7 @@ let packages = project.hsPkgs; in recurseIntoAttrs { - ifdInputs = recurseIntoAttrs { + ifdInputs = { inherit (project) stack-nix; }; run = stdenv.mkDerivation { diff --git a/test/project-flags/cabal.nix b/test/project-flags/cabal.nix index adf93b2f4d..ec4d54af88 100644 --- a/test/project-flags/cabal.nix +++ b/test/project-flags/cabal.nix @@ -11,7 +11,7 @@ let packages = project.hsPkgs; in recurseIntoAttrs { - ifdInputs = recurseIntoAttrs { + ifdInputs = { inherit (project) plan-nix; }; run = stdenv.mkDerivation { diff --git a/test/project-flags/stack.nix b/test/project-flags/stack.nix index d29d1d7c98..7b60bba117 100644 --- a/test/project-flags/stack.nix +++ b/test/project-flags/stack.nix @@ -9,7 +9,7 @@ let packages = project.hsPkgs; in recurseIntoAttrs { - ifdInputs = recurseIntoAttrs { + ifdInputs = { inherit (project) stack-nix; }; run = stdenv.mkDerivation { diff --git a/test/setup-deps/default.nix b/test/setup-deps/default.nix index 736eb5d6e3..74c526b6dc 100644 --- a/test/setup-deps/default.nix +++ b/test/setup-deps/default.nix @@ -23,11 +23,11 @@ in recurseIntoAttrs (if stdenv.hostPlatform.isWindows touch $out ''; in { - ifdInputs = recurseIntoAttrs { plan-nix = skip; }; + ifdInputs = { plan-nix = skip; }; run = skip; } else { - ifdInputs = recurseIntoAttrs { + ifdInputs = { inherit (project) plan-nix; }; run = pkgs.stdenv.mkDerivation { diff --git a/test/shell-for-setup-deps/default.nix b/test/shell-for-setup-deps/default.nix index 47286ca33c..1647b583f5 100644 --- a/test/shell-for-setup-deps/default.nix +++ b/test/shell-for-setup-deps/default.nix @@ -22,12 +22,12 @@ in recurseIntoAttrs (if stdenv.hostPlatform.isWindows touch $out ''; in { - ifdInputs = recurseIntoAttrs { plan-nix = skip; }; + ifdInputs = { plan-nix = skip; }; env = skip; run = skip; } else { - ifdInputs = recurseIntoAttrs { + ifdInputs = { inherit (project) plan-nix; }; inherit env; From 1dc17089ee2749d9872aaf4e4d95cdc3ffcf5722 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sun, 24 Nov 2019 16:46:17 +1300 Subject: [PATCH 31/46] Try using ifd level to better control hydra eval --- build.nix | 6 +++--- lib/call-cabal-project-to-nix.nix | 2 +- overlays/bootstrap.nix | 6 +++--- overlays/haskell.nix | 23 +++++++++++++++++++---- release.nix | 4 ++-- test/default.nix | 6 +++--- 6 files changed, 31 insertions(+), 16 deletions(-) diff --git a/build.nix b/build.nix index 3682ce8df8..464b1b3e57 100644 --- a/build.nix +++ b/build.nix @@ -9,7 +9,7 @@ , crossSystem ? null , config ? {} , nixpkgsArgs ? { inherit system crossSystem; } -, ifdInputsOnly ? false +, ifdLevel ? 1000 }: let @@ -30,8 +30,8 @@ let haskell = pkgs.haskell-nix; in { - tests = import ./test/default.nix { inherit nixpkgs nixpkgsArgs ifdInputsOnly; }; -} // pkgs.lib.optionalAttrs (!ifdInputsOnly) rec { + tests = import ./test/default.nix { inherit nixpkgs nixpkgsArgs ifdLevel; }; +} // pkgs.lib.optionalAttrs (ifdLevel > 2) rec { # Scripts for keeping Hackage and Stackage up to date, and CI tasks. # The dontRecurseIntoAttrs prevents these from building on hydra # as not all of them can work in restricted eval mode (as they diff --git a/lib/call-cabal-project-to-nix.nix b/lib/call-cabal-project-to-nix.nix index b97e090d4a..91da499c26 100644 --- a/lib/call-cabal-project-to-nix.nix +++ b/lib/call-cabal-project-to-nix.nix @@ -156,7 +156,7 @@ let } else replaceSoureRepos rawCabalProject; - plan-nix = runCommand "plan-to-nix-pkgs" ({ + plan-nix = runCommand (if name == null then "plan-to-nix-pkgs" else name + "-plan-to-nix-pkgs") ({ nativeBuildInputs = [ nix-tools ghc hpack cabal-install pkgs.rsync pkgs.git ]; # Needed or stack-to-nix will die on unicode inputs LANG = "en_US.UTF-8"; diff --git a/overlays/bootstrap.nix b/overlays/bootstrap.nix index f9da41d99a..37bcc94eea 100644 --- a/overlays/bootstrap.nix +++ b/overlays/bootstrap.nix @@ -267,7 +267,7 @@ self: super: { index-state = "2019-10-20T00:00:00Z"; plan-sha256 = "086kd6aa5bir3y4aqb1wl5zkj6agz5q4wp4snvdnf6cidz5wra06"; }; - alex = bootstrap.packages.alex-project.alex.components.exes.alex; + alex = bootstrap.packages.alex-project.hsPkgs.alex.components.exes.alex; happy-project = hackage-project { # Only a boot compiler is suitable here ghc = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; }; @@ -276,7 +276,7 @@ self: super: { index-state = "2019-10-20T00:00:00Z"; plan-sha256 = "011bxlxdv239psgi80j00km2wcgb68j16sz3fng67d03sqf5i37w"; }; - happy = bootstrap.packages.happy-project.happy.components.exes.happy; + happy = bootstrap.packages.happy-project.hsPkgs.happy.components.exes.happy; hscolour-project = hackage-project { # Only a boot compiler is suitable here ghc = ghc // { isHaskellNixCompiler = ghc.isHaskellNixBootCompiler; }; @@ -285,7 +285,7 @@ self: super: { index-state = "2019-10-20T00:00:00Z"; plan-sha256 = "021rwcmkshibc3mfr833ay5hfr19kq6k32lxyrrb6vp9vmihgw4b"; }; - hscolour = bootstrap.packages.hscolour-project.hscolour.components.exes.HsColour; + hscolour = bootstrap.packages.hscolour-project.hsPkgs.hscolour.components.exes.HsColour; }; }; }; diff --git a/overlays/haskell.nix b/overlays/haskell.nix index 5d200bb01c..58c28d0d67 100644 --- a/overlays/haskell.nix +++ b/overlays/haskell.nix @@ -309,7 +309,7 @@ self: super: { tar xzf ${tarball} mv "${name}-${version}" $out ''; - in cabalProject (builtins.removeAttrs args [ "version" ] // { inherit src; }); + in cabalProject' (builtins.removeAttrs args [ "version" ] // { inherit src; }); # This function is like `cabalProject` but it makes the plan-nix available # separately from the hsPkgs. The advantage is that the you can get the @@ -371,20 +371,35 @@ self: super: { # Add this to your tests to make all the dependencies of haskell.nix # are tested and cached. - haskellNixRoots = self.recurseIntoAttrs (builtins.mapAttrs (_: self.recurseIntoAttrs) { + haskellNixRoots = self.recurseIntoAttrs { + Level0 = haskellNixRoots' 0; + Level1 = haskellNixRoots' 1; + }; + + haskellNixRoots' = ifdLevel: self.recurseIntoAttrs ({ + # Things that require no IFD to build inherit (self.buildPackages.haskell-nix) nix-tools source-pins; bootstap-nix-tools = self.buildPackages.haskell-nix.bootstrap.packages.nix-tools; alex-plan-nix = withInputs self.buildPackages.haskell-nix.bootstrap.packages.alex-project.plan-nix; happy-plan-nix = withInputs self.buildPackages.haskell-nix.bootstrap.packages.happy-project.plan-nix; hscolour-plan-nix = withInputs self.buildPackages.haskell-nix.bootstrap.packages.hscolour-project.plan-nix; - ghc-extra-projects = builtins.mapAttrs (_: proj: self.recurseIntoAttrs (withInputs proj.plan-nix)) + } // self.lib.optionalAttrs (ifdLevel > 0) { + # Things that require one IFD to build (the inputs should be in level 0) + alex = self.buildPackages.haskell-nix.bootstrap.packages.alex; + happy = self.buildPackages.haskell-nix.bootstrap.packages.happy; + hscolour = self.buildPackages.haskell-nix.bootstrap.packages.hscolour; + ghc865 = self.buildPackages.haskell-nix.compiler.ghc865; + ghc-extra-projects = self.recurseIntoAttrs (builtins.mapAttrs (_: proj: withInputs proj.plan-nix) (self.lib.filterAttrs (n: _: n != "ghc844" && n != "ghc861" && n != "ghc862" && n != "ghc863" && n != "ghc864" - ) self.ghc-extra-projects); + ) self.ghc-extra-projects)); + } // self.lib.optionalAttrs (ifdLevel > 1) { + # Things that require two levels of IFD to build (inputs should be in level 1) + ghc-extra-packages = self.recurseIntoAttrs self.ghc-extra-packages; }); }; } diff --git a/release.nix b/release.nix index b7ef66aa4f..c103021f15 100644 --- a/release.nix +++ b/release.nix @@ -2,7 +2,7 @@ , scrubJobs ? true , haskell-nix ? { outPath = ./.; rev = "abcdef"; } , nixpkgsArgs ? {} -, ifdInputsOnly ? true +, ifdLevel ? 0 }: let defaultNixpkgs = import ./nixpkgs {}; in @@ -32,7 +32,7 @@ let , ...}@args: import (haskell-nix + /build.nix) (args // { nixpkgsArgs = nixpkgsArgs // { inherit nixpkgs-pin; }; - inherit ifdInputsOnly; + inherit ifdLevel; }); }); diff --git a/test/default.nix b/test/default.nix index a54e17ad06..e403a5b961 100644 --- a/test/default.nix +++ b/test/default.nix @@ -1,7 +1,7 @@ { pkgs ? import nixpkgs ((import ../.) // nixpkgsArgs) , nixpkgs ? ../nixpkgs , nixpkgsArgs ? { } -, ifdInputsOnly ? false +, ifdLevel ? 1000 }: with pkgs; @@ -13,8 +13,8 @@ let else x); util = import ./util.nix { inherit (pkgs.haskell-nix) cabal-install; }; in pkgs.recurseIntoAttrs { - inherit (haskell-nix) haskellNixRoots; -} // builtins.mapAttrs (_: y: withIfdInputs y) ((if ifdInputsOnly + haskellNixRoots = haskell-nix.haskellNixRoots' ifdLevel; +} // builtins.mapAttrs (_: y: withIfdInputs y) ((if ifdLevel < 3 then builtins.mapAttrs (_: d: pkgs.recurseIntoAttrs (pkgs.lib.filterAttrs (n: _: n == "ifdInputs") d)) else x: x) { cabal-simple = haskell-nix.callPackage ./cabal-simple { inherit util; }; From a1e0b92b6843e25ec2b0d1be6291607bf707e4ea Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sun, 24 Nov 2019 21:04:23 +1300 Subject: [PATCH 32/46] Set `preferLocalBuild=false` instead of withInputs --- lib/call-cabal-project-to-nix.nix | 1 + lib/call-stack-to-nix.nix | 1 + overlays/haskell.nix | 8 +------- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/call-cabal-project-to-nix.nix b/lib/call-cabal-project-to-nix.nix index 91da499c26..7f7c937c1c 100644 --- a/lib/call-cabal-project-to-nix.nix +++ b/lib/call-cabal-project-to-nix.nix @@ -160,6 +160,7 @@ let nativeBuildInputs = [ nix-tools ghc hpack cabal-install pkgs.rsync pkgs.git ]; # Needed or stack-to-nix will die on unicode inputs LANG = "en_US.UTF-8"; + preferLocalBuild = false; } // (if plan-sha256 == null then {} else { diff --git a/lib/call-stack-to-nix.nix b/lib/call-stack-to-nix.nix index 7a607d0a6d..5089f3e570 100644 --- a/lib/call-stack-to-nix.nix +++ b/lib/call-stack-to-nix.nix @@ -20,6 +20,7 @@ let LOCALE_ARCHIVE = pkgs.lib.optionalString (pkgs.stdenv.hostPlatform.libc == "glibc") "${pkgs.glibcLocales}/lib/locale/locale-archive"; LANG = "en_US.UTF-8"; LC_ALL = "en_US.UTF-8"; + preferLocalBuild = false; } ('' mkdir -p $out '' + pkgs.lib.optionalString (cache != null) '' diff --git a/overlays/haskell.nix b/overlays/haskell.nix index 58c28d0d67..523445faf3 100644 --- a/overlays/haskell.nix +++ b/overlays/haskell.nix @@ -361,13 +361,7 @@ self: super: { # project = cabalProject' {...}; # In your tests module add something that is effectively # testProjectPlan = withInputs project.plan-nix; - withInputs = derivation: self.recurseIntoAttrs (builtins.mapAttrs (_: self.recurseIntoAttrs) { - inherit derivation; - inputs = builtins.listToAttrs ( - builtins.concatMap (i: if i == null then [] else [ - { name = builtins.replaceStrings ["." (self.stdenv.hostPlatform.config + "-")] ["_" ""] i.name; value = i; } - ]) derivation.nativeBuildInputs); - }); + withInputs = self.recurseIntoAttrs; # Add this to your tests to make all the dependencies of haskell.nix # are tested and cached. From a8a044ff70f0d7daa3d0812f34db48ec5afb6021 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sun, 24 Nov 2019 21:06:21 +1300 Subject: [PATCH 33/46] Only build tests when ifdLevel>1 --- test/default.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/default.nix b/test/default.nix index e403a5b961..3657b8d6ae 100644 --- a/test/default.nix +++ b/test/default.nix @@ -14,7 +14,8 @@ let util = import ./util.nix { inherit (pkgs.haskell-nix) cabal-install; }; in pkgs.recurseIntoAttrs { haskellNixRoots = haskell-nix.haskellNixRoots' ifdLevel; -} // builtins.mapAttrs (_: y: withIfdInputs y) ((if ifdLevel < 3 +} // pkgs.lib.optionalAttrs (ifdLevel > 1) ( + builtins.mapAttrs (_: y: withIfdInputs y) ((if ifdLevel < 3 then builtins.mapAttrs (_: d: pkgs.recurseIntoAttrs (pkgs.lib.filterAttrs (n: _: n == "ifdInputs") d)) else x: x) { cabal-simple = haskell-nix.callPackage ./cabal-simple { inherit util; }; @@ -46,7 +47,7 @@ in pkgs.recurseIntoAttrs { in runCommand "unit-tests" { passthru = { inherit tests; }; } (lib.concatMapStringsSep "\n" (t: "echo ${t.name} failed") tests + (if builtins.length tests == 0 then "\ntouch $out" else "\nexit 1")); -}) +})) ## more possible test cases # 1. fully static linking From e861f35c0c105c904fd2aeb801d01663f723aa78 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sun, 24 Nov 2019 21:28:45 +1300 Subject: [PATCH 34/46] ifdLevel = 1 --- release.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release.nix b/release.nix index c103021f15..2468a0e9df 100644 --- a/release.nix +++ b/release.nix @@ -2,7 +2,7 @@ , scrubJobs ? true , haskell-nix ? { outPath = ./.; rev = "abcdef"; } , nixpkgsArgs ? {} -, ifdLevel ? 0 +, ifdLevel ? 1 }: let defaultNixpkgs = import ./nixpkgs {}; in From fff24e488d8b27713450d238db8a243a523d446c Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sun, 24 Nov 2019 21:37:40 +1300 Subject: [PATCH 35/46] ifdLevel = 2 --- release.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release.nix b/release.nix index 2468a0e9df..4cfc162e13 100644 --- a/release.nix +++ b/release.nix @@ -2,7 +2,7 @@ , scrubJobs ? true , haskell-nix ? { outPath = ./.; rev = "abcdef"; } , nixpkgsArgs ? {} -, ifdLevel ? 1 +, ifdLevel ? 2 }: let defaultNixpkgs = import ./nixpkgs {}; in From d8199c4e2f69fb701139b021a5fa72b12bf7af0f Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sun, 24 Nov 2019 22:20:10 +1300 Subject: [PATCH 36/46] Run check-hydra on all the IFD levels --- .buildkite/pipeline.yml | 5 ++++- build.nix | 27 +++++++++++---------------- scripts/check-hydra.nix | 3 ++- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 5a2846c460..9eaae77ad1 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -7,7 +7,10 @@ steps: - label: 'Check that jobset will evaluate in Hydra' command: - nix-build build.nix -A maintainer-scripts.check-hydra -o check-hydra.sh - - ./check-hydra.sh + - ./check-hydra.sh 0 + - ./check-hydra.sh 1 + - ./check-hydra.sh 2 + - ./check-hydra.sh 3 agents: system: x86_64-linux diff --git a/build.nix b/build.nix index 464b1b3e57..2cebe6bf36 100644 --- a/build.nix +++ b/build.nix @@ -14,24 +14,12 @@ let haskellNixArgs = import ./default.nix; - pkgs = import nixpkgs ({ - config = haskellNixArgs.config // config; - overlays = haskellNixArgs.overlays ++ - [(self: super: { - darcs = (self.haskell-nix.hackage-package { - name = "darcs"; - version = "2.14.2"; - index-state = "2019-10-28T00:00:00Z"; - plan-sha256 = "1h8dxib0wz6mg8md6ldwa54dsr1dn7vxfij8cfhdawl4y3wr51k0"; - # Apply the latest darcs.net Setup.hs patches - modules = [{packages.darcs.patches = [ ./patches/darcs-setup.patch ];}]; - }).components.exes.darcs; - })]; } // nixpkgsArgs); + pkgs = import nixpkgs nixpkgsArgs; haskell = pkgs.haskell-nix; -in { +in rec { tests = import ./test/default.nix { inherit nixpkgs nixpkgsArgs ifdLevel; }; -} // pkgs.lib.optionalAttrs (ifdLevel > 2) rec { + # Scripts for keeping Hackage and Stackage up to date, and CI tasks. # The dontRecurseIntoAttrs prevents these from building on hydra # as not all of them can work in restricted eval mode (as they @@ -53,6 +41,11 @@ in { }) {}; }; }; + # Because this is going to be used to test caching on hydra, it must not + # use the darcs package from the haskell.nix we are testing. For that reason + # it uses `pkgs.buildPackages.callPackage` not `haskell.callPackage` + # (We could pull in darcs from a known good haskell.nix for hydra to + # use) check-hydra = pkgs.buildPackages.callPackage ./scripts/check-hydra.nix {}; check-closure-size = pkgs.buildPackages.callPackage ./scripts/check-closure-size.nix { inherit (haskell) nix-tools; @@ -62,7 +55,9 @@ in { # These are pure parts of maintainer-script so they can be built by hydra # and added to the cache to speed up buildkite. maintainer-script-cache = pkgs.recurseIntoAttrs { - inherit (maintainer-scripts) update-docs check-hydra check-closure-size; + inherit (maintainer-scripts) check-hydra; + } // pkgs.lib.optionalAttrs (ifdLevel > 2) { + inherit (maintainer-scripts) update-docs check-closure-size; # Some of the dependencies of the impure scripts so that they will # will be in the cache too for buildkite. inherit (pkgs.buildPackages) glibc coreutils git openssh cabal-install nix-prefetch-git; diff --git a/scripts/check-hydra.nix b/scripts/check-hydra.nix index a2b10ff866..1f0b9a1dce 100644 --- a/scripts/check-hydra.nix +++ b/scripts/check-hydra.nix @@ -9,11 +9,12 @@ writeScript "check-hydra.sh" '' export PATH="${makeBinPath [ coreutils time gnutar gzip hydra jq ]}" - echo '~~~ Evaluating release.nix' + echo '~~~ Evaluating release.nix with --arg ifdLevel '$0 command time --format '%e' -o eval-time.txt \ hydra-eval-jobs \ --option allowed-uris "https://github.com/NixOS https://github.com/input-output-hk" \ --arg supportedSystems '[ builtins.currentSystem ]' \ + --arg ifdLevel $0 \ -I . release.nix > eval.json EVAL_EXIT_CODE="$?" if [ "$EVAL_EXIT_CODE" != 0 ] From 5a321d392307d3598f3f4bca336fad1985a5e30a Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sun, 24 Nov 2019 22:21:36 +1300 Subject: [PATCH 37/46] Run check-hydra on all the IFD levels --- scripts/check-hydra.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/check-hydra.nix b/scripts/check-hydra.nix index 1f0b9a1dce..7f54b87479 100644 --- a/scripts/check-hydra.nix +++ b/scripts/check-hydra.nix @@ -9,12 +9,12 @@ writeScript "check-hydra.sh" '' export PATH="${makeBinPath [ coreutils time gnutar gzip hydra jq ]}" - echo '~~~ Evaluating release.nix with --arg ifdLevel '$0 + echo '~~~ Evaluating release.nix with --arg ifdLevel '$1 command time --format '%e' -o eval-time.txt \ hydra-eval-jobs \ --option allowed-uris "https://github.com/NixOS https://github.com/input-output-hk" \ --arg supportedSystems '[ builtins.currentSystem ]' \ - --arg ifdLevel $0 \ + --arg ifdLevel $1 \ -I . release.nix > eval.json EVAL_EXIT_CODE="$?" if [ "$EVAL_EXIT_CODE" != 0 ] From 6021f5dbd4f1244bd64db97194006e38f8b1d357 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sun, 24 Nov 2019 22:32:38 +1300 Subject: [PATCH 38/46] Only build ghc-extra-packages for ghc865 --- overlays/haskell.nix | 47 +++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/overlays/haskell.nix b/overlays/haskell.nix index 523445faf3..09798ea326 100644 --- a/overlays/haskell.nix +++ b/overlays/haskell.nix @@ -370,30 +370,27 @@ self: super: { Level1 = haskellNixRoots' 1; }; - haskellNixRoots' = ifdLevel: self.recurseIntoAttrs ({ - # Things that require no IFD to build - inherit (self.buildPackages.haskell-nix) nix-tools source-pins; - bootstap-nix-tools = self.buildPackages.haskell-nix.bootstrap.packages.nix-tools; - alex-plan-nix = withInputs self.buildPackages.haskell-nix.bootstrap.packages.alex-project.plan-nix; - happy-plan-nix = withInputs self.buildPackages.haskell-nix.bootstrap.packages.happy-project.plan-nix; - hscolour-plan-nix = withInputs self.buildPackages.haskell-nix.bootstrap.packages.hscolour-project.plan-nix; - } // self.lib.optionalAttrs (ifdLevel > 0) { - # Things that require one IFD to build (the inputs should be in level 0) - alex = self.buildPackages.haskell-nix.bootstrap.packages.alex; - happy = self.buildPackages.haskell-nix.bootstrap.packages.happy; - hscolour = self.buildPackages.haskell-nix.bootstrap.packages.hscolour; - ghc865 = self.buildPackages.haskell-nix.compiler.ghc865; - ghc-extra-projects = self.recurseIntoAttrs (builtins.mapAttrs (_: proj: withInputs proj.plan-nix) - (self.lib.filterAttrs (n: _: - n != "ghc844" - && n != "ghc861" - && n != "ghc862" - && n != "ghc863" - && n != "ghc864" - ) self.ghc-extra-projects)); - } // self.lib.optionalAttrs (ifdLevel > 1) { - # Things that require two levels of IFD to build (inputs should be in level 1) - ghc-extra-packages = self.recurseIntoAttrs self.ghc-extra-packages; - }); + haskellNixRoots' = ifdLevel: + let filterSupportedGhc = self.lib.filterAttrs (n: _: n == "ghc65"); + in self.recurseIntoAttrs ({ + # Things that require no IFD to build + inherit (self.buildPackages.haskell-nix) nix-tools source-pins; + bootstap-nix-tools = self.buildPackages.haskell-nix.bootstrap.packages.nix-tools; + alex-plan-nix = withInputs self.buildPackages.haskell-nix.bootstrap.packages.alex-project.plan-nix; + happy-plan-nix = withInputs self.buildPackages.haskell-nix.bootstrap.packages.happy-project.plan-nix; + hscolour-plan-nix = withInputs self.buildPackages.haskell-nix.bootstrap.packages.hscolour-project.plan-nix; + } // self.lib.optionalAttrs (ifdLevel > 0) { + # Things that require one IFD to build (the inputs should be in level 0) + alex = self.buildPackages.haskell-nix.bootstrap.packages.alex; + happy = self.buildPackages.haskell-nix.bootstrap.packages.happy; + hscolour = self.buildPackages.haskell-nix.bootstrap.packages.hscolour; + ghc865 = self.buildPackages.haskell-nix.compiler.ghc865; + ghc-extra-projects = self.recurseIntoAttrs (builtins.mapAttrs (_: proj: withInputs proj.plan-nix) + (filterSupportedGhc self.ghc-extra-projects)); + } // self.lib.optionalAttrs (ifdLevel > 1) { + # Things that require two levels of IFD to build (inputs should be in level 1) + ghc-extra-packages = self.recurseIntoAttrs + (filterSupportedGhc self.ghc-extra-packages); + }); }; } From b79da5fe846169ecb7889ddfd18c6d3c2af7c293 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sun, 24 Nov 2019 22:33:22 +1300 Subject: [PATCH 39/46] Only build ghc-extra-packages for ghc865 --- overlays/haskell.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/overlays/haskell.nix b/overlays/haskell.nix index 09798ea326..0e39032b0e 100644 --- a/overlays/haskell.nix +++ b/overlays/haskell.nix @@ -371,7 +371,7 @@ self: super: { }; haskellNixRoots' = ifdLevel: - let filterSupportedGhc = self.lib.filterAttrs (n: _: n == "ghc65"); + let filterSupportedGhc = self.lib.filterAttrs (n: _: n == "ghc865"); in self.recurseIntoAttrs ({ # Things that require no IFD to build inherit (self.buildPackages.haskell-nix) nix-tools source-pins; From 4cf064f1579f38aff38fc258104122dbfcd289a5 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sun, 24 Nov 2019 22:47:29 +1300 Subject: [PATCH 40/46] Fix maintainer scripts --- build.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build.nix b/build.nix index 2cebe6bf36..caa189fb69 100644 --- a/build.nix +++ b/build.nix @@ -14,7 +14,10 @@ let haskellNixArgs = import ./default.nix; - pkgs = import nixpkgs nixpkgsArgs; + pkgs = import nixpkgs ({ + config = haskellNixArgs.config // config; + inherit haskellNixArgs overlays; + } // nixpkgsArgs); haskell = pkgs.haskell-nix; in rec { From 192737c5f0563787f4fea1268e6d9c0d0b04601c Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sun, 24 Nov 2019 23:05:49 +1300 Subject: [PATCH 41/46] Skip check-hydra on windows --- build.nix | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/build.nix b/build.nix index caa189fb69..f05de74bf1 100644 --- a/build.nix +++ b/build.nix @@ -16,7 +16,7 @@ let haskellNixArgs = import ./default.nix; pkgs = import nixpkgs ({ config = haskellNixArgs.config // config; - inherit haskellNixArgs overlays; + inherit (haskellNixArgs) overlays; } // nixpkgsArgs); haskell = pkgs.haskell-nix; @@ -57,13 +57,16 @@ in rec { # These are pure parts of maintainer-script so they can be built by hydra # and added to the cache to speed up buildkite. - maintainer-script-cache = pkgs.recurseIntoAttrs { - inherit (maintainer-scripts) check-hydra; - } // pkgs.lib.optionalAttrs (ifdLevel > 2) { - inherit (maintainer-scripts) update-docs check-closure-size; - # Some of the dependencies of the impure scripts so that they will - # will be in the cache too for buildkite. - inherit (pkgs.buildPackages) glibc coreutils git openssh cabal-install nix-prefetch-git; - inherit (haskell) nix-tools; - }; + maintainer-script-cache = pkgs.recurseIntoAttrs ( + (pkgs.lib.optionalAttrs stdenv.hostPlatform.isWindows { + inherit (maintainer-scripts) check-hydra; + }) + // (pkgs.lib.optionalAttrs (ifdLevel > 2) { + inherit (maintainer-scripts) update-docs check-closure-size; + # Some of the dependencies of the impure scripts so that they will + # will be in the cache too for buildkite. + inherit (pkgs.buildPackages) glibc coreutils git openssh cabal-install nix-prefetch-git; + inherit (haskell) nix-tools; + }) + ); } From 27ce94c7cc7e53e83ca46006836cad74c79e0054 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sun, 24 Nov 2019 23:07:25 +1300 Subject: [PATCH 42/46] Skip check-hydra on windows --- build.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.nix b/build.nix index f05de74bf1..114cef40c8 100644 --- a/build.nix +++ b/build.nix @@ -58,7 +58,7 @@ in rec { # These are pure parts of maintainer-script so they can be built by hydra # and added to the cache to speed up buildkite. maintainer-script-cache = pkgs.recurseIntoAttrs ( - (pkgs.lib.optionalAttrs stdenv.hostPlatform.isWindows { + (pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isWindows { inherit (maintainer-scripts) check-hydra; }) // (pkgs.lib.optionalAttrs (ifdLevel > 2) { From c2be4abc81899d7f61b23eeb1db7ffe56989db8f Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Sun, 24 Nov 2019 23:10:46 +1300 Subject: [PATCH 43/46] ifdLevel = 3 --- release.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release.nix b/release.nix index 4cfc162e13..98cedb1827 100644 --- a/release.nix +++ b/release.nix @@ -2,7 +2,7 @@ , scrubJobs ? true , haskell-nix ? { outPath = ./.; rev = "abcdef"; } , nixpkgsArgs ? {} -, ifdLevel ? 2 +, ifdLevel ? 3 }: let defaultNixpkgs = import ./nixpkgs {}; in From 344abd71d963425dde20b3ed5da9922db11a306a Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Wed, 27 Nov 2019 14:20:53 +1300 Subject: [PATCH 44/46] Fix `data-dir:` when cleaning components `normalizeRelativeDir` adds a slash on to the end of `dataDir`. Adding another one here results in `//` and files are left out by mistake. --- lib/clean-cabal-component.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/clean-cabal-component.nix b/lib/clean-cabal-component.nix index 485657060c..8add866c01 100644 --- a/lib/clean-cabal-component.nix +++ b/lib/clean-cabal-component.nix @@ -69,8 +69,7 @@ in ++ package.extraSrcFiles ++ component.extraSrcFiles ++ package.extraDocFiles - ++ builtins.map (f: - dataDir + (if dataDir == "" then "" else "/") + f) package.dataFiles + ++ builtins.map (f: dataDir + f) package.dataFiles ++ otherSourceFiles)) || traceReason "cabal package definition" (lib.strings.hasSuffix ".cabal" rPath) || traceReason "hpack package defintion" (rPath == "package.yaml") From fa15c3a5351dd7421469efcbf52ca8072b6b1fc9 Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Fri, 29 Nov 2019 18:02:33 +1300 Subject: [PATCH 45/46] Make test component source available in check --- lib/check.nix | 8 +++++--- lib/default.nix | 4 ++-- overlays/haskell.nix | 2 +- package-set.nix | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/check.nix b/lib/check.nix index 6b5e1ea0b3..f1626cdc3b 100644 --- a/lib/check.nix +++ b/lib/check.nix @@ -1,4 +1,4 @@ -{ stdenv, lib, haskellLib }: +{ stdenv, lib, haskellLib, srcOnly }: drv: let @@ -10,7 +10,9 @@ let in stdenv.mkDerivation ({ name = (drv.name + "-check"); - src = drv; + # Useing `srcOnly` (rather than getting the `src` via a `drv.passthru`) + # should correctly apply the patches from `drv` (if any). + src = srcOnly drv; passthru = { inherit (drv) identifier config configFiles executableToolDepends cleanSrc env; @@ -31,7 +33,7 @@ in stdenv.mkDerivation ({ checkPhase = '' runHook preCheck - ${toString component.testWrapper} $src/${drv.installedExe} ${lib.concatStringsSep " " component.testFlags} | tee $out + ${toString component.testWrapper} ${drv}/${drv.installedExe} ${lib.concatStringsSep " " component.testFlags} | tee $out runHook postCheck ''; diff --git a/lib/default.nix b/lib/default.nix index 1483a468d4..90fad53b68 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,4 +1,4 @@ -{ stdenv, lib, haskellLib, runCommand, git }: +{ stdenv, lib, haskellLib, runCommand, git, srcOnly }: with haskellLib; @@ -162,6 +162,6 @@ with haskellLib; # Check a test component check = import ./check.nix { - inherit stdenv lib haskellLib; + inherit stdenv lib haskellLib srcOnly; }; } diff --git a/overlays/haskell.nix b/overlays/haskell.nix index 0e39032b0e..ec81691d59 100644 --- a/overlays/haskell.nix +++ b/overlays/haskell.nix @@ -59,7 +59,7 @@ self: super: { # Utility functions for working with the component builder. haskellLib = let hl = import ../lib { - inherit (self) stdenv lib runCommand; + inherit (self) stdenv lib runCommand srcOnly; inherit (self.buildPackages) git; haskellLib = hl; }; in hl; diff --git a/package-set.nix b/package-set.nix index 6836752c29..63523a8831 100644 --- a/package-set.nix +++ b/package-set.nix @@ -7,7 +7,7 @@ in pkgs.lib.evalModules { _module.args = { # this is *not* the hasekllLib from nixpkgs; it is rather our own # library from haskell.nix - haskellLib = let hl = import ./lib { inherit lib; inherit (pkgs) stdenv runCommand git; haskellLib = hl; }; in hl; + haskellLib = let hl = import ./lib { inherit lib; inherit (pkgs) stdenv runCommand git srcOnly; haskellLib = hl; }; in hl; # The package descriptions depend on pkgs, which are used to resolve system package dependencies # as well as pkgconfPkgs, which are used to resolve pkgconfig name to nixpkgs names. We simply From 46cd1a84fb7ad45fe16293396c2ff1378f2ebbbc Mon Sep 17 00:00:00 2001 From: Hamish Mackenzie Date: Fri, 29 Nov 2019 20:11:17 +1300 Subject: [PATCH 46/46] Remove collectRunComponents. Doc haskellLib.check --- docs/reference/library.md | 32 +++++++++++++++++++++++--------- lib/default.nix | 12 +----------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/docs/reference/library.md b/docs/reference/library.md index 318da43f02..513fee4a6e 100644 --- a/docs/reference/library.md +++ b/docs/reference/library.md @@ -281,17 +281,16 @@ Assorted functions for operating on [Haskell.nix][] data. This is distinct from `pkgs.haskell.lib` in the current Nixpkgs Haskell Infrastructure. -### collectRunComponents and collectComponents +### collectComponents -Extracts a selection of derivations to run components from a Haskell [package set](#package-set). +Extracts a selection of components from a Haskell [package set](#package-set). -`collectRunComponents` can be used to filter out all test suites or benchmarks of -your project, so that they can be built and run in Hydra. - -`collectComponents` can be used to just build the components. +This can be used to filter out all test suites or benchmarks of +your project, so that they can be built in Hydra (see check if you +waht to run the tests as well as build them). ``` -collectRunComponents = +collectComponents = group: packageSel: haskellPackages: ... ``` @@ -307,12 +306,27 @@ collectRunComponents = **Example**: ```nix -tests = collectRunComponents "tests" (package: package.identifier.name == "mypackage") hsPkgs; +tests = collectComponents "tests" (package: package.identifier.name == "mypackage") hsPkgs; ``` -Will result in moving derivations from `hsPkgs.mypackage.components.tests.unit-tests.run` +Will result in moving derivations from `hsPkgs.mypackage.components.tests.unit-tests` to `tests.mypackage.unit-tests`. +#### check + +This function turns a derivation that builds a test into one to run it. + +| Argument | Type | Description | +|-------------------|--------|---------------------| +| `drv` | Derivation | One of `$pkg.components.tests.$test`. | + +For convenience `$pkg.components.tests` are mapped with this function +to `$pkg.components.checks`. + +This function is intended for use with `tests` but it should also work +for `exes` and `benchmarks` if you just want to run them to make sure +they execute. + #### subComponentTypes Sub-component types identify [components](#component) and are one of: diff --git a/lib/default.nix b/lib/default.nix index 90fad53b68..a0230093e6 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -123,7 +123,7 @@ with haskellLib; # Extracts a selection of components from a Haskell package set. # # This can be used to filter out all test suites or benchmarks of - # your project, so that they can be built and run in Hydra. + # your project, so that they can be built in Hydra. # # For example: # @@ -133,21 +133,11 @@ with haskellLib; # from: hsPkgs.mypackage.components.tests.unit-tests # to: tests.mypackage.unit-tests # - # Note: To build, but not run the components use `collectComponents` - collectRunComponents = group: packageSel: haskellPackages: - collectRunDerivations (collectComponents group packageSel haskellPackages); - - # Like `collectRunComponents`, but does not build the `run` derivation - # (so your benchmark or test will be built, but not run). collectComponents = group: packageSel: haskellPackages: (lib.mapAttrs (_: package: package.components.${group} // { recurseForDerivations = true; }) (lib.filterAttrs (name: package: (package.isHaskell or false) && packageSel package) haskellPackages)) // { recurseForDerivations = true; }; - # If a derivation has a passthru.run derivation this will map to that - collectRunDerivations = - lib.mapAttrsRecursiveCond (d: !(lib.isDerivation d)) (_: d: d.run or d); - # Replacement for lib.cleanSourceWith that has a subDir argument. inherit (import ./clean-source-with.nix { inherit lib; }) cleanSourceWith canCleanSource;