Skip to content

Commit

Permalink
Simple flake for multi cabal home
Browse files Browse the repository at this point in the history
Uses haskell-flake-utils (experimental) to provide build and devShell with nix flakes:
```
nix build .#rhine-gloss
result/bin/rhine-gloss-gears
```

```
nix develop
cabal build rhine
```
  • Loading branch information
jmatsushita committed Jun 18, 2022
1 parent a43d98b commit 1001e35
Show file tree
Hide file tree
Showing 19 changed files with 156 additions and 84 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,24 @@ jobs:
- name: Cabal test
run: |
cabal test all --enable-tests --test-show-details=Always --project-file=cabal.project.${{ matrix.ghc }}
build-flake:
name: Nix Flake
strategy:
matrix:
os:
- ubuntu-20.04
- macos-12
runs-on: ${{ matrix.os }}
steps:
- uses: actions/[email protected]
- uses: cachix/install-nix-action@v15
- name: Build default package (rhine)
run: nix build
- name: Build default package (rhine-examples)
run: nix build .#rhine-examples
- name: Build default package (rhine-gloss)
run: nix build .#rhine-gloss
- name: Run tests
run: nix develop -c cabal test all
# nix flake check breaks on IFD in multi-platform flake https://github.com/NixOS/nix/issues/4265
# - run: nix flake check
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ cabal.sandbox.config
*.eventlog
.stack-work/
cabal.project.local
result
4 changes: 2 additions & 2 deletions Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

### GHC, cabal, stack, nix

* Rhine should be compilable with `cabal`, `nix` and `stack`.
If in doubt, use `cabal` and `nix`.
* Rhine should be compilable with `cabal`, `nix` (including flakes) and `stack`.
If in doubt, use `cabal` and `nix` (preferably flakes with `nix develop`).
* Rhine does not make an effort to support old GHC versions,
but it does make an effort to support _new_ versions.
Check `.travis.yml` for supported GHC versions.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ constraints on clocks come into effect, enforcing clock safety.

A typical example,
which can be run as `cd rhine-examples/ && cabal run Demonstration`,
(or using nix flakes with `nix develop` followed `cabal run Demonstration`),
would be:

```haskell
Expand Down
17 changes: 7 additions & 10 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
attrs@{ ... }:

let
localPackages = import ./nix/localPackages.nix attrs;
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
flake-compat-src = fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
};
flake-compat = import flake-compat-src { src = ./.; };
in
{
inherit (localPackages)
rhine
rhine-gloss
rhine-examples
;
}
flake-compat.defaultNix
80 changes: 80 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
description = "rhine";
nixConfig.bash-prompt = "\[rhine\]$ ";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";

flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};

haskell-flake-utils.url = "github:ivanovs-4/haskell-flake-utils";
haskell-flake-utils.inputs.nixpkgs.follows = "nixpkgs";
haskell-flake-utils.inputs.flake-utils.follows = "flake-utils";
};

outputs = { self, nixpkgs, flake-utils, haskell-flake-utils, flake-compat, ... }:
haskell-flake-utils.lib.simpleCabalProject2flake {
inherit self nixpkgs;

systems = [
# Tested in CI
"x86_64-linux"
"x86_64-darwin"
# Tested by maintainers
"aarch64-darwin"
# Not sure we can test this in CI
"i686-linux"
];

name = "rhine";
packageNames = [ "rhine-gloss" "rhine-examples" ];
};
}
8 changes: 0 additions & 8 deletions nix/all-ghcs.nix

This file was deleted.

6 changes: 0 additions & 6 deletions nix/defaults.nix

This file was deleted.

13 changes: 0 additions & 13 deletions nix/localPackages.nix

This file was deleted.

18 changes: 0 additions & 18 deletions nix/shellFrom.nix

This file was deleted.

5 changes: 0 additions & 5 deletions rhine-examples/default.nix

This file was deleted.

1 change: 0 additions & 1 deletion rhine-examples/shell.nix

This file was deleted.

5 changes: 0 additions & 5 deletions rhine-gloss/default.nix

This file was deleted.

1 change: 0 additions & 1 deletion rhine-gloss/shell.nix

This file was deleted.

6 changes: 0 additions & 6 deletions rhine-gloss/stack_NixOS.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions rhine/default.nix

This file was deleted.

1 change: 0 additions & 1 deletion rhine/shell.nix

This file was deleted.

11 changes: 8 additions & 3 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
let
mypkgs = import ./. {};
shellFrom = import ./nix/shellFrom.nix {};
in shellFrom mypkgs.rhine-gloss
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
flake-compat-src = fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
};
flake-compat = import flake-compat-src { src = ./.; };
in
flake-compat.shellNix

0 comments on commit 1001e35

Please sign in to comment.