Skip to content

Reduce the number of derivations #1605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
b4a36e9
Store default setup on ghc derivation
hamishmack Aug 5, 2022
9b06216
Less derivations first cut
hamishmack Aug 7, 2022
ad6a27a
Fixes and optimize nix-tools usage
hamishmack Aug 9, 2022
1069180
Fix cabal.config
hamishmack Aug 11, 2022
d7004ee
Fix for cabal package db issue in nix shell
hamishmack Aug 15, 2022
08bb11b
Fixes for shellFor and hoogle in shell
hamishmack Aug 15, 2022
c94ed63
Fixes for shellFor and hoogle in shell
hamishmack Aug 15, 2022
417a7da
Fix hpack support
hamishmack Aug 16, 2022
afb52d9
Fix (p.shellFor {}).ghc
hamishmack Aug 16, 2022
1aa5e2b
More fixes for shellFor
hamishmack Aug 16, 2022
16e23cb
More fixes for shellFor
hamishmack Aug 16, 2022
11fe87c
Use ghc env for exactDeps
hamishmack Aug 16, 2022
12ecc24
Keep config files and wrapped ghc for cabal-doctest
hamishmack Aug 16, 2022
51737c7
Fix name clash
hamishmack Aug 16, 2022
82cda52
Remove special treatment of ghc dependency in custom setup
hamishmack Aug 17, 2022
af62a32
Merge remote-tracking branch 'origin/master' into hkm/combined-deriva…
hamishmack Aug 18, 2022
14f7a4b
Fix ghcjs and use ln -s instead of cp
hamishmack Aug 20, 2022
362b982
ifdLevel 0
hamishmack Aug 20, 2022
07c4426
ifdLevel 1
hamishmack Aug 20, 2022
c744c1e
ifdLevel 2
hamishmack Aug 20, 2022
0c6f255
ifdLevel 3
hamishmack Aug 20, 2022
557bebc
Fix for ghcjs default setup
hamishmack Aug 21, 2022
acb0eb0
Only propagate inputs to library components
hamishmack Aug 22, 2022
d17dcbf
ifdLevel 0
hamishmack Aug 20, 2022
872cb27
Shorten nix-tools attribute path
hamishmack Aug 22, 2022
db3ca22
Shorten nix-tools attribute path
hamishmack Aug 22, 2022
ba5bc4e
Fix closure size issue
hamishmack Aug 22, 2022
46846bf
Merge remote-tracking branch 'origin/master' into hkm/combined-deriva…
hamishmack Aug 25, 2022
42d08a6
Merge remote-tracking branch 'origin/master' into hkm/combined-deriva…
hamishmack Aug 29, 2022
e894bc2
Merge remote-tracking branch 'origin/master' into hkm/combined-deriva…
hamishmack Aug 31, 2022
9499917
Merge remote-tracking branch 'origin/master' into hkm/combined-deriva…
hamishmack Aug 31, 2022
5f32a61
ifdLevel 1
hamishmack Aug 31, 2022
eb6e1c2
Use cabal 3.8
hamishmack Sep 2, 2022
0dedd34
ifdLevel 0
hamishmack Sep 2, 2022
eccd186
Use tool function for cabal
hamishmack Sep 2, 2022
bbcc46f
ifdLevel 1
hamishmack Sep 3, 2022
1d7f07d
ifdLevel 2
hamishmack Sep 3, 2022
a17863c
ifdLevel 3
hamishmack Sep 3, 2022
2611a66
Explicit pkg-config
hamishmack Sep 4, 2022
0acd595
Merge branch 'hkm/use-cabal-3.8' into hkm/combined-derivations
hamishmack Sep 4, 2022
8a0d0d1
Fix merge issue
hamishmack Sep 4, 2022
eec5710
ifdLevel 2
hamishmack Sep 4, 2022
204296f
More fixes and work arounds
hamishmack Sep 5, 2022
a39ad04
Fix for cross compile
hamishmack Sep 5, 2022
0e3417a
Fix test.sh
hamishmack Sep 6, 2022
9621d93
Add description for `pkgconfigSelector`
hamishmack Sep 6, 2022
09fec30
Merge branch 'hkm/use-cabal-3.8' into hkm/combined-derivations
hamishmack Sep 6, 2022
b5f42a5
Fix merge issue
hamishmack Sep 6, 2022
8021d30
Merge remote-tracking branch 'origin/master' into hkm/combined-deriva…
hamishmack Oct 3, 2022
489111a
Merge remote-tracking branch 'origin/master' into hkm/combined-deriva…
hamishmack Oct 5, 2022
db5eff6
Check that stack builds
hamishmack Oct 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixes and optimize nix-tools usage
  • Loading branch information
hamishmack committed Aug 9, 2022
commit ad6a27aefac9bc9a7b03ced5ea7562c023003cbb
18 changes: 7 additions & 11 deletions builder/comp-builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -371,19 +371,18 @@ let
# Not sure why pkgconfig needs to be propagatedBuildInputs but
# for gi-gtk-hs it seems to help.
++ builtins.concatLists pkgconfig
++ configFiles.libDeps
++ lib.optionals (stdenv.hostPlatform.isWindows)
(lib.flatten component.libs
++ map haskellLib.dependToLib component.depends);
(lib.flatten component.libs);

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

