From 485e087637a69139f655570e8fdacafa452fb3d7 Mon Sep 17 00:00:00 2001 From: Guillaume Bouchard Date: Fri, 21 Jan 2022 20:08:41 +0100 Subject: [PATCH 1/2] refactor(flake): Use a separate flake for hackage sources This will be easier to update, and pass them as one dictionary. --- flake.lock | 26 ++++++++++++++++++++------ flake.nix | 23 +++++++---------------- flake_hackage/flake.nix | 20 ++++++++++++++++++++ 3 files changed, 47 insertions(+), 22 deletions(-) create mode 100644 flake_hackage/flake.nix diff --git a/flake.lock b/flake.lock index 6e1a7bcc2f..a341391f10 100644 --- a/flake.lock +++ b/flake.lock @@ -62,7 +62,23 @@ "type": "github" } }, - "lsp-source": { + "hackage-sources": { + "inputs": { + "lsp": "lsp", + "lsp-test": "lsp-test", + "lsp-types": "lsp-types" + }, + "locked": { + "narHash": "sha256-p6aOFA/SahtoQC2FLWxltQ3Fy9pXElKq0FGCgNsehSc=", + "path": "./flake_hackage", + "type": "path" + }, + "original": { + "path": "./flake_hackage", + "type": "path" + } + }, + "lsp": { "flake": false, "locked": { "narHash": "sha256-OcyNHNRh9j5nbJ8SjaNAWIEKuixAJlA7+vTimFY0c2c=", @@ -74,7 +90,7 @@ "url": "https://hackage.haskell.org/package/lsp-1.4.0.0/lsp-1.4.0.0.tar.gz" } }, - "lsp-test-source": { + "lsp-test": { "flake": false, "locked": { "narHash": "sha256-IOmbQH6tKdu9kAyirvLx6xFS2N+/tbs6vZn0mNGm3No=", @@ -86,7 +102,7 @@ "url": "https://hackage.haskell.org/package/lsp-test-0.14.0.2/lsp-test-0.14.0.2.tar.gz" } }, - "lsp-types-source": { + "lsp-types": { "flake": false, "locked": { "narHash": "sha256-K1CeV6o5mmrXubATCh19iFatJ1RtPwpY5lxD8rf/SIw=", @@ -152,9 +168,7 @@ "flake-compat": "flake-compat", "flake-utils": "flake-utils", "gitignore": "gitignore", - "lsp-source": "lsp-source", - "lsp-test-source": "lsp-test-source", - "lsp-types-source": "lsp-types-source", + "hackage-sources": "hackage-sources", "nixpkgs": "nixpkgs", "pre-commit-hooks": "pre-commit-hooks" } diff --git a/flake.nix b/flake.nix index 2a4c220f69..d0c5144edf 100644 --- a/flake.nix +++ b/flake.nix @@ -22,25 +22,16 @@ flake = false; }; - lsp-source = { - url = "https://hackage.haskell.org/package/lsp-1.4.0.0/lsp-1.4.0.0.tar.gz"; - flake = false; - }; - lsp-types-source = { - url = "https://hackage.haskell.org/package/lsp-types-1.4.0.0/lsp-types-1.4.0.0.tar.gz"; - flake = false; - }; - lsp-test-source = { - url = "https://hackage.haskell.org/package/lsp-test-0.14.0.2/lsp-test-0.14.0.2.tar.gz"; - flake = false; - }; + hackage-sources.url = "path:./flake_hackage"; }; outputs = - { self, nixpkgs, flake-compat, flake-utils, pre-commit-hooks, gitignore, lsp-source, lsp-types-source, lsp-test-source }: + { self, nixpkgs, flake-compat, flake-utils, pre-commit-hooks, gitignore, hackage-sources }: { overlay = final: prev: with prev; let + hackage = hackage-sources.inputs; + haskellOverrides = hself: hsuper: { # we override mkDerivation here to apply the following # tweak to each haskell package: @@ -88,9 +79,9 @@ # We need an older version hiedb = hself.hiedb_0_4_1_0; - lsp = hsuper.callCabal2nix "lsp" lsp-source {}; - lsp-types = hsuper.callCabal2nix "lsp-types" lsp-types-source {}; - lsp-test = hsuper.callCabal2nix "lsp-test" lsp-test-source {}; + lsp = hsuper.callCabal2nix "lsp" hackage.lsp {}; + lsp-types = hsuper.callCabal2nix "lsp-types" hackage.lsp-types {}; + lsp-test = hsuper.callCabal2nix "lsp-test" hackage.lsp-test {}; implicit-hie-cradle = hself.callCabal2nix "implicit-hie-cradle" (builtins.fetchTarball { diff --git a/flake_hackage/flake.nix b/flake_hackage/flake.nix new file mode 100644 index 0000000000..61b0feddc1 --- /dev/null +++ b/flake_hackage/flake.nix @@ -0,0 +1,20 @@ +{ + description = "Sources from hackage"; + + inputs = { + lsp = { + url = "https://hackage.haskell.org/package/lsp-1.4.0.0/lsp-1.4.0.0.tar.gz"; + flake = false; + }; + lsp-types = { + url = "https://hackage.haskell.org/package/lsp-types-1.4.0.0/lsp-types-1.4.0.0.tar.gz"; + flake = false; + }; + lsp-test = { + url = "https://hackage.haskell.org/package/lsp-test-0.14.0.2/lsp-test-0.14.0.2.tar.gz"; + flake = false; + }; + }; + + outputs = {self, ...}: {}; +} From 65f88dd1e072df9fc65c11864d9a9b422ce5c452 Mon Sep 17 00:00:00 2001 From: Guillaume Bouchard Date: Fri, 21 Jan 2022 20:30:26 +0100 Subject: [PATCH 2/2] flake: support for GHC 9.2 I've naively copied most of the special cases for `GHC 9.0.1`. - `nix develop .\#haskell-language-server-921` gives me a shell in which I'm able to `cabal build` - `nix build .#haskell-language-server-921` builds HLS binary. I was able to use it in a proprietary codebase (by importing the flake) and it works fine. - some plugins are disabled, `brittany`, `stylishhaskell`, `hlint`, `haddockComments`, `alternateNumberFormat`. I didn't fight too much to fix this because I'm not using them. I'll do an effort in the future to fix them. - `nix develop .\#haskell-language-server-921-dev` does not starts, I need to investigate. --- configuration-ghc-921.nix | 42 ++++++++++++++++++++++++ flake.lock | 69 +++++++++++++++++++++++++++++++++++++-- flake.nix | 7 ++++ flake_hackage/flake.nix | 24 ++++++++++++++ 4 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 configuration-ghc-921.nix diff --git a/configuration-ghc-921.nix b/configuration-ghc-921.nix new file mode 100644 index 0000000000..05d7887698 --- /dev/null +++ b/configuration-ghc-921.nix @@ -0,0 +1,42 @@ +# nix version of cabal-ghc901.project +{ pkgs, hackage }: + +let + disabledPlugins = [ + "hls-brittany-plugin" + "hls-stylish-haskell-plugin" + ]; + + hpkgsOverride = hself: hsuper: + with pkgs.haskell.lib; + { + fourmolu = hself.callCabal2nix "fourmolu" hackage.fourmolu {}; + primitive-extras = hself.primitive-extras_0_10_1_2; + ghc-exactprint = hself.callCabal2nix "ghc-exactprint" hackage.ghc-exactprint {}; + constraints-extras = hself.callCabal2nix "constraints-extras" hackage.constraints-extras {}; + retrie = hself.callCabal2nix "retrie" hackage.retrie {}; + hlint = doJailbreak (hself.callCabal2nix "hlint" hackage.hlint {}); + + # Re-generate HLS drv excluding some plugins + haskell-language-server = + hself.callCabal2nixWithOptions "haskell-language-server" ./. + (pkgs.lib.concatStringsSep " " [ + "-f-brittany" + "-f-stylishhaskell" + "-f-hlint" + "-f-haddockComments" + "-f-alternateNumberFormat" + "-f-eval" + ]) { }; + + # YOLO + mkDerivation = args: + hsuper.mkDerivation (args // { + jailbreak = true; + doCheck = false; + }); + }; +in { + inherit disabledPlugins; + tweakHpkgs = hpkgs: hpkgs.extend hpkgsOverride; +} diff --git a/flake.lock b/flake.lock index a341391f10..dc7b690ee8 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,17 @@ { "nodes": { + "constraints-extras": { + "flake": false, + "locked": { + "narHash": "sha256-WGDSpT37RrHwpQtExGkL5eEmBk/s9b0rxtT9DYqSGg4=", + "type": "tarball", + "url": "https://hackage.haskell.org/package/constraints-extras-0.3.2.1/constraints-extras-0.3.2.1.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://hackage.haskell.org/package/constraints-extras-0.3.2.1/constraints-extras-0.3.2.1.tar.gz" + } + }, "flake-compat": { "flake": false, "locked": { @@ -46,6 +58,30 @@ "type": "github" } }, + "fourmolu": { + "flake": false, + "locked": { + "narHash": "sha256-uo5UE2SzrimnZl+JjJ30Hlg/nIw1OXJTPFIgkQopaI0=", + "type": "tarball", + "url": "https://hackage.haskell.org/package/fourmolu-0.5.0.1/fourmolu-0.5.0.1.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://hackage.haskell.org/package/fourmolu-0.5.0.1/fourmolu-0.5.0.1.tar.gz" + } + }, + "ghc-exactprint": { + "flake": false, + "locked": { + "narHash": "sha256-8OWLBQj0WYi1f91EE3d5Pq+lTjY+FQei37NEedDtKeo=", + "type": "tarball", + "url": "https://hackage.haskell.org/package/ghc-exactprint-1.4.1/ghc-exactprint-1.4.1.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://hackage.haskell.org/package/ghc-exactprint-1.4.1/ghc-exactprint-1.4.1.tar.gz" + } + }, "gitignore": { "flake": false, "locked": { @@ -64,12 +100,17 @@ }, "hackage-sources": { "inputs": { + "constraints-extras": "constraints-extras", + "fourmolu": "fourmolu", + "ghc-exactprint": "ghc-exactprint", + "hlint": "hlint", "lsp": "lsp", "lsp-test": "lsp-test", - "lsp-types": "lsp-types" + "lsp-types": "lsp-types", + "retrie": "retrie" }, "locked": { - "narHash": "sha256-p6aOFA/SahtoQC2FLWxltQ3Fy9pXElKq0FGCgNsehSc=", + "narHash": "sha256-gVzFEW0y/uPHJaGJ6w7VZc3QDhH6latvmYHJuzaXDa0=", "path": "./flake_hackage", "type": "path" }, @@ -78,6 +119,18 @@ "type": "path" } }, + "hlint": { + "flake": false, + "locked": { + "narHash": "sha256-Kz6adx97kY7ojoDlw3y0R6LQ0h/EtXGR5+N07/b6uGk=", + "type": "tarball", + "url": "https://hackage.haskell.org/package/hlint-3.3.6/hlint-3.3.6.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://hackage.haskell.org/package/hlint-3.3.6/hlint-3.3.6.tar.gz" + } + }, "lsp": { "flake": false, "locked": { @@ -163,6 +216,18 @@ "type": "github" } }, + "retrie": { + "flake": false, + "locked": { + "narHash": "sha256-SrUyFea9Qr2SYeNVDJfWZfCguJV2rHK2mO/FO4xLFaY=", + "type": "tarball", + "url": "https://hackage.haskell.org/package/retrie-1.2.0.1/retrie-1.2.0.1.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://hackage.haskell.org/package/retrie-1.2.0.1/retrie-1.2.0.1.tar.gz" + } + }, "root": { "inputs": { "flake-compat": "flake-compat", diff --git a/flake.nix b/flake.nix index d0c5144edf..916603c6b5 100644 --- a/flake.nix +++ b/flake.nix @@ -135,6 +135,7 @@ } // (flake-utils.lib.eachSystem [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ]) (system: let + hackage = hackage-sources.inputs; pkgs = import nixpkgs { inherit system; overlays = [ self.overlay ]; @@ -169,6 +170,7 @@ }; ghc901Config = (import ./configuration-ghc-901.nix) { inherit pkgs; }; + ghc921Config = (import ./configuration-ghc-921.nix) { inherit pkgs hackage; }; # GHC versions ghcDefault = pkgs.hlsHpkgs ("ghc" @@ -177,6 +179,7 @@ ghc884 = pkgs.hlsHpkgs "ghc884"; ghc8107 = pkgs.hlsHpkgs "ghc8107"; ghc901 = ghc901Config.tweakHpkgs (pkgs.hlsHpkgs "ghc901"); + ghc921 = ghc921Config.tweakHpkgs (pkgs.hlsHpkgs "ghc921"); # For markdown support myst-parser = pkgs.python3Packages.callPackage ./myst-parser.nix {}; @@ -211,6 +214,8 @@ map (name: p.${name}) (attrNames (if hpkgs.ghc.version == "9.0.1" then removeAttrs hlsSources ghc901Config.disabledPlugins + else if hpkgs.ghc.version == "9.2.1" then + removeAttrs hlsSources ghc921Config.disabledPlugins else hlsSources)); buildInputs = [ gmp zlib ncurses capstone tracy (gen-hls-changelogs hpkgs) pythonWithPackages ] @@ -253,12 +258,14 @@ haskell-language-server-884-dev = mkDevShell ghc884; haskell-language-server-8107-dev = mkDevShell ghc8107; haskell-language-server-901-dev = mkDevShell ghc901; + haskell-language-server-921-dev = mkDevShell ghc921; # hls package haskell-language-server = mkExe ghcDefault; haskell-language-server-884 = mkExe ghc884; haskell-language-server-8107 = mkExe ghc8107; haskell-language-server-901 = mkExe ghc901; + haskell-language-server-921 = mkExe ghc921; # docs docs = docs; diff --git a/flake_hackage/flake.nix b/flake_hackage/flake.nix index 61b0feddc1..3b91d2e04f 100644 --- a/flake_hackage/flake.nix +++ b/flake_hackage/flake.nix @@ -14,6 +14,30 @@ url = "https://hackage.haskell.org/package/lsp-test-0.14.0.2/lsp-test-0.14.0.2.tar.gz"; flake = false; }; + ghc-exactprint = { + url = "https://hackage.haskell.org/package/ghc-exactprint-1.4.1/ghc-exactprint-1.4.1.tar.gz"; + flake = false; + }; + + constraints-extras = { + url = "https://hackage.haskell.org/package/constraints-extras-0.3.2.1/constraints-extras-0.3.2.1.tar.gz"; + flake = false; + }; + + retrie = { + url = "https://hackage.haskell.org/package/retrie-1.2.0.1/retrie-1.2.0.1.tar.gz"; + flake = false; + }; + + fourmolu = { + url = "https://hackage.haskell.org/package/fourmolu-0.5.0.1/fourmolu-0.5.0.1.tar.gz"; + flake = false; + }; + + hlint = { + url = "https://hackage.haskell.org/package/hlint-3.3.6/hlint-3.3.6.tar.gz"; + flake = false; + }; }; outputs = {self, ...}: {};