Skip to content

Commit 7dd8837

Browse files
committed
Flakify
1 parent f04f481 commit 7dd8837

13 files changed

Lines changed: 179 additions & 310 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,26 @@ jobs:
2424
~/.cabal/packages
2525
~/.cabal/store
2626
dist-newstyle
27-
key: cabal-deps-${{ runner.os }}-${{ hashFiles('nix/sources.json') }}-${{ matrix.ghc-version }}-v${{ env.cache-invalidation-key }}-${{ hashFiles('linear-base.cabal') }}-${{ github.sha }}
28-
restore-keys: cabal-deps-${{ runner.os }}-${{ hashFiles('nix/sources.json') }}-${{ matrix.ghc-version }}-v${{ env.cache-invalidation-key }}-${{ hashFiles('linear-base.cabal') }}-
27+
key: cabal-deps-${{ runner.os }}-${{ hashFiles('flake.lock') }}-${{ matrix.ghc-version }}-v${{ env.cache-invalidation-key }}-${{ hashFiles('linear-base.cabal') }}-${{ github.sha }}
28+
restore-keys: cabal-deps-${{ runner.os }}-${{ hashFiles('flake.lock') }}-${{ matrix.ghc-version }}-v${{ env.cache-invalidation-key }}-${{ hashFiles('linear-base.cabal') }}-
2929
- name: Build Nix dependencies
30-
run: nix-shell --arg ghcVersion '"${{ matrix.ghc-version }}"' --arg installHls 'false' --pure --run "echo '=== Nix dependencies installed ==='"
30+
run: nix develop .#devShells.x86_64-linux.ci-"${{ matrix.ghc-version }}" --command echo '=== Nix dependencies installed ==='
3131
- name: Init Cabal's config file
32-
run: nix-shell --arg ghcVersion '"${{ matrix.ghc-version }}"' --arg installHls 'false' --pure --run "cabal --config-file=/home/runner/.cabal/config user-config -f init"
32+
run: nix develop .#devShells.x86_64-linux.ci-"${{ matrix.ghc-version }}" --command cabal --config-file=/home/runner/.cabal/config user-config -f init
3333
- name: Update Cabal's database
34-
run: nix-shell --arg ghcVersion '"${{ matrix.ghc-version }}"' --arg installHls 'false' --pure --run "cabal update"
34+
run: nix develop .#devShells.x86_64-linux.ci-"${{ matrix.ghc-version }}" --command cabal update
3535
- name: Build Cabal's dependencies
36-
run: nix-shell --arg ghcVersion '"${{ matrix.ghc-version }}"' --arg installHls 'false' --pure --run "cabal build --dependencies-only"
36+
run: nix develop .#devShells.x86_64-linux.ci-"${{ matrix.ghc-version }}" --command cabal build --dependencies-only
3737
- name: Build
38-
run: nix-shell --arg ghcVersion '"${{ matrix.ghc-version }}"' --arg installHls 'false' --pure --run "cabal build"
38+
run: nix develop .#devShells.x86_64-linux.ci-"${{ matrix.ghc-version }}" --command cabal build
3939
- name: Haddock
40-
run: nix-shell --arg ghcVersion '"${{ matrix.ghc-version }}"' --arg installHls 'false' --pure --run "cabal haddock"
40+
run: nix develop .#devShells.x86_64-linux.ci-"${{ matrix.ghc-version }}" --command cabal haddock
4141
- name: cabal-docspec
42-
run: nix-shell --arg ghcVersion '"${{ matrix.ghc-version }}"' --arg installHls 'false' --pure --run "cabal-docspec"
42+
run: nix develop .#devShells.x86_64-linux.ci-"${{ matrix.ghc-version }}" --command cabal-docspec
4343
- name: Build benchmarks
44-
run: nix-shell --arg ghcVersion '"${{ matrix.ghc-version }}"' --arg installHls 'false' --pure --run "cabal build linear-base:bench:bench"
44+
run: nix develop .#devShells.x86_64-linux.ci-"${{ matrix.ghc-version }}" --command cabal build linear-base:bench:bench
4545
- name: Run benchmarks
46-
run: nix-shell --arg ghcVersion '"${{ matrix.ghc-version }}"' --arg installHls 'false' --pure --run "cabal bench 2>&1 | tee benchmark_ghc${{ matrix.ghc-version }}.txt"
46+
run: nix develop .#devShells.x86_64-linux.ci-"${{ matrix.ghc-version }}" --command cabal bench 2>&1 | tee benchmark_ghc${{ matrix.ghc-version }}.txt
4747
- name: Upload benchmark results
4848
uses: actions/upload-artifact@v4
4949
with:
@@ -60,16 +60,10 @@ jobs:
6060
- uses: cachix/install-nix-action@v15
6161
with:
6262
nix_path: "${{ env.nixpkgs-url }}"
63-
- name: Cache Stack dependencies
64-
uses: actions/cache@v4
65-
with:
66-
path: ~/.stack
67-
key: stack-deps-ormolu-${{ runner.os }}-${{ hashFiles('nix/sources.json') }}-v${{ env.cache-invalidation-key }}-${{ hashFiles('stack.yaml.lock') }}-${{ github.sha }}
68-
restore-keys: stack-deps-ormolu-${{ runner.os }}-${{ hashFiles('nix/sources.json') }}-v${{ env.cache-invalidation-key }}-${{ hashFiles('stack.yaml.lock') }}-
6963
- name: Build Nix dependencies
70-
run: nix-shell --arg installHls 'false' --pure --run "echo '=== Nix dependencies installed ==='"
64+
run: nix develop .#devShells.x86_64-linux.ci-stack --command echo '=== Nix dependencies installed ==='
7165
- name: check formatting
72-
run: nix-shell --arg installHls 'false' --pure --run 'stack build ormolu && stack exec ormolu -- -m check $(find . -type f -name "*.hs-boot" -o -name "*.hs")'
66+
run: nix develop .#devShells.x86_64-linux.ci-stack --command ormolu -m check $(find . -type f -name "*.hs-boot" -o -name "*.hs")
7367

