From 8fb3adb740a786c426fcb7b180951c5fd4083aa1 Mon Sep 17 00:00:00 2001 From: Sven Tennie Date: Fri, 24 Feb 2023 14:36:21 +0100 Subject: [PATCH] Squashed commit of the following: commit a9d9ac238fec0c878b00b11eb293a7631a91d436 Merge: 80f2ab3 c686098 Author: Gabriella Gonzalez Date: Tue Feb 21 16:36:19 2023 -0800 Merge branch 'master' into gabriella/fix_build commit 80f2ab33bd725a3867c2193271321b416be5a817 Author: Gabriella Gonzalez Date: Fri Feb 10 10:29:37 2023 -0800 Fix hash commit 46dc419f53c3f2e1930b9f5c84bd0475ea1ee585 Merge: 2d2b8e8 84e4f9c Author: Gabriella Gonzalez Date: Fri Feb 10 10:04:33 2023 -0800 Merge branch 'master' into gabriella/fix_build commit 2d2b8e8e8df7078b4695677304df258095076f68 Author: Gabriella Gonzalez Date: Thu Feb 2 12:50:40 2023 -0800 Fix build failures on `aarch64-darwin` The main change here is enabling the separate `bin` output for `ormolu`, which is currently necessary to get HLS working on `aarch64-darwin`. See: https://github.com/NixOS/nixpkgs/issues/140774#issuecomment-1365283244 Adding in the overlay to fix that entailed some surgery to `ghc.nix` and `flake.nix`, but I tried my best to make it as unintrusive as possible. --- flake.lock | 6 +++--- flake.nix | 8 ++------ ghc.nix | 60 +++++++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 53 insertions(+), 21 deletions(-) diff --git a/flake.lock b/flake.lock index 8728c1c..f1c5d9e 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "all-cabal-hashes": { "flake": false, "locked": { - "lastModified": 1669117019, - "narHash": "sha256-qZc9NDRdThtS/lTd/9PgBvQML2MOgcsKNek8pEichwc=", + "lastModified": 1675288170, + "narHash": "sha256-7vtAf3PkiC3tbnuTojrgsdqMSkeip9fiUOXEwMyParw=", "owner": "commercialhaskell", "repo": "all-cabal-hashes", - "rev": "f79fc30696a89734d6314f48ab53479fa3d974d1", + "rev": "e55a65f8e5361aa2f45610b7dafc350731cb7455", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index c33279b..bea1347 100644 --- a/flake.nix +++ b/flake.nix @@ -18,14 +18,10 @@ outputs = { self, nixpkgs, nixpkgs-unstable, all-cabal-hashes, ... }: with nixpkgs.lib; let supportedSystems = systems.flakeExposed; perSystem = genAttrs supportedSystems; - pkgsFor = system: import nixpkgs { inherit system; }; - unstablePkgsFor = system: import nixpkgs-unstable { inherit system; }; defaultSettings = system: { - inherit system; + inherit nixpkgs nixpkgs-unstable system; all-cabal-hashes = all-cabal-hashes.outPath; - nixpkgs = pkgsFor system; - nixpkgs-unstable = unstablePkgsFor system; }; # NOTE: change this according to the settings allowed in the ./ghc.nix file and described @@ -40,7 +36,7 @@ ghc-nix = import ./ghc.nix (defaultSettings system // userSettings); default = ghc-nix; }); - formatter = perSystem (system: (pkgsFor system).nixpkgs-fmt); + formatter = perSystem (system: (import nixpkgs { inherit system; }).nixpkgs-fmt); # NOTE: this attribute is used by the flake-compat code to allow passing arguments to ./ghc.nix legacy = args: import ./ghc.nix (defaultSettings args.system // args); diff --git a/ghc.nix b/ghc.nix index 70a286c..17bb5b9 100644 --- a/ghc.nix +++ b/ghc.nix @@ -4,6 +4,12 @@ # nix-shell path/to/ghc.nix/ --run 'hadrian/build -c -j4 --flavour=quickest' # nix-shell path/to/ghc.nix/ --run 'THREADS=4 ./validate --slow' # +let + pkgsFor = nixpkgs: system: + import nixpkgs { inherit system; overlays = [ ]; config = { }; }; + +in + { system ? builtins.currentSystem , nixpkgs , nixpkgs-unstable @@ -17,14 +23,44 @@ , withGhcid ? false , withIde ? false , withHadrianDeps ? false -, withDwarf ? nixpkgs.stdenv.isLinux # enable libdw unwinding support -, withNuma ? nixpkgs.stdenv.isLinux -, withDtrace ? nixpkgs.stdenv.isLinux -, withGrind ? !(nixpkgs.valgrind.meta.broken or false) +, withDwarf ? (pkgsFor nixpkgs system).stdenv.isLinux # enable libdw unwinding support +, withNuma ? (pkgsFor nixpkgs system).stdenv.isLinux +, withDtrace ? (pkgsFor nixpkgs system).stdenv.isLinux +, withGrind ? !((pkgsFor nixpkgs system).valgrind.meta.broken or false) , withEMSDK ? false # load emscripten for js-backend }: -with nixpkgs; +let + overlay = self: super: { + haskell = super.haskell // { + packages = super.haskell.packages // { + ${bootghc} = super.haskell.packages.${bootghc}.override (old: { + inherit all-cabal-hashes; + overrides = + self.lib.composeExtensions + (old.overrides or (_: _: {})) + (hself: hsuper: { + ormolu = + if self.system == "aarch64-darwin" + then + self.haskell.lib.overrideCabal + hsuper.ormolu + (_: { enableSeparateBinOutput = false; }) + else + hsuper.ormolu; + }); + }); + }; + }; + }; + + pkgs = import nixpkgs { inherit system; overlays = [ overlay ]; }; + + pkgs-unstable = + import nixpkgs-unstable { inherit system; overlays = [ overlay ]; }; +in + +with pkgs; let llvmForGhc = @@ -34,8 +70,8 @@ let stdenv = if useClang - then nixpkgs.clangStdenv - else nixpkgs.stdenv; + then pkgs.clangStdenv + else pkgs.stdenv; noTest = pkg: haskell.lib.dontCheck pkg; hspkgs = haskell.packages.${bootghc}.override { @@ -45,12 +81,12 @@ let ghc = haskell.compiler.${bootghc}; ourtexlive = - nixpkgs.texlive.combine { - inherit (nixpkgs.texlive) + pkgs.texlive.combine { + inherit (pkgs.texlive) scheme-medium collection-xetex fncychap titlesec tabulary varwidth framed capt-of wrapfig needspace dejavu-otf helvetic upquote; }; - fonts = nixpkgs.makeFontsConf { fontDirectories = [ nixpkgs.dejavu_fonts ]; }; + fonts = pkgs.makeFontsConf { fontDirectories = [ pkgs.dejavu_fonts ]; }; docsPackages = if withDocs then [ python3Packages.sphinx ourtexlive ] else [ ]; depsSystem = with lib; ( @@ -81,8 +117,8 @@ let ++ optional withNuma numactl ++ optional withDwarf elfutils ++ optional withGhcid ghcid - ++ optional withIde (nixpkgs-unstable.haskell-language-server.override { supportedGhcVersions = [ (builtins.replaceStrings [ "." ] [ "" ] ghc.version) ]; }) - ++ optional withIde nixpkgs-unstable.clang-tools # N.B. clang-tools for clangd + ++ optional withIde (pkgs-unstable.haskell-language-server.override { supportedGhcVersions = [ (builtins.replaceStrings [ "." ] [ "" ] ghc.version) ]; }) + ++ optional withIde pkgs-unstable.clang-tools # N.B. clang-tools for clangd ++ optional withDtrace linuxPackages.systemtap ++ (if (! stdenv.isDarwin) then [ pxz ]