From 4f407ed2d4cbb3186877c24a7a60bfb1730b75c7 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Thu, 2 Feb 2023 16:49:31 +0800 Subject: [PATCH 1/3] First attempt --- builder/comp-builder.nix | 2 +- builder/hspkg-builder.nix | 4 --- lib/call-cabal-project-to-nix.nix | 3 --- overlays/ghc-packages.nix | 2 +- test/with-nixpkgs-ghc/default.nix | 38 +++++++++++++++++++++++++++++ test/with-nixpkgs-ghc/empty/.almost | 0 6 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 test/with-nixpkgs-ghc/default.nix create mode 100644 test/with-nixpkgs-ghc/empty/.almost diff --git a/builder/comp-builder.nix b/builder/comp-builder.nix index 7092a8b8e7..bcca8c11a0 100644 --- a/builder/comp-builder.nix +++ b/builder/comp-builder.nix @@ -82,7 +82,7 @@ let self = , enableTSanRTS ? false # LLVM -, useLLVM ? ghc.useLLVM +, useLLVM ? false , smallAddressSpace ? false }@drvArgs: diff --git a/builder/hspkg-builder.nix b/builder/hspkg-builder.nix index dd99d061b6..a0de9d127c 100644 --- a/builder/hspkg-builder.nix +++ b/builder/hspkg-builder.nix @@ -18,10 +18,6 @@ config: , ... }@pkg: -assert (if ghc.isHaskellNixCompiler or false then true - else throw ("It is likely you used `haskell.compiler.X` instead of `haskell-nix.compiler.X`" - + pkgs.lib.optionalString (name != null) (" for " + name))); - let # Some packages bundled with GHC are not the same as they are in hackage. bundledSrc = { diff --git a/lib/call-cabal-project-to-nix.nix b/lib/call-cabal-project-to-nix.nix index bc0f5c3577..ecaf102428 100644 --- a/lib/call-cabal-project-to-nix.nix +++ b/lib/call-cabal-project-to-nix.nix @@ -107,9 +107,6 @@ let pkgs.haskell-nix.compiler."${compiler-nix-name}"; in - assert (if ghc'.isHaskellNixCompiler or false then true - else throw ("It is likely you used `haskell.compiler.X` instead of `haskell-nix.compiler.X`" - + forName)); let ghc = ghc'; diff --git a/overlays/ghc-packages.nix b/overlays/ghc-packages.nix index 0a8870d287..99d39b72d2 100644 --- a/overlays/ghc-packages.nix +++ b/overlays/ghc-packages.nix @@ -163,7 +163,7 @@ in rec { inherit subDir; includeSiblings = true; } - else "${ghc.passthru.configured-src}/${subDir}"; + else "${ghc.configured-src}/${subDir}"; nix = callCabal2Nix ghcName "${ghcName}-${pkgName}" src; }) (ghc-extra-pkgs ghc.version)) final.buildPackages.haskell-nix.compiler; diff --git a/test/with-nixpkgs-ghc/default.nix b/test/with-nixpkgs-ghc/default.nix new file mode 100644 index 0000000000..84c62de04a --- /dev/null +++ b/test/with-nixpkgs-ghc/default.nix @@ -0,0 +1,38 @@ +let + + haskell-nix = import ../../default.nix { }; + nixpkgs = haskell-nix.inputs.nixpkgs.outPath; + + o2 = ( + final: prev: { + haskell-nix = prev.haskell-nix // { + compiler = prev.haskell-nix.compiler // { + ghc8107 = prev.haskell.compiler.ghc8107 // { + # Add stuff not in nixpkgs ghc + configured-src = prev.haskell-nix.compiler.ghc8107.configured-src; # Needed for reinstallableLibGhc to work + }; + }; + }; + } + ); + + pkgs = import nixpkgs { + system = __currentSystem; + inherit (haskell-nix) config; + overlays = [ + # haskell-nix.overlays.haskell + # haskell-nix.overlays.tools + haskell-nix.overlay + o2 + ]; + }; + + prj = pkgs.haskell-nix.cabalProject { + src = ./empty; + cabalProject = "extra-packages: lens"; + compiler-nix-name = "ghc8107"; + }; +in + +prj.plan-nix + diff --git a/test/with-nixpkgs-ghc/empty/.almost b/test/with-nixpkgs-ghc/empty/.almost new file mode 100644 index 0000000000..e69de29bb2 From 9085614f00a8abe453cf62dd5a7a992a58f3b782 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Sun, 5 Feb 2023 12:30:54 +0800 Subject: [PATCH 2/3] WIP --- test/with-nixpkgs-ghc/default.nix | 10 ++++------ .../empty/{.almost => almost/.gitkeep} | 0 2 files changed, 4 insertions(+), 6 deletions(-) rename test/with-nixpkgs-ghc/empty/{.almost => almost/.gitkeep} (100%) diff --git a/test/with-nixpkgs-ghc/default.nix b/test/with-nixpkgs-ghc/default.nix index 84c62de04a..cb8e884e45 100644 --- a/test/with-nixpkgs-ghc/default.nix +++ b/test/with-nixpkgs-ghc/default.nix @@ -1,3 +1,4 @@ +{ with-nixpkgs ? true }: let haskell-nix = import ../../default.nix { }; @@ -17,14 +18,12 @@ let ); pkgs = import nixpkgs { - system = __currentSystem; inherit (haskell-nix) config; overlays = [ - # haskell-nix.overlays.haskell - # haskell-nix.overlays.tools haskell-nix.overlay - o2 - ]; + ] + ++ + (if with-nixpkgs then [ o2 ] else [ ]); }; prj = pkgs.haskell-nix.cabalProject { @@ -35,4 +34,3 @@ let in prj.plan-nix - diff --git a/test/with-nixpkgs-ghc/empty/.almost b/test/with-nixpkgs-ghc/empty/almost/.gitkeep similarity index 100% rename from test/with-nixpkgs-ghc/empty/.almost rename to test/with-nixpkgs-ghc/empty/almost/.gitkeep From 99e5334b31f85a3be20ac5e6e009df19e9af9427 Mon Sep 17 00:00:00 2001 From: Andrea Bedini Date: Sun, 5 Feb 2023 20:21:46 +0800 Subject: [PATCH 3/3] WIP This seems to work. Revert a couple of unnecessary changes. --- builder/comp-builder.nix | 2 +- overlays/ghc-packages.nix | 2 +- test/with-nixpkgs-ghc/default.nix | 60 ++++++++++++++++++++++++++++--- 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/builder/comp-builder.nix b/builder/comp-builder.nix index bcca8c11a0..7092a8b8e7 100644 --- a/builder/comp-builder.nix +++ b/builder/comp-builder.nix @@ -82,7 +82,7 @@ let self = , enableTSanRTS ? false # LLVM -, useLLVM ? false +, useLLVM ? ghc.useLLVM , smallAddressSpace ? false }@drvArgs: diff --git a/overlays/ghc-packages.nix b/overlays/ghc-packages.nix index 99d39b72d2..0a8870d287 100644 --- a/overlays/ghc-packages.nix +++ b/overlays/ghc-packages.nix @@ -163,7 +163,7 @@ in rec { inherit subDir; includeSiblings = true; } - else "${ghc.configured-src}/${subDir}"; + else "${ghc.passthru.configured-src}/${subDir}"; nix = callCabal2Nix ghcName "${ghcName}-${pkgName}" src; }) (ghc-extra-pkgs ghc.version)) final.buildPackages.haskell-nix.compiler; diff --git a/test/with-nixpkgs-ghc/default.nix b/test/with-nixpkgs-ghc/default.nix index cb8e884e45..401dfb0084 100644 --- a/test/with-nixpkgs-ghc/default.nix +++ b/test/with-nixpkgs-ghc/default.nix @@ -4,14 +4,63 @@ let haskell-nix = import ../../default.nix { }; nixpkgs = haskell-nix.inputs.nixpkgs.outPath; + fix = final: prev: compiler-nix-name: + let + haskell-nix-ghc = prev.haskell-nix.compiler.${compiler-nix-name}; + nixpkgs-ghc = prev.haskell.compiler.${compiler-nix-name}; + + exactDepOut = + pkgs.runCommand "${nixpkgs-ghc.name}-exactDeps" { } + '' + mkdir -p $out + ${nixpkgs-ghc}/bin/ghc-pkg --version + for P in $(${nixpkgs-ghc}/bin/ghc-pkg list --simple-output | sed 's/-[0-9][0-9.]*//g'); do + mkdir -p $out/exactDeps/$P + touch $out/exactDeps/$P/configure-flags + touch $out/exactDeps/$P/cabal.config + + if id=$(${nixpkgs-ghc}/bin/ghc-pkg field $P id --simple-output); then + echo "--dependency=$P=$id" >> $out/exactDeps/$P/configure-flags + elif id=$(${nixpkgs-ghc}/bin/ghc-pkg field "z-$P-z-*" id --simple-output); then + name=$(${nixpkgs-ghc}/bin/ghc-pkg 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/exactDeps/$P/configure-flags + fi + if ver=$(${nixpkgs-ghc}/bin/ghc-pkg field $P version --simple-output); then + echo "constraint: $P == $ver" >> $out/exactDeps/$P/cabal.config + echo "constraint: $P installed" >> $out/exactDeps/$P/cabal.config + fi + done + + mkdir -p $out/evalDeps + for P in $(${nixpkgs-ghc}/bin/ghc-pkg list --simple-output | sed 's/-[0-9][0-9.]*//g'); do + touch $out/evalDeps/$P + if id=$(${nixpkgs-ghc}/bin/ghc-pkg field $P id --simple-output); then + echo "package-id $id" >> $out/evalDeps/$P + fi + done + ''; + in + pkgs.symlinkJoin { + paths = [ nixpkgs-ghc exactDepOut ]; + + name = "${nixpkgs-ghc.name}-with-evalDeps"; + inherit (nixpkgs-ghc) version; + + # BLAH + inherit (haskell-nix-ghc) passthru; + # enableShared = true; + # targetPrefix = ""; + # passthru.configured-src = haskell-nix-ghc.passthru.configured-src; + # useLLVM = false; + }; + o2 = ( final: prev: { haskell-nix = prev.haskell-nix // { compiler = prev.haskell-nix.compiler // { - ghc8107 = prev.haskell.compiler.ghc8107 // { - # Add stuff not in nixpkgs ghc - configured-src = prev.haskell-nix.compiler.ghc8107.configured-src; # Needed for reinstallableLibGhc to work - }; + ghc8107 = fix final prev "ghc8107"; }; }; } @@ -23,7 +72,8 @@ let haskell-nix.overlay ] ++ - (if with-nixpkgs then [ o2 ] else [ ]); + (if with-nixpkgs then [ o2 ] else [ ]) + ; }; prj = pkgs.haskell-nix.cabalProject {