nativeBuildInputs =
[ghc buildPackages.removeReferencesTo]
++ executableToolDepends;

outputs = ["out" "configFiles"]
outputs = ["out"]
++ (lib.optional enableSeparateDataOutput "data")
++ (lib.optional keepSource "source")
++ (lib.optional writeHieFiles "hie");
Expand All @@ -403,15 +402,12 @@ let
'') + commonAttrs.prePatch;

configurePhase = ''
echo A ${name}
configFiles=$(mktemp -d)
${configFiles.script}
echo B ${name}
wrappedGhc=$(mktemp -d)
echo C ${name}
${shellWrappers.script}
echo D ${name}
PATH=$wrappedGhc/bin:$PATH
echo E ${name}

runHook preConfigure
echo Configure flags:
printf "%q " ${finalConfigureFlags}
Expand Down Expand Up @@ -602,4 +598,4 @@ let
// lib.optionalAttrs (hardeningDisable != [] || stdenv.hostPlatform.isMusl) {
hardeningDisable = hardeningDisable ++ lib.optional stdenv.hostPlatform.isMusl "pie";
});
in drv // { configFiles = drv.configFiles // configFiles; }; in self)
in drv; in self)
34 changes: 14 additions & 20 deletions builder/make-config-files.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,11 @@ let
libDir = "lib/${ghcCommand}-${ghc.version}";
packageCfgDir = "${libDir}/package.conf.d";

# Filters out only library packages that for this GHC target
# TODO investigate why this is needed
# TODO find out why p ? configFiles helps (for instance for `R1909.aarch64-unknown-linux-gnu.tests.cabal-22.run.x86_64-linux`)
libDeps = map chooseDrv (
(if enableDWARF then (x: map (p: p.dwarf or p) x) else x: x)
((if needsProfiling then (x: map (p: p.profiled or p) x) else x: x)
(lib.filter (p: (p ? configFiles) && p.configFiles.targetPrefix == ghc.targetPrefix)
(map getLibComponent component.depends)))
(map haskellLib.dependToLib component.depends))
);
cfgFiles =
let xs = map
(p: "${p.configFiles}")
libDeps;
in lib.concatStringsSep "\" \"" xs;
libs = lib.concatMapStringsSep "\" \"" (p: "${p}") libDeps;
script = ''
${target-pkg} init $configFiles/${packageCfgDir}

Expand All @@ -86,8 +76,8 @@ let
done
''}

