From 383fbfadccaa12f908f79ab83f21fa5dbe10c6be Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Thu, 31 Mar 2022 12:37:00 +0200 Subject: [PATCH 1/4] ghcWithPackages: use packageCfgDir over ghc.name where appropriate This is an incorrectness pointed out in #153319 which we already have a proper solution for. --- pkgs/development/haskell-modules/with-packages-wrapper.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/development/haskell-modules/with-packages-wrapper.nix b/pkgs/development/haskell-modules/with-packages-wrapper.nix index 7c7add61679d..65a575e08e8a 100644 --- a/pkgs/development/haskell-modules/with-packages-wrapper.nix +++ b/pkgs/development/haskell-modules/with-packages-wrapper.nix @@ -121,7 +121,7 @@ symlinkJoin { '' + (lib.optionalString (stdenv.targetPlatform.isDarwin && !isGhcjs && !stdenv.targetPlatform.isiOS) '' # Work around a linker limit in macOS Sierra (see generic-builder.nix): - local packageConfDir="$out/lib/${ghc.name}/package.conf.d"; + local packageConfDir="${packageCfgDir}"; local dynamicLinksDir="$out/lib/links" mkdir -p $dynamicLinksDir # Clean up the old links that may have been (transitively) included by @@ -148,8 +148,8 @@ symlinkJoin { # to another nix derivation, so they are not writable. Removing # them allow the correct behavior of ghc-pkg recache # See: https://github.com/NixOS/nixpkgs/issues/79441 - rm $out/lib/${ghc.name}/package.conf.d/package.cache.lock - rm $out/lib/${ghc.name}/package.conf.d/package.cache + rm ${packageCfgDir}/package.cache.lock + rm ${packageCfgDir}/package.cache $out/bin/${ghcCommand}-pkg recache ''} From 78a93b5352a26bbbad4a9f22f0fcdaf76f5dc176 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Thu, 31 Mar 2022 12:47:54 +0200 Subject: [PATCH 2/4] haskellPackages.mkDerivation: get ghclibdir via haskellCompilerName This is the correctest and clearest way to do it I can think of at the moment that doesn't need us to add anything. "${ghcCommand}-${ghc.version}" also works, but is clunkier and harder to replicate for downstream users. --- pkgs/development/haskell-modules/generic-builder.nix | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkgs/development/haskell-modules/generic-builder.nix b/pkgs/development/haskell-modules/generic-builder.nix index 04973d3251e6..f63533137030 100644 --- a/pkgs/development/haskell-modules/generic-builder.nix +++ b/pkgs/development/haskell-modules/generic-builder.nix @@ -195,13 +195,13 @@ let "--prefix=$out" "--libdir=\\$prefix/lib/\\$compiler" "--libsubdir=\\$abi/\\$libname" - (optionalString enableSeparateDataOutput "--datadir=$data/share/${ghc.name}") + (optionalString enableSeparateDataOutput "--datadir=$data/share/${ghcNameWithPrefix}") (optionalString enableSeparateDocOutput "--docdir=${docdir "$doc"}") ] ++ optionals stdenv.hasCC [ "--with-gcc=$CC" # Clang won't work without that extra information. ] ++ [ "--package-db=$packageConfDir" - (optionalString (enableSharedExecutables && stdenv.isLinux) "--ghc-option=-optl=-Wl,-rpath=$out/lib/${ghc.name}/${pname}-${version}") + (optionalString (enableSharedExecutables && stdenv.isLinux) "--ghc-option=-optl=-Wl,-rpath=$out/lib/${ghcNameWithPrefix}/${pname}-${version}") (optionalString (enableSharedExecutables && stdenv.isDarwin) "--ghc-option=-optl=-Wl,-headerpad_max_install_names") (optionalString enableParallelBuilding "--ghc-options=${parallelBuildingFlags}") (optionalString useCpphs "--with-cpphs=${cpphs}/bin/cpphs --ghc-options=-cpp --ghc-options=-pgmP${cpphs}/bin/cpphs --ghc-options=-optP--cpp") @@ -274,6 +274,8 @@ let ghcCommand' = if isGhcjs then "ghcjs" else "ghc"; ghcCommand = "${ghc.targetPrefix}${ghcCommand'}"; + ghcNameWithPrefix = "${ghc.targetPrefix}${ghc.haskellCompilerName}"; + nativeGhcCommand = "${nativeGhc.targetPrefix}ghc"; buildPkgDb = ghcName: packageConfDir: '' @@ -349,14 +351,14 @@ stdenv.mkDerivation ({ # pkgs* arrays defined in stdenv/setup.hs + '' for p in "''${pkgsBuildBuild[@]}" "''${pkgsBuildHost[@]}" "''${pkgsBuildTarget[@]}"; do - ${buildPkgDb nativeGhc.name "$setupPackageConfDir"} + ${buildPkgDb "${nativeGhcCommand}-${nativeGhc.version}" "$setupPackageConfDir"} done ${nativeGhcCommand}-pkg --${nativePackageDbFlag}="$setupPackageConfDir" recache '' # For normal components + '' for p in "''${pkgsHostHost[@]}" "''${pkgsHostTarget[@]}"; do - ${buildPkgDb ghc.name "$packageConfDir"} + ${buildPkgDb ghcNameWithPrefix "$packageConfDir"} if [ -d "$p/include" ]; then configureFlags+=" --extra-include-dirs=$p/include" fi @@ -493,7 +495,7 @@ stdenv.mkDerivation ({ # just the target specified; "install" will error here, since not all targets have been built. else '' ${setupCommand} copy ${buildTarget} - local packageConfDir="$out/lib/${ghc.name}/package.conf.d" + local packageConfDir="$out/lib/${ghcNameWithPrefix}/package.conf.d" local packageConfFile="$packageConfDir/${pname}-${version}.conf" mkdir -p "$packageConfDir" ${setupCommand} register --gen-pkg-config=$packageConfFile From 456faf71e5a842128589e0b44dea3d426fa87e40 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Thu, 31 Mar 2022 12:50:43 +0200 Subject: [PATCH 3/4] ghcWithPackages: use haskellCompilerName for ghclibdir This is done for consistency with generic-builder.nix and because it's easier for downstream users to replicate which will inevitably use our code as inspiration. --- pkgs/development/haskell-modules/with-packages-wrapper.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/haskell-modules/with-packages-wrapper.nix b/pkgs/development/haskell-modules/with-packages-wrapper.nix index 65a575e08e8a..c478c875540d 100644 --- a/pkgs/development/haskell-modules/with-packages-wrapper.nix +++ b/pkgs/development/haskell-modules/with-packages-wrapper.nix @@ -51,7 +51,7 @@ let ghcCommand = "${ghc.targetPrefix}${ghcCommand'}"; ghcCommandCaps= lib.toUpper ghcCommand'; libDir = if isHaLVM then "$out/lib/HaLVM-${ghc.version}" - else "$out/lib/${ghcCommand}-${ghc.version}"; + else "$out/lib/${ghc.targetPrefix}${ghc.haskellCompilerName}"; docDir = "$out/share/doc/ghc/html"; packageCfgDir = "${libDir}/package.conf.d"; paths = lib.filter (x: x ? isHaskellLibrary) (lib.closePropagation packages); From 6016ed50768d2ccc5417382970bb16948bc76c95 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Thu, 31 Mar 2022 12:53:40 +0200 Subject: [PATCH 4/4] treewide: replace uses of ghc.name to find packages' datadir --- nixos/modules/services/misc/gitit.nix | 2 +- pkgs/development/haskell-modules/configuration-common.nix | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nixos/modules/services/misc/gitit.nix b/nixos/modules/services/misc/gitit.nix index ceb186c0f049..87dd97166b8e 100644 --- a/nixos/modules/services/misc/gitit.nix +++ b/nixos/modules/services/misc/gitit.nix @@ -10,7 +10,7 @@ let toYesNo = b: if b then "yes" else "no"; - gititShared = with cfg.haskellPackages; gitit + "/share/" + pkgs.stdenv.hostPlatform.system + "-" + ghc.name + "/" + gitit.pname + "-" + gitit.version; + gititShared = with cfg.haskellPackages; gitit + "/share/" + ghc.targetPrefix + ghc.haskellCompilerName + "/" + gitit.pname + "-" + gitit.version; gititWithPkgs = hsPkgs: extras: hsPkgs.ghcWithPackages (self: with self; [ gitit ] ++ (extras self)); diff --git a/pkgs/development/haskell-modules/configuration-common.nix b/pkgs/development/haskell-modules/configuration-common.nix index dfa47f2a82c5..809259da3ee5 100644 --- a/pkgs/development/haskell-modules/configuration-common.nix +++ b/pkgs/development/haskell-modules/configuration-common.nix @@ -613,7 +613,7 @@ self: super: { doCheck = false; # https://github.com/kazu-yamamoto/ghc-mod/issues/335 executableToolDepends = drv.executableToolDepends or [] ++ [pkgs.buildPackages.emacs]; postInstall = '' - local lispdir=( "$data/share/${self.ghc.name}/*/${drv.pname}-${drv.version}/elisp" ) + local lispdir=( "$data/share/${self.ghc.targetPrefix}${self.ghc.haskellCompilerName}/*/${drv.pname}-${drv.version}/elisp" ) make -C $lispdir mkdir -p $data/share/emacs/site-lisp ln -s "$lispdir/"*.el{,c} $data/share/emacs/site-lisp/ @@ -648,7 +648,7 @@ self: super: { # cannot easily byte-compile these files, unfortunately, because they # depend on a new version of haskell-mode that we don't have yet. postInstall = '' - local lispdir=( "$data/share/${self.ghc.name}/"*"/${drv.pname}-"*"/elisp" ) + local lispdir=( "$data/share/${self.ghc.targetPrefix}${self.ghc.haskellCompilerName}/"*"/${drv.pname}-"*"/elisp" ) mkdir -p $data/share/emacs ln -s $lispdir $data/share/emacs/site-lisp ''; @@ -659,7 +659,7 @@ self: super: { # We cannot easily byte-compile these files, unfortunately, because they # depend on a new version of haskell-mode that we don't have yet. postInstall = '' - local lispdir=( "$data/share/${self.ghc.name}/"*"/${drv.pname}-"*"/elisp" ) + local lispdir=( "$data/share/${self.ghc.targetPrefix}${self.ghc.haskellCompilerName}/"*"/${drv.pname}-"*"/elisp" ) mkdir -p $data/share/emacs ln -s $lispdir $data/share/emacs/site-lisp '';