Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve flake setup #366

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Make sure you have direnv >= 2.30
use flake --extra-experimental-features nix-command --extra-experimental-features flakes
use flake
2 changes: 1 addition & 1 deletion .github/workflows/nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
needs: lint
strategy:
matrix:
ghc: ["ghc902", "ghc927", "ghc945", "ghc964", "ghc982", "ghc9101"]
ghc: ["ghc90", "ghc92", "ghc94", "ghc96", "ghc98", "ghc910"]
include:
- os: ubuntu-latest
system: x86_64-linux
Expand Down
65 changes: 36 additions & 29 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
url = "github:cachix/pre-commit-hooks.nix";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
jupyenv = {
Expand Down Expand Up @@ -68,8 +67,21 @@
"^.*\.md"
];

monad-bayes-per-ghc = let
opts = {
# Always keep this up to date with the tested-with section in monad-bayes.cabal!
# and the build-all-ghcs job in .github/workflows/nix.yml!
ghcs = [
"ghc90"
"ghc92"
"ghc94"
"ghc96"
"ghc98"
"ghc910"
"default"
];

allHaskellPackages = lib.filterAttrs (ghcVersion: _: builtins.elem ghcVersion ghcs) (pkgs.haskell.packages // {default = pkgs.haskellPackages;});

monad-bayes-for = haskellPackages: haskellPackages.developPackage {
name = "monad-bayes";
root = src;
cabal2nixOptions = "--benchmark -fdev";
Expand All @@ -90,21 +102,10 @@
microstache = doJailbreak super.microstache;
};
};
ghcs = [
# Always keep this up to date with the tested-with section in monad-bayes.cabal,
# and the build-all-ghcs job in .github/workflows/nix.yml!
"ghc902"
"ghc927"
"ghc945"
"ghc964"
"ghc982"
"ghc9101"
];
buildForVersion = ghcVersion: (builtins.getAttr ghcVersion pkgs.haskell.packages).developPackage opts;
in
lib.attrsets.genAttrs ghcs buildForVersion;

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

monad-bayes = monad-bayes-per-ghc.default;

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

Expand All @@ -114,17 +115,6 @@
];
};

monad-bayes-dev = pkgs.mkShell {
inputsFrom = [monad-bayes.env];
packages = with pre-commit-hooks.packages.${system}; [
alejandra
cabal-fmt
hlint
ormolu
jupyterEnvironment
];
shellHook = pre-commit.shellHook;
};
pre-commit = pre-commit-hooks.lib.${system}.run {
inherit src;
hooks = {
Expand All @@ -134,13 +124,30 @@
ormolu.enable = true;
};
};
devShellFor = ghcVersion: haskellPackages: addJupyter: haskellPackages.shellFor {
packages = hps: [
(monad-bayes-for haskellPackages)
];
nativeBuildInputs = with pre-commit-hooks.packages.${system}; [
alejandra
cabal-fmt
hlint
ormolu
] ++ lib.optional addJupyter jupyterEnvironment
++ (with haskellPackages; [
haskell-language-server
]);
};
in rec {
packages = {
inherit monad-bayes monad-bayes-per-ghc monad-bayes-all-ghcs pre-commit jupyterEnvironment;
};
packages.default = packages.monad-bayes;
checks = {inherit monad-bayes pre-commit;};
devShells.default = monad-bayes-dev;
devShells = lib.concatMapAttrs (ghcVersion: haskellPackages: {
"${ghcVersion}" = devShellFor ghcVersion haskellPackages false;
"${ghcVersion}-jupyter" = devShellFor ghcVersion haskellPackages true;
}) allHaskellPackages;
# Needed for backwards compatibility with Nix versions <2.8
defaultPackage = warnToUpdateNix packages.default;
devShell = warnToUpdateNix devShells.default;
Expand Down
4 changes: 1 addition & 3 deletions monad-bayes.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ copyright: 2015-2020 Adam Scibior
maintainer: [email protected]
author: Adam Scibior <[email protected]>
stability: experimental
tested-with:
GHC ==9.0.2 || ==9.2.7 || ==9.4.5 || ==9.6.4 || ==9.8.2 || ==9.10.1

tested-with: GHC ==9.0 || ==9.2 || ==9.4 || ==9.6 || ==9.8 || ==9.10
homepage: http://github.com/tweag/monad-bayes#readme
bug-reports: https://github.com/tweag/monad-bayes/issues
synopsis: A library for probabilistic programming.
Expand Down
2 changes: 1 addition & 1 deletion regenerate_notebooks.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
# Regenerates the notebook html files in `docs/docs/notebooks/`

nix --print-build-logs develop --command jupyter-nbconvert --to html notebooks/examples/*.ipynb --output-dir docs/docs/notebooks/
nix --print-build-logs develop .#default-jupyter --command jupyter-nbconvert --to html notebooks/examples/*.ipynb --output-dir docs/docs/notebooks/
7 changes: 0 additions & 7 deletions stack.yaml

This file was deleted.

Loading