From fdaa426452250db4f4c73c2c7a79136ee41267d4 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 17 Sep 2018 23:11:59 +0200 Subject: [PATCH 1/3] haskell.lib.getBuildInputs: Use generic builder passthru to implement --- .../haskell-modules/generic-builder.nix | 15 ++++- pkgs/development/haskell-modules/lib.nix | 56 +------------------ 2 files changed, 13 insertions(+), 58 deletions(-) diff --git a/pkgs/development/haskell-modules/generic-builder.nix b/pkgs/development/haskell-modules/generic-builder.nix index 1fd64c79fc2c..4f713e055099 100644 --- a/pkgs/development/haskell-modules/generic-builder.nix +++ b/pkgs/development/haskell-modules/generic-builder.nix @@ -173,8 +173,7 @@ let (optionalString (versionOlder "7.10" ghc.version && !isHaLVM) "-threaded") ]; - isHaskellPkg = x: (x ? pname) && (x ? version) && (x ? env); - isSystemPkg = x: !isHaskellPkg x; + isHaskellPkg = x: x ? isHaskellLibrary; allPkgconfigDepends = pkgconfigDepends ++ libraryPkgconfigDepends ++ executablePkgconfigDepends ++ optionals doCheck testPkgconfigDepends ++ optionals doBenchmark benchmarkPkgconfigDepends; @@ -191,7 +190,10 @@ let optionals doCheck (testDepends ++ testHaskellDepends ++ testSystemDepends ++ testFrameworkDepends) ++ optionals doBenchmark (benchmarkDepends ++ benchmarkHaskellDepends ++ benchmarkSystemDepends ++ benchmarkFrameworkDepends); - allBuildInputs = propagatedBuildInputs ++ otherBuildInputs; + + allBuildInputs = propagatedBuildInputs ++ otherBuildInputs ++ depsBuildBuild; + isHaskellPartition = + stdenv.lib.partition isHaskellPkg allBuildInputs; haskellBuildInputs = stdenv.lib.filter isHaskellPkg allBuildInputs; systemBuildInputs = stdenv.lib.filter isSystemPkg allBuildInputs; @@ -428,6 +430,13 @@ stdenv.mkDerivation ({ compiler = ghc; + + getBuildInputs = { + inherit propagatedBuildInputs otherBuildInputs allPkgconfigDepends; + haskellBuildInputs = isHaskellPartition.right; + systemBuildInputs = isHaskellPartition.wrong; + }; + isHaskellLibrary = isLibrary; # TODO: ask why the split outputs are configurable at all? diff --git a/pkgs/development/haskell-modules/lib.nix b/pkgs/development/haskell-modules/lib.nix index 8dae7c8d72c0..6155e158e9de 100644 --- a/pkgs/development/haskell-modules/lib.nix +++ b/pkgs/development/haskell-modules/lib.nix @@ -299,12 +299,7 @@ rec { overrideCabal drv (_: { inherit src version; editedCabalFile = null; }); # Get all of the build inputs of a haskell package, divided by category. - getBuildInputs = p: - (overrideCabal p (args: { - passthru = (args.passthru or {}) // { - _getBuildInputs = extractBuildInputs p.compiler args; - }; - }))._getBuildInputs; + getBuildInputs = p: p.getBuildInputs; # Extract the haskell build inputs of a haskell package. # This is useful to build environments for developing on that @@ -339,55 +334,6 @@ rec { , ... }: { inherit doCheck doBenchmark; }; - # Divide the build inputs of the package into useful sets. - extractBuildInputs = ghc: - { setupHaskellDepends ? [], extraLibraries ? [] - , librarySystemDepends ? [], executableSystemDepends ? [] - , pkgconfigDepends ? [], libraryPkgconfigDepends ? [] - , executablePkgconfigDepends ? [], testPkgconfigDepends ? [] - , benchmarkPkgconfigDepends ? [], testDepends ? [] - , testHaskellDepends ? [], testSystemDepends ? [] - , testToolDepends ? [], benchmarkDepends ? [] - , benchmarkHaskellDepends ? [], benchmarkSystemDepends ? [] - , benchmarkToolDepends ? [], buildDepends ? [] - , libraryHaskellDepends ? [], executableHaskellDepends ? [] - , ... - }@args: - let inherit (ghcInfo ghc) isGhcjs nativeGhc; - inherit (controlPhases ghc args) doCheck doBenchmark; - isHaskellPkg = x: x ? isHaskellLibrary; - allPkgconfigDepends = - pkgconfigDepends ++ libraryPkgconfigDepends ++ - executablePkgconfigDepends ++ - lib.optionals doCheck testPkgconfigDepends ++ - lib.optionals doBenchmark benchmarkPkgconfigDepends; - otherBuildInputs = - setupHaskellDepends ++ extraLibraries ++ - librarySystemDepends ++ executableSystemDepends ++ - allPkgconfigDepends ++ - lib.optionals doCheck ( testDepends ++ testHaskellDepends ++ - testSystemDepends ++ testToolDepends - ) ++ - # ghcjs's hsc2hs calls out to the native hsc2hs - lib.optional isGhcjs nativeGhc ++ - lib.optionals doBenchmark ( benchmarkDepends ++ - benchmarkHaskellDepends ++ - benchmarkSystemDepends ++ - benchmarkToolDepends - ); - propagatedBuildInputs = - buildDepends ++ libraryHaskellDepends ++ - executableHaskellDepends; - allBuildInputs = propagatedBuildInputs ++ otherBuildInputs; - isHaskellPartition = - lib.partition isHaskellPkg allBuildInputs; - in - { haskellBuildInputs = isHaskellPartition.right; - systemBuildInputs = isHaskellPartition.wrong; - inherit propagatedBuildInputs otherBuildInputs - allPkgconfigDepends; - }; - # Utility to convert a directory full of `cabal2nix`-generated files into a # package override set # From 08814b72cf8641d8b03c7e1296e1911ec09261f8 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 17 Sep 2018 23:18:43 +0200 Subject: [PATCH 2/3] haskellPackages.shellFor: Clean and fixup - Now correctly sets NIX_GHC* env vars --- .../haskell-modules/make-package-set.nix | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/pkgs/development/haskell-modules/make-package-set.nix b/pkgs/development/haskell-modules/make-package-set.nix index 45cc37117883..3a6d0bb128b8 100644 --- a/pkgs/development/haskell-modules/make-package-set.nix +++ b/pkgs/development/haskell-modules/make-package-set.nix @@ -256,20 +256,46 @@ in package-set { inherit pkgs stdenv callPackage; } self // { shellFor = { packages, withHoogle ? false, ... } @ args: let selected = packages self; - packageInputs = builtins.map getBuildInputs selected; - haskellInputs = - builtins.filter - (input: pkgs.lib.all (p: input.outPath != p.outPath) selected) - (pkgs.lib.concatMap (p: p.haskellBuildInputs) packageInputs); + + packageInputs = map getBuildInputs selected; + + name = if pkgs.lib.length selected == 1 + then "ghc-shell-for-${(pkgs.lib.head selected).name}" + else "ghc-shell-for-packages"; + + # If `packages = [ a b ]` and `a` depends on `b`, don't build `b`, + # because cabal will end up ignoring that built version, assuming + # new-style commands. + haskellInputs = pkgs.lib.filter + (input: pkgs.lib.all (p: input.outPath != p.outPath) selected) + (pkgs.lib.concatMap (p: p.haskellBuildInputs) packageInputs); systemInputs = pkgs.lib.concatMap (p: p.systemBuildInputs) packageInputs; + withPackages = if withHoogle then self.ghcWithHoogle else self.ghcWithPackages; + ghcEnv = withPackages (p: haskellInputs); + nativeBuildInputs = pkgs.lib.concatMap (p: p.nativeBuildInputs) selected; + + ghcCommand' = if ghc.isGhcjs or false then "ghcjs" else "ghc"; + ghcCommand = "${ghc.targetPrefix}${ghcCommand'}"; + ghcCommandCaps= pkgs.lib.toUpper ghcCommand'; + mkDrvArgs = builtins.removeAttrs args ["packages" "withHoogle"]; in pkgs.stdenv.mkDerivation (mkDrvArgs // { - name = "ghc-shell-for-packages"; - nativeBuildInputs = [(withPackages (_: haskellInputs))] ++ mkDrvArgs.nativeBuildInputs or []; + name = mkDrvArgs.name or name; + buildInputs = systemInputs ++ mkDrvArgs.buildInputs or []; + nativeBuildInputs = [ ghcEnv ] ++ nativeBuildInputs ++ mkDrvArgs.nativeBuildInputs or []; phases = ["installPhase"]; installPhase = "echo $nativeBuildInputs $buildInputs > $out"; + LANG = "en_US.UTF-8"; + LOCALE_ARCHIVE = pkgs.lib.optionalString (stdenv.hostPlatform.libc == "glibc") "${buildPackages.glibcLocales}/lib/locale/locale-archive"; + "NIX_${ghcCommandCaps}" = "${ghcEnv}/bin/${ghcCommand}"; + "NIX_${ghcCommandCaps}PKG" = "${ghcEnv}/bin/${ghcCommand}-pkg"; + # TODO: is this still valid? + "NIX_${ghcCommandCaps}_DOCDIR" = "${ghcEnv}/share/doc/ghc/html"; + "NIX_${ghcCommandCaps}_LIBDIR" = if ghc.isHaLVM or false + then "${ghcEnv}/lib/HaLVM-${ghc.version}" + else "${ghcEnv}/lib/${ghcCommand}-${ghc.version}"; }); ghc = ghc // { From 2bafa93b75464eee5744653319d8046e05cf141a Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 17 Sep 2018 23:20:29 +0200 Subject: [PATCH 3/3] haskellPackages.*.env: Use shellFor --- .../haskell-modules/generic-builder.nix | 33 ++++--------------- .../haskell-modules/make-package-set.nix | 2 +- 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/pkgs/development/haskell-modules/generic-builder.nix b/pkgs/development/haskell-modules/generic-builder.nix index 4f713e055099..45ee8e33bbaa 100644 --- a/pkgs/development/haskell-modules/generic-builder.nix +++ b/pkgs/development/haskell-modules/generic-builder.nix @@ -1,5 +1,5 @@ { stdenv, buildPackages, buildHaskellPackages, ghc -, jailbreak-cabal, hscolour, cpphs, nodejs +, jailbreak-cabal, hscolour, cpphs, nodejs, shellFor }: let @@ -195,18 +195,10 @@ let isHaskellPartition = stdenv.lib.partition isHaskellPkg allBuildInputs; - haskellBuildInputs = stdenv.lib.filter isHaskellPkg allBuildInputs; - systemBuildInputs = stdenv.lib.filter isSystemPkg allBuildInputs; - - # When not cross compiling, also include Setup.hs dependencies. - ghcEnv = ghc.withPackages (p: - haskellBuildInputs ++ stdenv.lib.optional (!isCross) setupHaskellDepends); - setupCommand = "./Setup"; ghcCommand' = if isGhcjs then "ghcjs" else "ghc"; ghcCommand = "${ghc.targetPrefix}${ghcCommand'}"; - ghcCommandCaps= toUpper ghcCommand'; nativeGhcCommand = "${nativeGhc.targetPrefix}ghc"; @@ -216,8 +208,7 @@ let continue fi ''; - -in +in stdenv.lib.fix (drv: assert allPkgconfigDepends != [] -> pkgconfig != null; @@ -447,23 +438,10 @@ stdenv.mkDerivation ({ # TODO: fetch the self from the fixpoint instead haddockDir = self: if doHaddock then "${docdir self.doc}/html" else null; - env = stdenv.mkDerivation { - name = "interactive-${pname}-${version}-environment"; - buildInputs = systemBuildInputs; - nativeBuildInputs = [ ghcEnv ] ++ nativeBuildInputs; - LANG = "en_US.UTF-8"; - LOCALE_ARCHIVE = optionalString (stdenv.hostPlatform.libc == "glibc") "${glibcLocales}/lib/locale/locale-archive"; - shellHook = '' - export NIX_${ghcCommandCaps}="${ghcEnv}/bin/${ghcCommand}" - export NIX_${ghcCommandCaps}PKG="${ghcEnv}/bin/${ghcCommand}-pkg" - # TODO: is this still valid? - export NIX_${ghcCommandCaps}_DOCDIR="${ghcEnv}/share/doc/ghc/html" - ${if isHaLVM - then ''export NIX_${ghcCommandCaps}_LIBDIR="${ghcEnv}/lib/HaLVM-${ghc.version}"'' - else ''export NIX_${ghcCommandCaps}_LIBDIR="${ghcEnv}/lib/${ghcCommand}-${ghc.version}"''} - ${shellHook} - ''; + env = shellFor { + packages = p: [ drv ]; }; + }; meta = { inherit homepage license platforms; } @@ -497,3 +475,4 @@ stdenv.mkDerivation ({ // optionalAttrs (hardeningDisable != []) { inherit hardeningDisable; } // optionalAttrs (stdenv.buildPlatform.libc == "glibc"){ LOCALE_ARCHIVE = "${glibcLocales}/lib/locale/locale-archive"; } ) +) diff --git a/pkgs/development/haskell-modules/make-package-set.nix b/pkgs/development/haskell-modules/make-package-set.nix index 3a6d0bb128b8..fd74034a0744 100644 --- a/pkgs/development/haskell-modules/make-package-set.nix +++ b/pkgs/development/haskell-modules/make-package-set.nix @@ -43,7 +43,7 @@ let mkDerivationImpl = pkgs.callPackage ./generic-builder.nix { inherit stdenv; nodejs = buildPackages.nodejs-slim; - inherit (self) buildHaskellPackages ghc; + inherit (self) buildHaskellPackages ghc shellFor; inherit (self.buildHaskellPackages) jailbreak-cabal; hscolour = overrideCabal self.buildHaskellPackages.hscolour (drv: { isLibrary = false;