Skip to content

Commit ad6a27a

Browse files
committed
Fixes and optimize nix-tools usage
1 parent 9b06216 commit ad6a27a

File tree

7 files changed

+48
-41
lines changed

7 files changed

+48
-41
lines changed

builder/comp-builder.nix

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -371,19 +371,18 @@ let
371371
# Not sure why pkgconfig needs to be propagatedBuildInputs but
372372
# for gi-gtk-hs it seems to help.
373373
++ builtins.concatLists pkgconfig
374+
++ configFiles.libDeps
374375
++ lib.optionals (stdenv.hostPlatform.isWindows)
375-
(lib.flatten component.libs
376-
++ map haskellLib.dependToLib component.depends);
376+
(lib.flatten component.libs);
377377

378378
buildInputs = lib.optionals (!stdenv.hostPlatform.isWindows)
379-
(lib.flatten component.libs
380-
++ map haskellLib.dependToLib component.depends);
379+
(lib.flatten component.libs);
381380

382381
nativeBuildInputs =
383382
[ghc buildPackages.removeReferencesTo]
384383
++ executableToolDepends;
385384

386-
outputs = ["out" "configFiles"]
385+
outputs = ["out"]
387386
++ (lib.optional enableSeparateDataOutput "data")
388387
++ (lib.optional keepSource "source")
389388
++ (lib.optional writeHieFiles "hie");
@@ -403,15 +402,12 @@ let
403402
'') + commonAttrs.prePatch;
404403

405404
configurePhase = ''
406-
echo A ${name}
405+
configFiles=$(mktemp -d)
407406
${configFiles.script}
408-
echo B ${name}
409407
wrappedGhc=$(mktemp -d)
410-
echo C ${name}
411408
${shellWrappers.script}
412-
echo D ${name}
413409
PATH=$wrappedGhc/bin:$PATH
414-
echo E ${name}
410+
415411
runHook preConfigure
416412
echo Configure flags:
417413
printf "%q " ${finalConfigureFlags}
@@ -602,4 +598,4 @@ let
602598
// lib.optionalAttrs (hardeningDisable != [] || stdenv.hostPlatform.isMusl) {
603599
hardeningDisable = hardeningDisable ++ lib.optional stdenv.hostPlatform.isMusl "pie";
604600
});
605-
in drv // { configFiles = drv.configFiles // configFiles; }; in self)
601+
in drv; in self)

builder/make-config-files.nix

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,11 @@ let
4949
libDir = "lib/${ghcCommand}-${ghc.version}";
5050
packageCfgDir = "${libDir}/package.conf.d";
5151