7468
stack-build:
7569
name: stack build
@@ -83,9 +77,9 @@ jobs:
8377
uses: actions/cache@v4
8478
with:
8579
path: ~/.stack
86-
key: stack-deps-${{ runner.os }}-${{ hashFiles('nix/sources.json') }}-v${{ env.cache-invalidation-key }}-${{ hashFiles('stack.yaml.lock', 'linear-base.cabal') }}-${{ github.sha }}
87-
restore-keys: stack-deps-${{ runner.os }}-${{ hashFiles('nix/sources.json') }}-v${{ env.cache-invalidation-key }}-${{ hashFiles('stack.yaml.lock', 'linear-base.cabal') }}-
80+
key: stack-deps-${{ runner.os }}-${{ hashFiles('flake.lock') }}-v${{ env.cache-invalidation-key }}-${{ hashFiles('stack.yaml.lock', 'linear-base.cabal') }}-${{ github.sha }}
81+
restore-keys: stack-deps-${{ runner.os }}-${{ hashFiles('flake.lock') }}-v${{ env.cache-invalidation-key }}-${{ hashFiles('stack.yaml.lock', 'linear-base.cabal') }}-
8882
- name: Build Nix dependencies
89-
run: nix-shell --arg installHls 'false' --pure --run "echo '=== Nix dependencies installed ==='"
83+
run: nix develop .#devShells.x86_64-linux.ci-stack --command echo '=== Nix dependencies installed ==='
9084
- name: Build
91-
run: nix-shell --arg installHls 'false' --pure --run "stack build --pedantic --test --bench --no-run-benchmarks"
85+
run: nix develop .#devShells.x86_64-linux.ci-stack --command stack build --pedantic --test --bench --no-run-benchmarks

