Skip to content

Commit 28888d2

Browse files
authored
Merge pull request #366 from tweag/dev_flake
Improve flake setup
2 parents a1a461c + 5831a8c commit 28888d2

File tree

9 files changed

+129
-127
lines changed

9 files changed

+129
-127
lines changed

.envrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
# Make sure you have direnv >= 2.30
2-
use flake --extra-experimental-features nix-command --extra-experimental-features flakes
1+
use flake

.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

default.nix

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
(
22
import
3-
(
4-
let
5-
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
6-
in
3+
(
4+
let
5+
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
6+
in
77
fetchTarball {
88
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
99
sha256 = lock.nodes.flake-compat.locked.narHash;
1010
}
11-
)
12-
{src = ./.;}
13-
)
14-
.defaultNix
11+
)
12+
{ src = ./.; }
13+
).defaultNix

flake.nix

Lines changed: 109 additions & 95 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 = {
@@ -32,44 +31,59 @@
3231
};
3332
};
3433
};
35-
outputs = {
36-
self,
37-
nixpkgs,
38-
jupyenv,
39-
flake-compat,
40-
flake-utils,
41-
pre-commit-hooks,
42-
} @ inputs:
34+
outputs =
35+
{ self
36+
, nixpkgs
37+
, jupyenv
38+
, flake-compat
39+
, flake-utils
40+
, pre-commit-hooks
41+
,
42+
} @ inputs:
4343
flake-utils.lib.eachSystem
44-
[
45-
# Tier 1 - Tested in CI
46-
flake-utils.lib.system.x86_64-linux
47-
flake-utils.lib.system.x86_64-darwin
48-
# Tier 2 - Not tested in CI (at least for now)
49-
flake-utils.lib.system.aarch64-linux
50-
flake-utils.lib.system.aarch64-darwin
51-
]
52-
(
53-
system: let
54-
inherit (nixpkgs) lib;
55-
inherit (jupyenv.lib.${system}) mkJupyterlabNew;
56-
pkgs = import nixpkgs {
57-
inherit system;
58-
config.allowBroken = true;
59-
};
44+
[
45+
# Tier 1 - Tested in CI
46+
flake-utils.lib.system.x86_64-linux
47+
flake-utils.lib.system.x86_64-darwin
48+
# Tier 2 - Not tested in CI (at least for now)
49+
flake-utils.lib.system.aarch64-linux
50+
flake-utils.lib.system.aarch64-darwin
51+
]
52+
(
53+
system:
54+
let
55+
inherit (nixpkgs) lib;
56+
inherit (jupyenv.lib.${system}) mkJupyterlabNew;
57+
pkgs = import nixpkgs {
58+
inherit system;
59+
config.allowBroken = true;
60+
};
6061

61-
warnToUpdateNix = pkgs.lib.warn "Consider updating to Nix > 2.7 to remove this warning!";
62-
src = lib.sourceByRegex self [
63-
"^benchmark.*$"
64-
"^models.*$"
65-
"^monad-bayes\.cabal$"
66-
"^src.*$"
67-
"^test.*$"
68-
"^.*\.md"
69-
];
62+
warnToUpdateNix = pkgs.lib.warn "Consider updating to Nix > 2.7 to remove this warning!";
63+
src = lib.sourceByRegex self [
64+
"^benchmark.*$"
65+
"^models.*$"
66+
"^monad-bayes\.cabal$"
67+
"^src.*$"
68+
"^test.*$"
69+
"^.*\.md"
70+
];
7071

71-
monad-bayes-per-ghc = let
72-
opts = {
72+
# Always keep this up to date with the tested-with section in monad-bayes.cabal!
73+
# and the build-all-ghcs job in .github/workflows/nix.yml!
74+
ghcs = [
75+
"ghc90"
76+
"ghc92"
77+
"ghc94"
78+
"ghc96"
79+
"ghc98"
80+
"ghc910"
81+
"default"
82+
];
83+
84+
allHaskellPackages = lib.filterAttrs (ghcVersion: _: builtins.elem ghcVersion ghcs) (pkgs.haskell.packages // { default = pkgs.haskellPackages; });
85+
86+
monad-bayes-for = haskellPackages: haskellPackages.developPackage {
7387
name = "monad-bayes";
7488
root = src;
7589
cabal2nixOptions = "--benchmark -fdev";
@@ -81,69 +95,69 @@
8195
else pkgs.haskell.lib.dontCheck drv;
8296
overrides = self: super:
8397
with pkgs.haskell.lib;
84-
{
85-
# Please check after flake.lock updates whether some of these overrides can be removed
86-
brick = super.brick_2_4;
87-
}
88-
// lib.optionalAttrs (lib.versionAtLeast super.ghc.version "9.10") {
89-
# Please check after flake.lock updates whether some of these overrides can be removed
90-
microstache = doJailbreak super.microstache;
91-
};
98+
{
99+
# Please check after flake.lock updates whether some of these overrides can be removed
100+
brick = super.brick_2_4;
101+
}
102+
// lib.optionalAttrs (lib.versionAtLeast super.ghc.version "9.10") {
103+
# Please check after flake.lock updates whether some of these overrides can be removed
104+
microstache = doJailbreak super.microstache;
105+
};
92106
};
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;
106107

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

109-
monad-bayes-all-ghcs = pkgs.linkFarm "monad-bayes-all-ghcs" monad-bayes-per-ghc;
110+
monad-bayes = monad-bayes-per-ghc.default;
110111

111-
jupyterEnvironment = mkJupyterlabNew {
112-
imports = [
113-
(import ./kernels/haskell.nix {inherit monad-bayes;})
114-
];
115-
};
112+
monad-bayes-all-ghcs = pkgs.linkFarm "monad-bayes-all-ghcs" monad-bayes-per-ghc;
116113

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-
};
128-
pre-commit = pre-commit-hooks.lib.${system}.run {
129-
inherit src;
130-
hooks = {
131-
alejandra.enable = true;
132-
cabal-fmt.enable = true;
133-
hlint.enable = false;
134-
ormolu.enable = true;
114+
jupyterEnvironment = mkJupyterlabNew {
115+
imports = [
116+
(import ./kernels/haskell.nix { inherit monad-bayes; })
117+
];
118+
};
119+
120+
121+
pre-commit = pre-commit-hooks.lib.${system}.run {
122+
inherit src;
123+
hooks = {
124+
alejandra.enable = true;
125+
cabal-fmt.enable = true;
126+
hlint.enable = false;
127+
ormolu.enable = true;
128+
};
129+
};
130+
devShellFor = ghcVersion: haskellPackages: addJupyter: haskellPackages.shellFor {
131+
packages = hps: [
132+
(monad-bayes-for haskellPackages)
133+
];
134+
nativeBuildInputs = with pre-commit-hooks.packages.${system}; [
135+
alejandra
136+
cabal-fmt
137+
hlint
138+
ormolu
139+
] ++ lib.optional addJupyter jupyterEnvironment
140+
++ (with haskellPackages; [
141+
haskell-language-server
142+
]);
143+
};
144+
in
145+
rec {
146+
packages = {
147+
inherit monad-bayes monad-bayes-per-ghc monad-bayes-all-ghcs pre-commit jupyterEnvironment;
135148
};
136-
};
137-
in rec {
138-
packages = {
139-
inherit monad-bayes monad-bayes-per-ghc monad-bayes-all-ghcs pre-commit jupyterEnvironment;
140-
};
141-
packages.default = packages.monad-bayes;
142-
checks = {inherit monad-bayes pre-commit;};
143-
devShells.default = monad-bayes-dev;
144-
# Needed for backwards compatibility with Nix versions <2.8
145-
defaultPackage = warnToUpdateNix packages.default;
146-
devShell = warnToUpdateNix devShells.default;
147-
}
148-
);
149+
packages.default = packages.monad-bayes;
150+
checks = { inherit monad-bayes pre-commit; };
151+
devShells = lib.concatMapAttrs
152+
(ghcVersion: haskellPackages: {
153+
"${ghcVersion}" = devShellFor ghcVersion haskellPackages false;
154+
"${ghcVersion}-jupyter" = devShellFor ghcVersion haskellPackages true;
155+
})
156+
allHaskellPackages;
157+
# Needed for backwards compatibility with Nix versions <2.8
158+
defaultPackage = warnToUpdateNix packages.default;
159+
devShell = warnToUpdateNix devShells.default;
160+
formatter = pkgs.nixpkgs-fmt;
161+
}
162+
);
149163
}

kernels/haskell.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{monad-bayes}:
1+
{ monad-bayes }:
22

3-
{pkgs, ...}: {
3+
{ pkgs, ... }: {
44
kernel.haskell.monad-bayes = {
55
enable = true;
66
name = "monad-bayes";

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/

shell.nix

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
(
22
import
3-
(
4-
let
5-
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
6-
in
3+
(
4+
let
5+
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
6+
in
77
fetchTarball {
88
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
99
sha256 = lock.nodes.flake-compat.locked.narHash;
1010
}
11-
)
12-
{src = ./.;}
13-
)
14-
.shellNix
11+
)
12+
{ src = ./.; }
13+
).shellNix

stack.yaml

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

0 commit comments

Comments
 (0)