Adding haskell.nix based default and shell.nix (#141)

Co-authored-by: Ben Ford <ben@perurbis.com>
This commit is contained in:
Ben Ford 2020-09-02 02:47:04 +01:00 committed by GitHub
commit f6f388c8da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 121 additions and 7 deletions

18
.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,18 @@
name: "Nix CI"
on:
pull_request:
push:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.1
- uses: cachix/install-nix-action@v10
with:
skip_adding_nixpkgs_channel: true
- uses: cachix/cachix-action@v6
with:
name: cdodev
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
- run: cachix use iohk && cachix use cdodev
- run: nix-build

View file

@ -79,6 +79,9 @@ $ stack ./examples/doc_drawCircle.hs
This should render the `doc_drawCircle` example in a new browser window. If you then change the
animation source code, the browser window will automatically reload and show the updated animation.
## Using Cabal
It's also possible to use cabal instead of stack:
```console
@ -86,10 +89,34 @@ $ git clone https://github.com/reanimate/reanimate.git
$ cd reanimate/
$ cabal v2-build
$ # Workaround for a cabal bug: https://github.com/haskell/cabal/issues/6235
$ export reanimate_datadir=`pwd`
$ export reanimate_datadir=`pwd`
$ cabal v2-exec -- runhaskell examples/doc_drawCircle.hs --ghc ghc
```
## Using Nix
If you'd rather use nix to build an environment with all of the system dependencies mentioned previously do:
```console
$ git clone https://github.com/reanimate/reanimate.git
$ cd reanimate/
$ nix-shell
[nix-shell:./reanimate]$ cabal v2-build --write-ghc-environment-files=always
```
If you have cachix available run `cachix use cdodev` before you drop into the nix shell. This will significantly speed things up!
This will write a file in the working directory like
`.ghc.environment.x86_64-linux-8.8.3` which will enable commands like `runhaskell`
to pick up reanimate.
Now, still within the `nix-shell` you can run:
```console
[nix-shell:./reanimate]$ reanimate_datadir=. runhaskell examples/doc_drawCircle.hs --ghc `which ghc`
```
# Documentation
* API reference: https://hackage.haskell.org/package/reanimate/docs/Reanimate.html

52
default.nix Normal file
View file

@ -0,0 +1,52 @@
let
haskellNixSrc = fetchTarball {
url = "https://github.com/input-output-hk/haskell.nix/tarball/403b1a1b848295b907f4ceaeb0b6508c3f97e3a3";
sha256 = "1m32hz6zalfhywrzjir4gn81xbwp9vmxqgv3x746gb1zzmjqdhhs";
};
# haskellSrcMaster = builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz;
haskellNix = import haskellNixSrc {};
all-hies = fetchTarball {
# Insert the desired all-hies commit here
url = "https://github.com/infinisil/all-hies/tarball/534ac517b386821b787d1edbd855b9966d0c0775";
# Insert the correct hash after the first evaluation
sha256 = "0bw1llpwxbh1dnrnbxkj2l0j58s523hjivszf827c3az5i4py1i2";
};
pkgs = import haskellNix.sources.nixpkgs-2003 (haskellNix.nixpkgsArgs // {
overlays = haskellNix.nixpkgsArgs.overlays ++ [
(import all-hies {}).overlay
];
});
set = pkgs.haskell-nix.stackProject {
name = "reanimate";
compiler-nix-name = "ghc883";
src = pkgs.haskell-nix.haskellLib.cleanGit {
name = "reanimate";
src = ./.;
};
};
in set.reanimate.components.library // {
env = set.shellFor {
packages = p: [ p.reanimate ];
# exactDeps = true;
nativeBuildInputs = [ pkgs.stack
pkgs.zlib.dev
pkgs.zlib.out
pkgs.gmp
pkgs.gnome3.librsvg
pkgs.blender
pkgs.povray
pkgs.ffmpeg
pkgs.texlive.combined.scheme-full
];
tools = {
cabal = "3.2.0.0";
hie = "unstable";
};
shellHook = ''
export HIE_HOOGLE_DATABASE=$(realpath "$(dirname "$(realpath "$(which hoogle)")")/../share/doc/hoogle/default.hoo")
'';
};
}

View file

@ -1,5 +1,12 @@
#!/usr/bin/env stack
-- stack runghc --package reanimate
#!/usr/bin/env cabal
{- cabal:
build-depends: base
, reanimate
, reanimate-svg
, vector
, random
, JuicyPixels
-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ParallelListComp #-}
module Main

View file

@ -1,5 +1,9 @@
#!/usr/bin/env stack
-- stack runghc --package reanimate
#!/usr/bin/env cabal
{- cabal:
build-depends: base
, reanimate
, reanimate-svg
-}
module Main(main) where
import Reanimate

View file

@ -1,5 +1,10 @@
#!/usr/bin/env stack
-- stack runghc --package reanimate
#!/usr/bin/env cabal
{- cabal:
build-depends: base
, reanimate
, reanimate-svg
, JuicyPixels
-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecursiveDo #-}
module Main (main) where

1
shell.nix Normal file
View file

@ -0,0 +1 @@
(import ./.).env