Skip to content

Commit f1b3f12

Browse files
committed
Improve flake setup
1 parent 1cd49cd commit f1b3f12

File tree

4 files changed

+39
-34
lines changed

4 files changed

+39
-34
lines changed

.github/workflows/nix.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
needs: lint
4646
strategy:
4747
matrix:
48-
ghc: ["ghc902", "ghc927", "ghc945", "ghc964", "ghc982", "ghc9101"]
48+
ghc: ["ghc90", "ghc92", "ghc94", "ghc96", "ghc98", "ghc910"]
4949
include:
5050
- os: ubuntu-latest
5151
system: x86_64-linux

flake.nix

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
url = "github:cachix/pre-commit-hooks.nix";
2222
inputs = {
2323
nixpkgs.follows = "nixpkgs";
24-
flake-utils.follows = "flake-utils";
2524
};
2625
};
2726
jupyenv = {
@@ -68,8 +67,21 @@
6867
"^.*\.md"
6968
];
7069

71-
monad-bayes-per-ghc = let
72-
opts = {
70+
# Always keep this up to date with the tested-with section in monad-bayes.cabal!
71+
# and the build-all-ghcs job in .github/workflows/nix.yml!
72+
ghcs = [
73+
"ghc90"
74+
"ghc92"
75+
"ghc94"
76+
"ghc96"
77+
"ghc98"
78+
"ghc910"
79+
"default"
80+
];
81+
82+
allHaskellPackages = lib.filterAttrs (ghcVersion: _: builtins.elem ghcVersion ghcs) (pkgs.haskell.packages // {default = pkgs.haskellPackages;});
83+
84+
monad-bayes-for = haskellPackages: haskellPackages.developPackage {
7385
name = "monad-bayes";
7486
root = src;
7587
cabal2nixOptions = "--benchmark -fdev";
@@ -90,21 +102,10 @@
90102
microstache = doJailbreak super.microstache;
91103
};
92104
};
93-
ghcs = [
94-
# Always keep this up to date with the tested-with section in monad-bayes.cabal,
95-
# and the build-all-ghcs job in .github/workflows/nix.yml!
96-
"ghc902"
97-
"ghc927"
98-
"ghc945"
99-
"ghc964"
100-
"ghc982"
101-
"ghc9101"
102-
];
103-
buildForVersion = ghcVersion: (builtins.getAttr ghcVersion pkgs.haskell.packages).developPackage opts;
104-
in
105-
lib.attrsets.genAttrs ghcs buildForVersion;
106105

107-
monad-bayes = monad-bayes-per-ghc.ghc902;
106+
monad-bayes-per-ghc = lib.mapAttrs (_: monad-bayes-for) allHaskellPackages;
107+
108+
monad-bayes = monad-bayes-per-ghc.default;
108109

109110
monad-bayes-all-ghcs = pkgs.linkFarm "monad-bayes-all-ghcs" monad-bayes-per-ghc;
110111

@@ -114,17 +115,6 @@
114115
];
115116
};
116117

117-
monad-bayes-dev = pkgs.mkShell {
118-
inputsFrom = [monad-bayes.env];
119-
packages = with pre-commit-hooks.packages.${system}; [
120-
alejandra
121-
cabal-fmt
122-
hlint
123-
ormolu
124-
jupyterEnvironment
125-
];
126-
shellHook = pre-commit.shellHook;
127-
};
128118
pre-commit = pre-commit-hooks.lib.${system}.run {
129119
inherit src;
130120
hooks = {
@@ -134,13 +124,30 @@
134124
ormolu.enable = true;
135125
};
136126
};
127+
devShellFor = ghcVersion: haskellPackages: addJupyter: haskellPackages.shellFor {
128+
packages = hps: [
129+
(monad-bayes-for haskellPackages)
130+
];
131+
nativeBuildInputs = with pre-commit-hooks.packages.${system}; [
132+
alejandra
133+
cabal-fmt
134+
hlint
135+
ormolu
136+
] ++ lib.optional addJupyter jupyterEnvironment
137+
++ (with haskellPackages; [
138+
haskell-language-server
139+
]);
140+
};
137141
in rec {
138142
packages = {
139143
inherit monad-bayes monad-bayes-per-ghc monad-bayes-all-ghcs pre-commit jupyterEnvironment;
140144
};
141145
packages.default = packages.monad-bayes;
142146
checks = {inherit monad-bayes pre-commit;};
143-
devShells.default = monad-bayes-dev;
147+
devShells = lib.concatMapAttrs (ghcVersion: haskellPackages: {
148+
"${ghcVersion}" = devShellFor ghcVersion haskellPackages false;
149+
"${ghcVersion}-jupyter" = devShellFor ghcVersion haskellPackages true;
150+
}) allHaskellPackages;
144151
# Needed for backwards compatibility with Nix versions <2.8
145152
defaultPackage = warnToUpdateNix packages.default;
146153
devShell = warnToUpdateNix devShells.default;

monad-bayes.cabal

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ copyright: 2015-2020 Adam Scibior
77
maintainer: [email protected]
88
author: Adam Scibior <[email protected]>
99
stability: experimental
10-
tested-with:
11-
GHC ==9.0.2 || ==9.2.7 || ==9.4.5 || ==9.6.4 || ==9.8.2 || ==9.10.1
12-
10+
tested-with: GHC ==9.0 || ==9.2 || ==9.4 || ==9.6 || ==9.8 || ==9.10
1311
homepage: http://github.com/tweag/monad-bayes#readme
1412
bug-reports: https://github.com/tweag/monad-bayes/issues
1513
synopsis: A library for probabilistic programming.

regenerate_notebooks.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env sh
22
# Regenerates the notebook html files in `docs/docs/notebooks/`
33

4-
nix --print-build-logs develop --command jupyter-nbconvert --to html notebooks/examples/*.ipynb --output-dir docs/docs/notebooks/
4+
nix --print-build-logs develop .#default-jupyter --command jupyter-nbconvert --to html notebooks/examples/*.ipynb --output-dir docs/docs/notebooks/

0 commit comments

Comments
 (0)