Skip to content

Commit 3717653

Browse files
authored
Merge pull request #639 from pepeiborra/Cachix
Upgrade the Nix build system
2 parents 3bd2338 + df0e329 commit 3717653

File tree

6 files changed

+124
-137
lines changed

6 files changed

+124
-137
lines changed

.circleci/config.yml

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -171,33 +171,6 @@ jobs:
171171
key: cabal-{{ .Environment.HIE_CACHE }}-{{ arch }}-{{ .Environment.CIRCLE_JOB }}
172172
paths:
173173
- ~/.cabal
174-
nix:
175-
working_directory: ~/build
176-
environment:
177-
- NIXPKGS_ALLOW_BROKEN: 1
178-
docker:
179-
- image: nixorg/nix:circleci
180-
steps:
181-
- checkout
182-
- run:
183-
name: Sync submodules
184-
command: git submodule sync --recursive
185-
- run:
186-
name: Update submodules
187-
command: git submodule update --recursive --init
188-
- restore-cache:
189-
keys:
190-
- cabal-{{ .Environment.HIE_CACHE }}-{{ arch }}-{{ .Environment.CIRCLE_JOB }}
191-
- run:
192-
name: Build
193-
command: nix-shell -j4 --run "cabal new-update && (cabal new-build -j1 --enable-tests || cabal new-build -j1 --enable-tests) "
194-
no_output_timeout: 30m
195-
- save_cache:
196-
key: cabal-{{ .Environment.HIE_CACHE }}-{{ arch }}-{{ .Environment.CIRCLE_JOB }}
197-
paths:
198-
- ~/.cabal
199-
200-
201174

202175
workflows:
203176
version: 2
@@ -212,4 +185,3 @@ workflows:
212185
- ghc-8.10.2
213186
# - ghc-nightly
214187
- cabal
215-
- nix

