Skip to content

Commit a026d54

Browse files
committed
Tidy
- Add CI specific treefmt config - Link devshell to .direnv - Set HLS in .vscode/config.json
1 parent 7e5b3fe commit a026d54

File tree

10 files changed

+84
-17
lines changed

10 files changed

+84
-17
lines changed

.envrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
#!/usr/bin/env bash
22
use nix
3+
4+
# Watch for changes in the following files
35
watch_file nixkell.toml
46
watch_file package.yaml
57
watch_file nix/*
68

9+
# Link the shell path (set in shell.nix) into .direnv
10+
mkdir -p "$(direnv_layout_dir)"
11+
rm -f "$(direnv_layout_dir)/shell"
12+
ln -s "$DEVSHELL_PATH" "$(direnv_layout_dir)/shell"
13+
14+
if [[ -f .envrc.private ]]; then
15+
source .envrc.private
16+
fi

.github/workflows/nix.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
if: ${{ runner.os == 'Linux' }}
6363
uses: jlumbroso/free-disk-space@main
6464

65-
- name: Set nix path
65+
- name: Set nixpkgs url
6666
id: nix-path
6767
run: |
6868
echo "nixpkgs=$(jq -r .nixpkgs.url ./nix/sources.json)" | tee -a $GITHUB_OUTPUT
@@ -74,7 +74,7 @@ jobs:
7474
extra_nix_config: |
7575
log-lines = 1000
7676
77-
- name: Install and configure Cachix
77+
- name: Install and authorise Cachix
7878
uses: cachix/cachix-action@v15
7979
with:
8080
name: nixkell
@@ -84,10 +84,10 @@ jobs:
8484
run: |
8585
nix-shell --run "echo OK"
8686
87-
- name: Check code formatting (Linux only)
87+
- name: Treefmt (Linux only)
8888
if: ${{ runner.os == 'Linux' }}
8989
run: |
90-
nix-shell --run "treefmt --fail-on-change"
90+
nix-shell --run "treefmt --ci --on-unmatched=debug --config-file treefmt-ci.toml --tree-root ."
9191
9292
- name: GHC version
9393
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.direnv
12
.ghc.environment*
23
.hie
34
cabal.project.local

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"haskell.serverExecutablePath": "haskell-language-server",
23
"nix.serverPath": "nil",
34
"nix.serverSettings": {
45
"nil": {

nix/packages.nix

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,31 @@ let
3939
"--ghc-option=-fwhole-archive-hs-libs");
4040
in lib.pipe pkg confFns;
4141

42-
hlsDisablePlugins = pkgs.lib.foldr (plugin: hls:
43-
hlib.disableCabalFlag
44-
(hls.override { ${"hls-" + plugin + "-plugin"} = null; }) plugin);
42+
# pkgs/development/haskell-modules/configuration-hackage2nix/broken.yaml
43+
unbreak = drv:
44+
drv.overrideAttrs (prev: {
45+
meta = prev.meta // { broken = false; };
46+
});
47+
48+
# By default they live in ./haskellPackages/patches
49+
patch = drv: patches:
50+
drv.overrideAttrs (prev: {
51+
patches = (prev.patches or [ ]) ++ patches;
52+
});
53+
54+
hlsDisablePlugins =
55+
pkgs.lib.foldr
56+
(plugin: hls: hlib.disableCabalFlag
57+
(hls.override (_: { ${plugin} = null; }))
58+
plugin);
4559

4660
# Create your own setup using the choosen GHC version (in the config) as a starting point
4761
ourHaskell = let
4862
# https://github.com/pwm/nixkell#direct-hackagegithub-dependencies
4963
depsFromDir = hlib.packagesFromDirectory { directory = ./packages; };
5064

5165
manual = hfinal: hprev: {
52-
cabal-install = util.patch hprev.cabal-install
66+
cabal-install = patch hprev.cabal-install
5367
[ ./patches/prevent_missing_index_error.patch ];
5468

5569
haskell-language-server = hlsDisablePlugins hprev.haskell-language-server

nix/util.nix

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,4 @@
4444
gitIgnore path type && !builtins.elem (baseNameOf path) files
4545
&& !lib.any (d: lib.hasPrefix d (relToPath path)) paths;
4646
};
47-
48-
patch = name: patches:
49-
name.overrideAttrs (prev: { patches = prev.patches or [ ] ++ patches; });
5047
}

nixkell.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ haskell_tools = [
1717
"cabal-install",
1818
"haskell-language-server",
1919
"hlint",
20-
"nixfmt",
2120
"ormolu",
2221
]
2322

2423
tools = [
2524
"cabal2nix",
2625
"nil",
2726
"niv",
27+
"nixpkgs-fmt",
2828
"shellcheck",
2929
"shfmt",
3030
"treefmt",

shell.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ let pkgs = import ./nix { inherit system compiler; };
33
in pkgs.mkShell {
44
buildInputs = [ pkgs.nixkell.shell ];
55
shellHook = ''
6-
export LD_LIBRARY_PATH=${pkgs.nixkell.shell}/lib:$LD_LIBRARY_PATH
6+
export DEVSHELL_PATH="${pkgs.nixkell.shell}"
7+
export LD_LIBRARY_PATH="${pkgs.nixkell.shell}/lib$${LD_LIBRARY_PATH:+:$$LD_LIBRARY_PATH}"
78
logo
89
'';
910
}

treefmt-ci.toml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# One CLI to format the code tree - https://github.com/numtide/treefmt
2+
3+
[formatter.haskell]
4+
command = "ormolu"
5+
includes = ["*.hs"]
6+
options = [
7+
"--mode", "check",
8+
"--check-idempotence",
9+
]
10+
11+
[formatter.nix]
12+
command = "nixpkgs-fmt"
13+
includes = ["*.nix"]
14+
excludes = [
15+
"nix/packages/*.nix",
16+
"nix/sources.nix",
17+
]
18+
options = [
19+
"--check",
20+
]
21+
22+
[formatter.shell]
23+
command = "shfmt"
24+
includes = ["*.sh"]
25+
options = [
26+
"--indent", "2",
27+
"--simplify",
28+
"--diff",
29+
]
30+
31+
[formatter.prettier]
32+
command = "prettier"
33+
includes = [
34+
"*.json",
35+
"*.md",
36+
"*.yaml",
37+
]
38+
options = [
39+
"--list-different"
40+
]
41+
excludes = [
42+
"nix/sources.json",
43+
]

treefmt.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
[formatter.haskell]
44
command = "ormolu"
5+
includes = ["*.hs"]
56
options = [
67
"--mode", "inplace",
7-
"--check-idempotence"
8+
"--check-idempotence",
89
]
9-
includes = ["*.hs"]
1010

1111
[formatter.nix]
12-
command = "nixfmt"
12+
command = "nixpkgs-fmt"
1313
includes = ["*.nix"]
1414
excludes = [
1515
"nix/packages/*.nix",
@@ -18,9 +18,9 @@ excludes = [
1818

1919
[formatter.shell]
2020
command = "shfmt"
21+
includes = ["*.sh"]
2122
options = [
2223
"--indent", "2",
2324
"--simplify",
2425
"--write",
2526
]
26-
includes = ["*.sh"]

0 commit comments

Comments
 (0)