bench/Data/Mutable/HashMap.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import qualified Data.HashMap.Strict as Map
2222
import qualified Data.HashTable.ST.Basic as BasicST
2323
import qualified Data.HashTable.ST.Cuckoo as CuckooST
2424
import Data.Hashable (Hashable (..), hashWithSalt)
25-
import Data.List (foldl')
25+
import qualified Data.List as List
2626
import qualified Data.Unrestricted.Linear as Linear
2727
import GHC.Generics (Generic)
2828
import qualified Prelude.Linear as Linear
@@ -199,7 +199,7 @@ vanilla_hashmap_strict inp@(BenchInput {pairs = kvs}) =
199199
bench (descriptions !! n) $ nf (\xs -> f xs Map.empty) kvs
200200

201201
foldlx :: (b -> a -> b) -> [a] -> b -> b
202-
foldlx f xs b = foldl' f b xs
202+
foldlx f xs b = List.foldl' f b xs
203203

204204
look :: Map.HashMap Key Int -> Key -> Map.HashMap Key Int
205205
look m k = case m Map.!? k of
@@ -208,7 +208,7 @@ vanilla_hashmap_strict inp@(BenchInput {pairs = kvs}) =
208208

209209
bench1 :: Benchmark
210210
bench1 = mkBench 0 $
211-
\xs hm -> foldl' (\m (k, v) -> Map.delete k (Map.insert k v m)) hm xs
211+
\xs hm -> List.foldl' (\m (k, v) -> Map.delete k (Map.insert k v m)) hm xs
212212

213213
bench2 :: Benchmark
214214
bench2 = mkBench 1 $

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ packages: *.cabal
33
tests: True
44
benchmarks: True
55
allow-newer: all
6-
index-state: 2024-09-13T13:31:57Z
6+
index-state: 2026-05-12T09:26:21Z

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
description = "Linear-base";
3+
4+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
5+
inputs.flake-utils.url = "github:numtide/flake-utils";
6+
7+
outputs = { self, nixpkgs, flake-utils }:
8+
flake-utils.lib.eachDefaultSystem (system:
9+
let
10+
pkgs = import nixpkgs { inherit system; inherit overlays; };
11+
12+
# need to match Stackage LTS version from stack.yaml snapshot
13+
stack-ghc-version = "ghc9103";
14+
15+
# Versions used by CI's Cabal-based matrix
16+
ci-ghc-versions = ["96" "98" "910" "912"];
17+
18+
cabal-docspec = import ./nix/cabal-docspec.nix { inherit pkgs; };
19+
20+
buildTools = ghc-ver:
21+
let hask = pkgs.haskell.packages."${ghc-ver}"; in
22+
[
23+
hask.ghc
24+
pkgs.cabal-install
25+
stack-wrapped
26+
cabal-docspec
27+
pkgs.ormolu # Haskell formatter
28+
];
29+
30+
devTools = ghc-ver:
31+
let hask = pkgs.haskell.packages."${ghc-ver}"; in
32+
[
33+
hask.ghcid # Continuous terminal Haskell compile checker
34+
hask.haskell-language-server # LSP server for editor
35+
];
36+
37+
mkCIShellFor = ghc-ver: pkgs.mkShell {
38+
# Set UTF-8 local so that run-tests can parse GHC's unicode output.
39+
LANG="C.UTF-8";
40+
41+
buildInputs = buildTools "${ghc-ver}";
42+
};
43+
44+
ci-shells = builtins.listToAttrs (map (ver:
45+
{ name = "ci-${ver}"; value = mkCIShellFor "ghc${ver}"; }
46+
) ci-ghc-versions);
47+
48+
mkDevShellFor = ghc-ver: pkgs.mkShell {
49+
# Set UTF-8 local so that run-tests can parse GHC's unicode output.
50+
LANG="C.UTF-8";
51+
52+
buildInputs = buildTools "${ghc-ver}" ++ devTools "${ghc-ver}";
53+
54+
};
55+
56+
cabal-dev-shells = builtins.listToAttrs (map (ver:
57+
{ name = "dev-${ver}"; value = mkDevShellFor "ghc${ver}"; }
58+
) ci-ghc-versions);
59+
60+
# See https://docs.haskellstack.org/en/stable/topics/nix_integration/
61+
stack-wrapped = pkgs.symlinkJoin {
62+
name = "stack"; # will be available as the usual `stack` in terminal
63+
paths = [ pkgs.stack ];
64+
buildInputs = [ pkgs.makeWrapper ];
65+
postBuild = ''
66+
wrapProgram $out/bin/stack \
67+
--add-flags "\
68+
--no-nix \
69+
--system-ghc \
70+
--no-install-ghc \
71+
"
72+
'';
73+
};
74+
75+
overlays = [
76+
];
77+
78+
in {
79+
80+
devShells = ci-shells // cabal-dev-shells // {
81+
default = mkDevShellFor stack-ghc-version;
82+
83+
ci-stack = mkCIShellFor stack-ghc-version;};
84+
}
85+
);
86+
}

format.sh

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
#!/usr/bin/env bash
2-
# Format linear-base using the version of Ormolu specified in stack.yaml.
2+
# Format linear-base using the version of Ormolu from the PATH. It's recommended
3+
# using the version provided by `flake.nix`, since it's the one used by the CI
4+
# to enforce formatting.
35

46
set -e
57

68
export LANG="C.UTF-8"
79

8-
stack build ormolu
9-
## We can't format cabal at the moment because `cabal format` inlines
10-
## common stanzas, which is very much something that we don't want. See
11-
## https://github.com/haskell/cabal/issues/5734
12-
#
13-
# cabal format
14-
stack exec ormolu -- -m inplace $(find . -type f -name "*.hs-boot" -o -name "*.hs")
10+
ormolu -m inplace $(find . -type f -name "*.hs-boot" -o -name "*.hs")

nix/shell-stack.nix

Lines changed: 0 additions & 9 deletions
This file was deleted.

nix/sources.json

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)