.github/workflows/nix.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Nix
2+
3+
on: [push, pull_request]
4+
jobs:
5+
nix:
6+
runs-on: ${{ matrix.os }}
7+
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
ghc: ['default', 'ghc8102', 'ghc884', 'ghc865']
12+
os: [ubuntu-latest, macOS-latest]
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
with:
17+
submodules: true
18+
- uses: cachix/install-nix-action@v12
19+
with:
20+
nix_path: nixpkgs=channel:nixos-20.03
21+
- uses: cachix/cachix-action@v8
22+
with:
23+
name: haskell-language-server
24+
extraPullNames: haskell-ghcide
25+
authToken: '${{ secrets.HLS_CACHIX_AUTH_TOKEN }}'
26+
- run: nix-shell --argstr compiler ${{ matrix.ghc }} --run "cabal update && cabal build"

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,19 @@ $ cd install
700700
$ stack build
701701
```
702702

703+
#### Using Nix
704+
705+
The instructions below show how to set up a Cachix binary cache and open a nix shell for local development.
706+
707+
```shell
708+
$ cachix use haskell-language-server
709+
$ nix-shell
710+
$ cabal update
711+
$ cabal build
712+
```
713+
714+
If you are looking for a Nix expression to create haskell-language-server binaries, see https://github.com/haskell/haskell-language-server/issues/122
715+
703716
#### Introduction tutorial
704717
Pepeiborra [wrote an tutorial](https://github.com/pepeiborra/hls-tutorial) on writing a plugin in HLS.
705718

nix/default.nix

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{ sources ? import ./sources.nix }:
2+
let
3+
overlay = _self: pkgs:
4+
let sharedOverrides = {
5+
overrides = _self: super: {
6+
mkDerivation = args: super.mkDerivation (args //
7+
{
8+
# skip running tests for Hackage packages
9+
doCheck = args.pname != "ghcide" && args.pname != "haskell-language-server";
10+
# relax upper bounds
11+
jailbreak = args.pname != "jailbreak-cabal";
12+
});
13+
};
14+
};
15+
extended = haskellPackages:
16+
haskellPackages.extend (pkgs.haskell.lib.packageSourceOverrides {
17+
haskell-language-server = ../.;
18+
ghcide = ../ghcide;
19+
hie-compat = ../ghcide/hie-compat;
20+
hls-plugin-api = ../hls-plugin-api;
21+
hls-tactics-plugin = ../plugins/tactics;
22+
hls-hlint-plugin = ../plugins/hls-hlint-plugin;
23+
});
24+
in
25+
{
26+
inherit (import sources.gitignore { inherit (pkgs) lib; }) gitignoreSource;
27+
ourHaskell = pkgs.haskell // {
28+
packages = pkgs.haskell.packages // {
29+
# relax upper bounds on ghc 8.10.x versions (and skip running tests)
30+
ghc8101 = extended (pkgs.haskell.packages.ghc8101.override sharedOverrides);
31+
ghc8102 = extended (pkgs.haskell.packages.ghc8102.override sharedOverrides);
32+
};
33+
};
34+
};
35+
36+
in import sources.nixpkgs
37+
{ overlays = [ overlay ] ; config = {allowBroken = true;}; }

nix/sources.json

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
{
2+
"gitignore": {
3+
"branch": "master",
4+
"description": "Nix function for filtering local git sources",
5+
"homepage": "",
6+
"owner": "hercules-ci",
7+
"repo": "gitignore",
8+
"rev": "c4662e662462e7bf3c2a968483478a665d00e717",
9+
"sha256": "1npnx0h6bd0d7ql93ka7azhj40zgjp815fw2r6smg8ch9p7mzdlx",
10+
"type": "tarball",
11+
"url": "https://github.com/hercules-ci/gitignore/archive/c4662e662462e7bf3c2a968483478a665d00e717.tar.gz",
12+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
13+
},
214
"niv": {
315
"branch": "master",
416
"description": "Easy dependency management for Nix projects",
@@ -12,15 +24,15 @@
1224
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
1325
},
1426
"nixpkgs": {
15-
"branch": "nixpkgs-unstable",
27+
"branch": "haskell-updates",
1628
"description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to",
1729
"homepage": "https://github.com/NixOS/nixpkgs",
1830
"owner": "NixOS",
19-
"repo": "nixpkgs-channels",
20-
"rev": "a332da8588aeea4feb9359d23f58d95520899e3c",
21-
"sha256": "18hlja5syv3xpi14c07h9lrn1cchq2azmj06fyalq52vl064nx75",
31+
"repo": "nixpkgs",
32+
"rev": "cbf707b2af4cd66bdcdd84b2bddfb627194b39c0",
33+
"sha256": "1bj55jkgdzx7lv6dvy26l354c7vsxaa1jipm99axgqqax905m8sa",
2234
"type": "tarball",
23-
"url": "https://github.com/NixOS/nixpkgs-channels/archive/a332da8588aeea4feb9359d23f58d95520899e3c.tar.gz",
35+
"url": "https://github.com/NixOS/nixpkgs/archive/cbf707b2af4cd66bdcdd84b2bddfb627194b39c0.tar.gz",
2436
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
2537
}
2638
}

shell.nix

Lines changed: 31 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,52 @@
11
# This shell.nix file is designed for use with cabal build
2-
# It aims to leverage the nix cache in as much as possible
3-
# while reducing Nix maintenance costs.
4-
# It does **not** aim to replace Cabal/Stack with Nix
2+
# It does **not** aim to replace Cabal
53

64
# Maintaining this file:
75
#
8-
# - Dealing with broken nix-shell
6+
# - Bump the nixpkgs version using `niv update nixpkgs`
7+
# - To edit the set of local packages:
8+
# 1. Declare them in nix/default.nix
9+
# 2. Edit the list of packages below
910
#
10-
# 1. Bump the nixpkgs version using `niv update nixpkgs`
11-
# 2. Comment out any remaining failing packages
12-
#
13-
# - Dealing with broken cabal build inside nix-shell:
14-
#
15-
# If my understanding of cabal new-build is correct this should never happen,
16-
# assuming that cabal new-build does succeed outside nix-shell
11+
# For more details: https://github.com/NixOS/nixpkgs/blob/20.03/pkgs/development/haskell-modules/make-package-set.nix#L256
12+
1713

18-
{ sources ? import nix/sources.nix,
19-
nixpkgs ? import sources.nixpkgs { },
20-
compiler ? "default",
21-
hoogle ? false
14+
{ compiler ? "default",
15+
withHoogle ? false,
16+
nixpkgs ? import ./nix {}
2217
}:
18+
2319
with nixpkgs;
2420

2521
let defaultCompiler = "ghc" + lib.replaceStrings ["."] [""] haskellPackages.ghc.version;
26-
haskellPackagesForProject = p:
27-
if compiler == "default" || compiler == defaultCompiler
28-
then if hoogle
29-
then haskellPackages.ghcWithHoogle p
30-
else haskellPackages.ghcWithPackages p
31-
# for all other compilers there is no Nix cache so dont bother building deps
32-
else if hoogle
33-
then haskell.packages.${compiler}.ghcWithHoogle (_: [])
34-
else haskell.packages.${compiler}.ghcWithPackages (_: []);
22+
haskellPackagesForProject =
23+
if compiler == "default"
24+
then ourHaskell.packages.${defaultCompiler}
25+
else ourHaskell.packages.${compiler};
26+
27+
packages = p: [ p.haskell-language-server
28+
p.ghcide
29+
p.hie-compat
30+
p.hls-plugin-api
31+
p.hls-tactics-plugin
32+
p.hls-hlint-plugin
33+
];
3534

36-
retrie = with haskell.lib; dontCheck(disableLibraryProfiling(haskellPackages.retrie));
37-
compilerWithPackages = haskellPackagesForProject(p:
38-
with p;
39-
[
40-
Diff
41-
Glob
42-
HsYAML-aeson
43-
QuickCheck
44-
aeson
45-
alex
46-
async
47-
base16-bytestring
48-
blaze-builder
49-
blaze-markup
50-
brittany
51-
conduit-extra
52-
conduit-parse
53-
cryptohash-sha1
54-
data-default
55-
data-default-class
56-
data-default-instances-containers
57-
data-default-instances-dlist
58-
data-default-instances-old-locale
59-
extra
60-
floskell
61-
# fourmolu
62-
fuzzy
63-
generic-deriving
64-
ghc-check
65-
gitrev
66-
haddock-library
67-
happy
68-
haskell-lsp
69-
haskell-src-exts
70-
hie-bios
71-
hslogger
72-
hspec
73-
lens
74-
lsp-test
75-
megaparsec
76-
network
77-
opentelemetry
78-
optparse-simple
79-
ormolu
80-
parser-combinators
81-
parsers
82-
prettyprinter
83-
prettyprinter-ansi-terminal
84-
primes
85-
psqueues
86-
regex-tdfa
87-
retrie
88-
rope-utf16-splay
89-
safe-exceptions
90-
shake
91-
sorted-list
92-
strict
93-
stylish-haskell
94-
tasty
95-
tasty-ant-xml
96-
tasty-expected-failure
97-
tasty-golden
98-
tasty-hunit
99-
tasty-rerun
100-
temporary
101-
text
102-
typed-process
103-
unix-compat
104-
unordered-containers
105-
xml
106-
yaml
107-
zlib
108-
]);
35+
isSupported = compiler == "default" || compiler == defaultCompiler;
10936
in
110-
stdenv.mkDerivation {
111-
name = "haskell-language-server";
37+
haskellPackagesForProject.shellFor {
38+
inherit withHoogle;
39+
doBenchmark = true;
40+
packages = p: if isSupported then packages p else [p.ghc-paths];
11241
buildInputs = [
113-
git
11442
gmp
115-
ncurses
11643
zlib
44+
ncurses
11745

11846
haskellPackages.cabal-install
11947
haskellPackages.hlint
120-
121-
compilerWithPackages
122-
48+
haskellPackages.ormolu
49+
haskellPackages.stylish-haskell
12350
];
12451
src = null;
12552
shellHook = ''

0 commit comments

Comments
 (0)