52-
# Filters out only library packages that for this GHC target
53-
# TODO investigate why this is needed
54-
# TODO find out why p ? configFiles helps (for instance for `R1909.aarch64-unknown-linux-gnu.tests.cabal-22.run.x86_64-linux`)
5552
libDeps = map chooseDrv (
5653
(if enableDWARF then (x: map (p: p.dwarf or p) x) else x: x)
5754
((if needsProfiling then (x: map (p: p.profiled or p) x) else x: x)
58-
(lib.filter (p: (p ? configFiles) && p.configFiles.targetPrefix == ghc.targetPrefix)
59-
(map getLibComponent component.depends)))
55+
(map haskellLib.dependToLib component.depends))
6056
);
61-
cfgFiles =
62-
let xs = map
63-
(p: "${p.configFiles}")
64-
libDeps;
65-
in lib.concatStringsSep "\" \"" xs;
66-
libs = lib.concatMapStringsSep "\" \"" (p: "${p}") libDeps;
6757
script = ''
6858
${target-pkg} init $configFiles/${packageCfgDir}
6959
@@ -86,8 +76,8 @@ let
8676
done
8777
''}
8878
89-
for l in "${cfgFiles}"; do
90-
if [ -n "$l" ]; then
79+
for l in "''${pkgsHostTarget[@]}"; do
80+
if [ -d "$l/${packageCfgDir}" ]; then
9181
files=("$l/${packageCfgDir}/"*.conf)
9282
if (( ''${#files[@]} )); then
9383
cp -f "''${files[@]}" $configFiles/${packageCfgDir}
@@ -97,8 +87,8 @@ let
9787
fi
9888
fi
9989
done
100-
for l in "${libs}"; do
101-
if [ -n "$l" ]; then
90+
for l in "''${pkgsHostTarget[@]}"; do
91+
if [ -d "$l/package.conf.d" ]; then
10292
files=("$l/package.conf.d/"*.conf)
10393
if (( ''${#files[@]} )); then
10494
cp -f "''${files[@]}" $configFiles/${packageCfgDir}
@@ -133,11 +123,15 @@ let
133123
echo "allow-older: ${identifier.name}:*" >> $configFiles/cabal.config
134124
''}
135125
136-
for p in ${lib.concatStringsSep " " libDeps}; do
137-
cat $p/envDep >> $configFiles/ghc-environment
126+
for p in $propagatedBuildInputs; do
127+
if [ -e $p/envDep ]; then
128+
cat $p/envDep >> $configFiles/ghc-environment
129+
fi
138130
${ lib.optionalString component.doExactConfig ''
139-
cat $p/exactDep/configure-flags >> $configFiles/configure-flags
140-
cat $p/exactDep/cabal.config >> $configFiles/cabal.config
131+
if [ -d $p/exactDep ]; then
132+
cat $p/exactDep/configure-flags >> $configFiles/configure-flags
133+
cat $p/exactDep/cabal.config >> $configFiles/cabal.config
134+
fi
141135
''}
142136
done
143137
for p in ${lib.concatStringsSep " " (lib.remove "ghc" nonReinstallablePkgs')}; do
@@ -211,7 +205,7 @@ let
211205
'');
212206
in {
213207
inherit (ghc) targetPrefix;
214-
inherit script drv ghcCommand ghcCommandCaps libDir packageCfgDir component;
208+
inherit script libDeps drv ghcCommand ghcCommandCaps libDir packageCfgDir component;
215209
# Use ''${pkgroot} relative paths so that we can relocate the package database
216210
# along with referenced packages and still have it work on systems with
217211
# or without nix installed.

builder/setup-builder.nix

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ let
4646
src = cleanSrc'.root;
4747
buildInputs = component.libs
4848
++ component.frameworks
49-
++ builtins.concatLists component.pkgconfig;
49+
++ builtins.concatLists component.pkgconfig
50+
++ configFiles.libDeps
51+
++ [ghc]; # Needs to be a build input so that the boot libraries are included
5052
nativeBuildInputs = [ghc] ++ executableToolDepends;
5153

5254
passthru = {
@@ -69,6 +71,9 @@ let
6971

7072
phases = ["unpackPhase" "patchPhase" "buildPhase" "installPhase"];
7173
buildPhase = ''
74+
configFiles=$(mktemp -d)
75+
mkdir -p $configFiles
76+
${configFiles.script}
7277
runHook preBuild
7378
if [[ ! -f ./Setup.hs && ! -f ./Setup.lhs ]]; then
7479
cat ${defaultSetupSrc} > Setup.hs
@@ -77,7 +82,7 @@ let
7782
if [ -f $f ]; then
7883
echo Compiling package $f
7984
ghc $f -threaded ${if includeGhcPackage then "-package ghc " else ""
80-
}-package-db ${configFiles.drv}/${configFiles.packageCfgDir} --make -o ./Setup
85+
}-package-db $configFiles/${configFiles.packageCfgDir} --make -o ./Setup
8186
fi
8287
done
8388
[ -f ./Setup ] || (echo Failed to build Setup && exit 1)

lib/call-cabal-project-to-nix.nix

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ in
6565
# any plutus-apps input being used for a
6666
# package.
6767
, evalPackages
68+
, supportHpack ? false # Run hpack on package.yaml files with no .cabal file
6869
, ...
6970
}@args:
7071

@@ -453,7 +454,10 @@ let
453454
} // pkgs.lib.optionalAttrs (checkMaterialization != null) {
454455
inherit checkMaterialization;
455456
}) (evalPackages.runCommand (nameAndSuffix "plan-to-nix-pkgs") {
456-
nativeBuildInputs = [ nix-tools dummy-ghc dummy-ghc-pkg cabal-install evalPackages.rsync evalPackages.gitMinimal ];
457+
nativeBuildInputs = [
458+
nix-tools.project.hsPkgs.nix-tools.components.exes.plan-to-nix
459+
dummy-ghc dummy-ghc-pkg cabal-install evalPackages.rsync evalPackages.gitMinimal ]
460+
++ pkgs.lib.optional supportHpack nix-tools.project.hsPkgs.hpack.components.exes.hpack;
457461
# Needed or stack-to-nix will die on unicode inputs
458462
LOCALE_ARCHIVE = pkgs.lib.optionalString (evalPackages.stdenv.buildPlatform.libc == "glibc") "${evalPackages.glibcLocales}/lib/locale/locale-archive";
459463
LANG = "en_US.UTF-8";
@@ -510,12 +514,20 @@ let
510514
if [ -e "$cabalFile" ]; then
511515
echo Ignoring $hpackFile as $cabalFile exists
512516
else
517+
${
513518
# warning: this may not generate the proper cabal file.
514519
# hpack allows globbing, and turns that into module lists
515-
# without the source available (we cleaneSourceWith'd it),
520+
# without the source available (we cleanSourceWith'd it),
516521
# this may not produce the right result.
517-
echo No .cabal file found, running hpack on $hpackFile
518-
hpack $hpackFile
522+
if supportHpack
523+
then ''
524+
echo No .cabal file found, running hpack on $hpackFile
525+
hpack $hpackFile
526+
''
527+
else ''
528+
echo WARNING $hpackFile has no .cabal file and `supportHpack` was not set.
529+
''
530+
}
519531
fi
520532
done
521533
)

overlays/bootstrap.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ in {
980980
final.buildPackages.buildPackages.gitMinimal
981981
final.buildPackages.buildPackages.nix-prefetch-git ];
982982
in
983-
final.buildPackages.symlinkJoin {
983+
(final.buildPackages.symlinkJoin {
984984
name = "nix-tools";
985985
paths = exes;
986986
buildInputs = [ final.buildPackages.makeWrapper ];
@@ -992,7 +992,7 @@ in {
992992
wrapProgram "$out/bin/$prog" --prefix PATH : "${final.lib.makeBinPath tools}"
993993
done
994994
'';
995-
};
995+
}) // { inherit project; };
996996

997997
# Memoize the cabal-install and nix-tools derivations by adding:
998998
# haskell-nix.cabal-install.ghcXXX

overlays/default-setup.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ let
3737
# version of Cabal bundled with GHC).
3838
cabalFromCabalInstall = final.buildPackages.haskell-nix.cabal-install-unchecked.${compiler-nix-name}.project.hsPkgs.Cabal.components.library;
3939

40-
in ghc // rec {
40+
in ghc // rec {
4141
defaultSetup = final.lib.mapAttrs (_: useCabalFromCabalInstall: setup-builder ({
4242
name = "${ghc.targetPrefix}default-Setup";
4343
component = {

overlays/haskell.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ final: prev: {
193193
name = "01-index.tar.gz-at-${at}";
194194
url = "https://hackage.haskell.org/01-index.tar.gz";
195195
downloadToTemp = true;
196-
postFetch = "${nix-tools}/bin/truncate-index -o $out -i $downloadedFile -s ${index-state}";
196+
postFetch = "${nix-tools.project.hsPkgs.nix-tools.components.exes.truncate-index}/bin/truncate-index -o $out -i $downloadedFile -s ${index-state}";
197197

198198
outputHashAlgo = "sha256";
199199
outputHash = sha256;

0 commit comments

Comments
 (0)