for l in "${cfgFiles}"; do
if [ -n "$l" ]; then
for l in "''${pkgsHostTarget[@]}"; do
if [ -d "$l/${packageCfgDir}" ]; then
files=("$l/${packageCfgDir}/"*.conf)
if (( ''${#files[@]} )); then
cp -f "''${files[@]}" $configFiles/${packageCfgDir}
Expand All @@ -97,8 +87,8 @@ let
fi
fi
done
for l in "${libs}"; do
if [ -n "$l" ]; then
for l in "''${pkgsHostTarget[@]}"; do
if [ -d "$l/package.conf.d" ]; then
files=("$l/package.conf.d/"*.conf)
if (( ''${#files[@]} )); then
cp -f "''${files[@]}" $configFiles/${packageCfgDir}
Expand Down Expand Up @@ -133,11 +123,15 @@ let
echo "allow-older: ${identifier.name}:*" >> $configFiles/cabal.config
''}

for p in ${lib.concatStringsSep " " libDeps}; do
cat $p/envDep >> $configFiles/ghc-environment
for p in $propagatedBuildInputs; do
if [ -e $p/envDep ]; then
cat $p/envDep >> $configFiles/ghc-environment
fi
${ lib.optionalString component.doExactConfig ''
cat $p/exactDep/configure-flags >> $configFiles/configure-flags
cat $p/exactDep/cabal.config >> $configFiles/cabal.config
if [ -d $p/exactDep ]; then
cat $p/exactDep/configure-flags >> $configFiles/configure-flags
cat $p/exactDep/cabal.config >> $configFiles/cabal.config
fi
''}
done
for p in ${lib.concatStringsSep " " (lib.remove "ghc" nonReinstallablePkgs')}; do
Expand Down Expand Up @@ -211,7 +205,7 @@ let
'');
in {
inherit (ghc) targetPrefix;
inherit script drv ghcCommand ghcCommandCaps libDir packageCfgDir component;
inherit script libDeps drv ghcCommand ghcCommandCaps libDir packageCfgDir component;
# Use ''${pkgroot} relative paths so that we can relocate the package database
# along with referenced packages and still have it work on systems with
# or without nix installed.
Expand Down
9 changes: 7 additions & 2 deletions builder/setup-builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ let
src = cleanSrc'.root;
buildInputs = component.libs
++ component.frameworks
++ builtins.concatLists component.pkgconfig;
++ builtins.concatLists component.pkgconfig
++ configFiles.libDeps
++ [ghc]; # Needs to be a build input so that the boot libraries are included
nativeBuildInputs = [ghc] ++ executableToolDepends;

passthru = {
Expand All @@ -69,6 +71,9 @@ let

phases = ["unpackPhase" "patchPhase" "buildPhase" "installPhase"];
buildPhase = ''
configFiles=$(mktemp -d)
mkdir -p $configFiles
${configFiles.script}
runHook preBuild
if [[ ! -f ./Setup.hs && ! -f ./Setup.lhs ]]; then
cat ${defaultSetupSrc} > Setup.hs
Expand All @@ -77,7 +82,7 @@ let
if [ -f $f ]; then
echo Compiling package $f
ghc $f -threaded ${if includeGhcPackage then "-package ghc " else ""
}-package-db ${configFiles.drv}/${configFiles.packageCfgDir} --make -o ./Setup
}-package-db $configFiles/${configFiles.packageCfgDir} --make -o ./Setup
fi
done
[ -f ./Setup ] || (echo Failed to build Setup && exit 1)
Expand Down
20 changes: 16 additions & 4 deletions lib/call-cabal-project-to-nix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ in
# any plutus-apps input being used for a
# package.
, evalPackages
, supportHpack ? false # Run hpack on package.yaml files with no .cabal file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍, although I guess this is going to break people

, ...
}@args:

Expand Down Expand Up @@ -453,7 +454,10 @@ let
} // pkgs.lib.optionalAttrs (checkMaterialization != null) {
inherit checkMaterialization;
}) (evalPackages.runCommand (nameAndSuffix "plan-to-nix-pkgs") {
nativeBuildInputs = [ nix-tools dummy-ghc dummy-ghc-pkg cabal-install evalPackages.rsync evalPackages.gitMinimal ];
nativeBuildInputs = [
nix-tools.project.hsPkgs.nix-tools.components.exes.plan-to-nix
dummy-ghc dummy-ghc-pkg cabal-install evalPackages.rsync evalPackages.gitMinimal ]
++ pkgs.lib.optional supportHpack nix-tools.project.hsPkgs.hpack.components.exes.hpack;
# Needed or stack-to-nix will die on unicode inputs
LOCALE_ARCHIVE = pkgs.lib.optionalString (evalPackages.stdenv.buildPlatform.libc == "glibc") "${evalPackages.glibcLocales}/lib/locale/locale-archive";
LANG = "en_US.UTF-8";
Expand Down Expand Up @@ -510,12 +514,20 @@ let
if [ -e "$cabalFile" ]; then
echo Ignoring $hpackFile as $cabalFile exists
else
${
# warning: this may not generate the proper cabal file.
# hpack allows globbing, and turns that into module lists
# without the source available (we cleaneSourceWith'd it),
# without the source available (we cleanSourceWith'd it),
# this may not produce the right result.
echo No .cabal file found, running hpack on $hpackFile
hpack $hpackFile
if supportHpack
then ''
echo No .cabal file found, running hpack on $hpackFile
hpack $hpackFile
''
else ''
echo WARNING $hpackFile has no .cabal file and `supportHpack` was not set.
''
}
fi
done
)
Expand Down
4 changes: 2 additions & 2 deletions overlays/bootstrap.nix
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ in {
final.buildPackages.buildPackages.gitMinimal
final.buildPackages.buildPackages.nix-prefetch-git ];
in
final.buildPackages.symlinkJoin {
(final.buildPackages.symlinkJoin {
name = "nix-tools";
paths = exes;
buildInputs = [ final.buildPackages.makeWrapper ];
Expand All @@ -992,7 +992,7 @@ in {
wrapProgram "$out/bin/$prog" --prefix PATH : "${final.lib.makeBinPath tools}"
done
'';
};
}) // { inherit project; };

# Memoize the cabal-install and nix-tools derivations by adding:
# haskell-nix.cabal-install.ghcXXX
Expand Down
2 changes: 1 addition & 1 deletion overlays/default-setup.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let
# version of Cabal bundled with GHC).
cabalFromCabalInstall = final.buildPackages.haskell-nix.cabal-install-unchecked.${compiler-nix-name}.project.hsPkgs.Cabal.components.library;

in ghc // rec {
in ghc // rec {
defaultSetup = final.lib.mapAttrs (_: useCabalFromCabalInstall: setup-builder ({
name = "${ghc.targetPrefix}default-Setup";
component = {
Expand Down
2 changes: 1 addition & 1 deletion overlays/haskell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ final: prev: {
name = "01-index.tar.gz-at-${at}";
url = "https://hackage.haskell.org/01-index.tar.gz";
downloadToTemp = true;
postFetch = "${nix-tools}/bin/truncate-index -o $out -i $downloadedFile -s ${index-state}";
postFetch = "${nix-tools.project.hsPkgs.nix-tools.components.exes.truncate-index}/bin/truncate-index -o $out -i $downloadedFile -s ${index-state}";

outputHashAlgo = "sha256";
outputHash = sha256;
Expand Down