From 8ce4ac34a4a7f91c8dd21143901e09f507c1b24f Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Mon, 30 Nov 2020 20:41:40 +0000 Subject: [PATCH 1/7] Upgrade Nix script to use the haskell-updates branch. The haskell-updates branch is already on Stackage nightly, which allows for a much better cache hit rate (assuming haskell-updates is backed by a Hydra cache, which I'm not quite sure of). --- nix/default.nix | 37 +++++++++++++ nix/sources.json | 22 ++++++-- shell.nix | 131 ++++++++++------------------------------------- 3 files changed, 80 insertions(+), 110 deletions(-) create mode 100644 nix/default.nix diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000000..ded4c02283 --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,37 @@ +{ sources ? import ./sources.nix }: +let + overlay = _self: pkgs: + let sharedOverrides = { + overrides = _self: super: { + mkDerivation = args: super.mkDerivation (args // + { + # skip running tests for Hackage packages + doCheck = args.pname != "ghcide" && args.pname != "haskell-language-server"; + # relax upper bounds + jailbreak = args.pname != "jailbreak-cabal"; + }); + }; + }; + extended = haskellPackages: + haskellPackages.extend (pkgs.haskell.lib.packageSourceOverrides { + haskell-language-server = ../.; + ghcide = ../ghcide; + hie-compat = ../ghcide/hie-compat; + hls-plugin-api = ../hls-plugin-api; + hls-tactics-plugin = ../plugins/tactics; + hls-hlint-plugin = ../plugins/hls-hlint-plugin; + }); + in + { + inherit (import sources.gitignore { inherit (pkgs) lib; }) gitignoreSource; + ourHaskell = pkgs.haskell // { + packages = pkgs.haskell.packages // { + # relax upper bounds on ghc 8.10.x versions (and skip running tests) + ghc8101 = extended (pkgs.haskell.packages.ghc8101.override sharedOverrides); + ghc8102 = extended (pkgs.haskell.packages.ghc8102.override sharedOverrides); + }; + }; + }; + +in import sources.nixpkgs +{ overlays = [ overlay ] ; config = {allowBroken = true;}; } diff --git a/nix/sources.json b/nix/sources.json index d7c27e628a..7db7eba31e 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -1,4 +1,16 @@ { + "gitignore": { + "branch": "master", + "description": "Nix function for filtering local git sources", + "homepage": "", + "owner": "hercules-ci", + "repo": "gitignore", + "rev": "c4662e662462e7bf3c2a968483478a665d00e717", + "sha256": "1npnx0h6bd0d7ql93ka7azhj40zgjp815fw2r6smg8ch9p7mzdlx", + "type": "tarball", + "url": "https://github.com/hercules-ci/gitignore/archive/c4662e662462e7bf3c2a968483478a665d00e717.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, "niv": { "branch": "master", "description": "Easy dependency management for Nix projects", @@ -12,15 +24,15 @@ "url_template": "https://github.com///archive/.tar.gz" }, "nixpkgs": { - "branch": "nixpkgs-unstable", + "branch": "haskell-updates", "description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to", "homepage": "https://github.com/NixOS/nixpkgs", "owner": "NixOS", - "repo": "nixpkgs-channels", - "rev": "a332da8588aeea4feb9359d23f58d95520899e3c", - "sha256": "18hlja5syv3xpi14c07h9lrn1cchq2azmj06fyalq52vl064nx75", + "repo": "nixpkgs", + "rev": "cbf707b2af4cd66bdcdd84b2bddfb627194b39c0", + "sha256": "1bj55jkgdzx7lv6dvy26l354c7vsxaa1jipm99axgqqax905m8sa", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs-channels/archive/a332da8588aeea4feb9359d23f58d95520899e3c.tar.gz", + "url": "https://github.com/NixOS/nixpkgs/archive/cbf707b2af4cd66bdcdd84b2bddfb627194b39c0.tar.gz", "url_template": "https://github.com///archive/.tar.gz" } } diff --git a/shell.nix b/shell.nix index ee644c46af..776302306b 100644 --- a/shell.nix +++ b/shell.nix @@ -1,125 +1,46 @@ # This shell.nix file is designed for use with cabal build -# It aims to leverage the nix cache in as much as possible -# while reducing Nix maintenance costs. -# It does **not** aim to replace Cabal/Stack with Nix +# It does **not** aim to replace Cabal # Maintaining this file: # -# - Dealing with broken nix-shell -# -# 1. Bump the nixpkgs version using `niv update nixpkgs` -# 2. Comment out any remaining failing packages -# -# - Dealing with broken cabal build inside nix-shell: -# -# If my understanding of cabal new-build is correct this should never happen, -# assuming that cabal new-build does succeed outside nix-shell +# - Bump the nixpkgs version using `niv update nixpkgs` -{ sources ? import nix/sources.nix, - nixpkgs ? import sources.nixpkgs { }, - compiler ? "default", - hoogle ? false +{ compiler ? "default", + withHoogle ? false, + nixpkgs ? import ./nix {} }: + with nixpkgs; let defaultCompiler = "ghc" + lib.replaceStrings ["."] [""] haskellPackages.ghc.version; - haskellPackagesForProject = p: - if compiler == "default" || compiler == defaultCompiler - then if hoogle - then haskellPackages.ghcWithHoogle p - else haskellPackages.ghcWithPackages p - # for all other compilers there is no Nix cache so dont bother building deps - else if hoogle - then haskell.packages.${compiler}.ghcWithHoogle (_: []) - else haskell.packages.${compiler}.ghcWithPackages (_: []); + haskellPackagesForProject = + if compiler == "default" + then ourHaskell.packages.${defaultCompiler} + else ourHaskell.packages.${compiler}; + + packages = p: [ p.haskell-language-server + p.ghcide + p.hie-compat + p.hls-plugin-api + p.hls-tactics-plugin + p.hls-hlint-plugin + ]; - retrie = with haskell.lib; dontCheck(disableLibraryProfiling(haskellPackages.retrie)); - compilerWithPackages = haskellPackagesForProject(p: - with p; - [ - Diff - Glob - HsYAML-aeson - QuickCheck - aeson - alex - async - base16-bytestring - blaze-builder - blaze-markup - brittany - conduit-extra - conduit-parse - cryptohash-sha1 - data-default - data-default-class - data-default-instances-containers - data-default-instances-dlist - data-default-instances-old-locale - extra - floskell - # fourmolu - fuzzy - generic-deriving - ghc-check - gitrev - haddock-library - happy - haskell-lsp - haskell-src-exts - hie-bios - hslogger - hspec - lens - lsp-test - megaparsec - network - opentelemetry - optparse-simple - ormolu - parser-combinators - parsers - prettyprinter - prettyprinter-ansi-terminal - primes - psqueues - regex-tdfa - retrie - rope-utf16-splay - safe-exceptions - shake - sorted-list - strict - stylish-haskell - tasty - tasty-ant-xml - tasty-expected-failure - tasty-golden - tasty-hunit - tasty-rerun - temporary - text - typed-process - unix-compat - unordered-containers - xml - yaml - zlib - ]); + isSupported = compiler == "default" || compiler == defaultCompiler; in -stdenv.mkDerivation { - name = "haskell-language-server"; +haskellPackagesForProject.shellFor { + inherit withHoogle; + doBenchmark = true; + packages = p: if isSupported then packages p else [p.ghc-paths]; buildInputs = [ - git gmp - ncurses zlib + ncurses haskellPackages.cabal-install haskellPackages.hlint - - compilerWithPackages - + haskellPackages.ormolu + haskellPackages.stylish-haskell ]; src = null; shellHook = '' From f2bdc62a922d2fe767da5cda6fd125a799595896 Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Mon, 30 Nov 2020 23:28:25 +0000 Subject: [PATCH 2/7] Delete CircleCI Nix job --- .circleci/config.yml | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f07ffb7ceb..89ddb3b5dd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -171,33 +171,6 @@ jobs: key: cabal-{{ .Environment.HIE_CACHE }}-{{ arch }}-{{ .Environment.CIRCLE_JOB }} paths: - ~/.cabal - nix: - working_directory: ~/build - environment: - - NIXPKGS_ALLOW_BROKEN: 1 - docker: - - image: nixorg/nix:circleci - steps: - - checkout - - run: - name: Sync submodules - command: git submodule sync --recursive - - run: - name: Update submodules - command: git submodule update --recursive --init - - restore-cache: - keys: - - cabal-{{ .Environment.HIE_CACHE }}-{{ arch }}-{{ .Environment.CIRCLE_JOB }} - - run: - name: Build - command: nix-shell -j4 --run "cabal new-update && (cabal new-build -j1 --enable-tests || cabal new-build -j1 --enable-tests) " - no_output_timeout: 30m - - save_cache: - key: cabal-{{ .Environment.HIE_CACHE }}-{{ arch }}-{{ .Environment.CIRCLE_JOB }} - paths: - - ~/.cabal - - workflows: version: 2 @@ -212,4 +185,3 @@ workflows: - ghc-8.10.2 # - ghc-nightly - cabal - - nix From b2d144911cb5d7a952a53caa3e75383648336306 Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Mon, 30 Nov 2020 20:48:54 +0000 Subject: [PATCH 3/7] Add a Github action to warm up the Cachix haskell-language-server --- .github/workflows/nix.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/nix.yml diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml new file mode 100644 index 0000000000..48de2c13a2 --- /dev/null +++ b/.github/workflows/nix.yml @@ -0,0 +1,26 @@ +name: Nix + +on: [push, pull_request] +jobs: + nix: + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + ghc: ['default', 'ghc8102', 'ghc884', 'ghc865'] + os: [ubuntu-latest, macOS-latest] + + steps: + - uses: actions/checkout@v2 + with: + submodules: true + - uses: cachix/install-nix-action@v12 + with: + nix_path: nixpkgs=channel:nixos-20.03 + - uses: cachix/cachix-action@v7 + with: + name: haskell-language-server + extraPullNames: haskell-ghcide + authToken: '${{ secrets.HLS_CACHIX_AUTH_TOKEN }}' + - run: nix-shell --argstr compiler ${{ matrix.ghc }} --run "cabal update && cabal build" From 05e1dae7816da8628c657278ea537ac2ab0c701e Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Mon, 30 Nov 2020 23:35:52 +0000 Subject: [PATCH 4/7] Add maintainer instructions --- shell.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/shell.nix b/shell.nix index 776302306b..1792cbe0a8 100644 --- a/shell.nix +++ b/shell.nix @@ -4,6 +4,12 @@ # Maintaining this file: # # - Bump the nixpkgs version using `niv update nixpkgs` +# - To edit the set of local packages: +# 1. Declare them in nix/default.nix +# 2. Edit the list of packages below +# +# For more details: https://github.com/NixOS/nixpkgs/blob/20.03/pkgs/development/haskell-modules/make-package-set.nix#L256 + { compiler ? "default", withHoogle ? false, From 63a5db1e92974f7aef0155c590f722d79c99210f Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Mon, 30 Nov 2020 23:44:12 +0000 Subject: [PATCH 5/7] Add README instructions --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index aaadbc5464..9c0468bae6 100644 --- a/README.md +++ b/README.md @@ -701,6 +701,19 @@ $ cd install $ stack build ``` +#### Using Nix + +The instructions below show how to set up a Cachix binary cache and open a nix shell for local development. + +```shell +$ cachix use haskell-language-server +$ nix-shell +$ cabal update +$ cabal build +``` + +If you are looking for a Nix expression to create haskell-language-server binaries, seehttps://github.com/haskell/haskell-language-server/issues/122 + #### Introduction tutorial Pepeiborra [wrote an tutorial](https://github.com/pepeiborra/hls-tutorial) on writing a plugin in HLS. From 46d1c7654c88c0f761647dcf21e9557f41d972f7 Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Tue, 1 Dec 2020 10:33:49 +0000 Subject: [PATCH 6/7] Upgrade to cachix-action@v8 Adds support for auth tokens --- .github/workflows/nix.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index 48de2c13a2..9ea6f0042a 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -18,7 +18,7 @@ jobs: - uses: cachix/install-nix-action@v12 with: nix_path: nixpkgs=channel:nixos-20.03 - - uses: cachix/cachix-action@v7 + - uses: cachix/cachix-action@v8 with: name: haskell-language-server extraPullNames: haskell-ghcide From df0e329567a7e449e8c1c6fde511fcb2ce64dc57 Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Tue, 1 Dec 2020 23:17:02 +0000 Subject: [PATCH 7/7] Update README.md Co-authored-by: Javier Neira --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9c0468bae6..4bad020340 100644 --- a/README.md +++ b/README.md @@ -712,7 +712,7 @@ $ cabal update $ cabal build ``` -If you are looking for a Nix expression to create haskell-language-server binaries, seehttps://github.com/haskell/haskell-language-server/issues/122 +If you are looking for a Nix expression to create haskell-language-server binaries, see https://github.com/haskell/haskell-language-server/issues/122 #### Introduction tutorial Pepeiborra [wrote an tutorial](https://github.com/pepeiborra/hls-tutorial) on writing a plugin in HLS.