Skip to content

Commit

Permalink
add basic nix build
Browse files Browse the repository at this point in the history
  • Loading branch information
tek committed Mar 14, 2021
1 parent c37d485 commit b8b912a
Show file tree
Hide file tree
Showing 12 changed files with 298 additions and 22 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/nix-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Build Polysemy with Nix
on:
push:
branches:
- nix-build
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: cachix/install-nix-action@v12
with:
install_url: https://github.com/numtide/nix-flakes-installer/releases/download/nix-2.4pre20201221_9fab14a/install
extra_nix_config: |
experimental-features = nix-command flakes
- run: nix flake check
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,50 @@ You're going to want to stick all of this into your `package.yaml` file.
- TypeFamilies
```
## Building with Nix
The project provides a basic nix config for building in development.
It is defined as a [flake] with backwards compatibility stubs in `default.nix` and `shell.nix`.

To build the main library or plugin:

```bash
nix-build -A polysemy
nix-build -A polysemy-plugin
```

Flake version:

```bash
nix build
nix build '.#polysemy-plugin'
```

To inspect a dependency:

```bash
nix repl
> p = import ./.
> p.unagi-chan
```

To run a shell command with all dependencies in the environment:

```bash
nix-shell --pure
nix-shell --pure --run 'cabal v2-haddock polysemy'
nix-shell --pure --run ghcid
```

Flake version:

```bash
nix develop -i # just enter a shell
nix develop -i -c cabal v2-haddock polysemy
nix develop -i -c haskell-language-server-wrapper # start HLS for your IDE
```

## *What about performance?* ([TL;DR](#tldr))

Previous versions of this `README` mentioned **the library being**
Expand Down Expand Up @@ -311,3 +355,4 @@ implementation:
[oleg:more]: http://okmij.org/ftp/Haskell/extensible/more.pdf
[schrijvers:fusion]: https://people.cs.kuleuven.be/~tom.schrijvers/Research/papers/mpc2015.pdf
[wu:scope]: https://www.cs.ox.ac.uk/people/nicolas.wu/papers/Scope.pdf
[flake]: https://nixos.wiki/wiki/Flakes
1 change: 1 addition & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{...}: (import ./nix/compat.nix).defaultNix
43 changes: 43 additions & 0 deletions flake.lock

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

37 changes: 37 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
description = "Higher-order, low-boilerplate free monads.";

inputs = {
nixpkgs.url = github:NixOs/nixpkgs/nixos-20.09;
flake-utils.url = github:numtide/flake-utils;
};

outputs = { nixpkgs, flake-utils, ... }:
flake-utils.lib.eachSystem ["x86_64-linux"] (system:
let
overlay = import ./nix/overlay.nix;

pkgs = import nixpkgs {
inherit system;
overlays = [overlay];
};
in {
packages = { inherit (pkgs.haskellPackages) polysemy polysemy-plugin; };

defaultPackage = pkgs.haskellPackages.polysemy;

devShell = pkgs.haskellPackages.shellFor {
packages = _: [];
buildInputs = with pkgs.haskellPackages; [
cabal-install
haskell-language-server
ghcid
];
withHoogle = true;
};

checks = {
inherit (pkgs.haskellPackages) polysemy polysemy-plugin;
};
});
}
13 changes: 13 additions & 0 deletions hie.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cradle:
cabal:
- path: "."
component: "lib:polysemy"

- path: "./test"
component: "polysemy:test:polysemy-test"

- path: "./polysemy-plugin"
component: "lib:polysemy-plugin"

- path: "./polysemy-plugin/test"
component: "polysemy-plugin:test:polysemy-plugin-test"
7 changes: 7 additions & 0 deletions nix/compat.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
let
compat = fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz";
sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2";
};
in
import compat { src = ../.; }
33 changes: 33 additions & 0 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
let
pkgOverrides = pkgs: self: super:
let
filter = pkgs.nix-gitignore.gitignoreSourcePure [./source-filter];
c2n = name: src: self.callCabal2nixWithOptions name (filter src) "" {};
hackage = pkg: ver: sha256: self.callHackageDirect { inherit pkg ver sha256; } {};
in {
polysemy = c2n "polysemy" ../.;
polysemy-plugin = c2n "polysemy-plugin" ../polysemy-plugin;
first-class-families =
hackage "first-class-families" "0.8.0.1" "0h1rxbc7zsxrlhx5xcl58wjx3qi2wny8wb3sk7c1qnydf4ckcckz";
ghc-lib = hackage "ghc-lib" "0.20190204" "1i2zjlr30bxpabsm8f995x455v847gbpzczm2w4089fqmsnzpzfd";
dump-core = hackage "dump-core" "0.1.3.2" "1mi8p736yn00z549pwnjv4ydwbs8mwg6dla3ly447c027nq8py6g";
monadLib = hackage "monadLib" "3.10" "1v4ynjcb963s3lfw3v71qdzvld1mmz1faf8swhvicma5jbvwchy2";
};
in
self: super: {
haskell = super.haskell // (
let
p = super.haskell.packages;
overrides = pkgOverrides self;
in {
packages = p // {
ghc865 = p.ghc865.override { inherit overrides; };
ghc883 = p.ghc883.override { inherit overrides; };
ghc884 = p.ghc884.override { inherit overrides; };
ghc8101 = p.ghc8101.override { inherit overrides; };
ghc8102 = p.ghc8102.override { inherit overrides; };
};
}
);
haskellPackages = self.haskell.packages.ghc884;
}
11 changes: 11 additions & 0 deletions nix/source-filter
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
.*
!*.cabal
!*.nix
!*.hs
!LICENSE
!/flake.lock
!/nix/
!/src/
!/test/
!/bench/
38 changes: 31 additions & 7 deletions polysemy-plugin/polysemy-plugin.cabal
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
cabal-version: 2.0

-- This file has been generated from package.yaml by hpack version 0.33.0.
-- This file has been generated from package.yaml by hpack version 0.34.4.
--
-- see: https://github.com/sol/hpack
--
-- hash: 0e9b200907c62e6df486f7512ceffff92f0941cf55d6ef49a581324d50201d44

name: polysemy-plugin
version: 0.2.5.2
Expand Down Expand Up @@ -51,14 +49,27 @@ library
Paths_polysemy_plugin
hs-source-dirs:
src
default-extensions: DataKinds DeriveFunctor FlexibleContexts GADTs LambdaCase PolyKinds RankNTypes ScopedTypeVariables StandaloneDeriving TypeApplications TypeOperators TypeFamilies UnicodeSyntax
default-extensions:
DataKinds
DeriveFunctor
FlexibleContexts
GADTs
LambdaCase
PolyKinds
RankNTypes
ScopedTypeVariables
StandaloneDeriving
TypeApplications
TypeOperators
TypeFamilies
UnicodeSyntax
build-depends:
base >=4.9 && <5
, containers >=0.5 && <0.7
, ghc >=8.4.4 && <9
, ghc-tcplugins-extra >=0.3 && <0.5
, polysemy >=1.3
, syb >=0.7 && <0.8
, syb ==0.7.*
, transformers >=0.5.2.0 && <0.6
default-language: Haskell2010

Expand All @@ -80,7 +91,20 @@ test-suite polysemy-plugin-test
Build_doctests
hs-source-dirs:
test
default-extensions: DataKinds DeriveFunctor FlexibleContexts GADTs LambdaCase PolyKinds RankNTypes ScopedTypeVariables StandaloneDeriving TypeApplications TypeOperators TypeFamilies UnicodeSyntax
default-extensions:
DataKinds
DeriveFunctor
FlexibleContexts
GADTs
LambdaCase
PolyKinds
RankNTypes
ScopedTypeVariables
StandaloneDeriving
TypeApplications
TypeOperators
TypeFamilies
UnicodeSyntax
ghc-options: -threaded -rtsopts -with-rtsopts=-N -fplugin=Polysemy.Plugin
build-tool-depends:
hspec-discover:hspec-discover
Expand All @@ -95,7 +119,7 @@ test-suite polysemy-plugin-test
, polysemy >=1.3.0.0
, polysemy-plugin
, should-not-typecheck >=2.1.0 && <3
, syb >=0.7 && <0.8
, syb ==0.7.*
, transformers >=0.5.2.0 && <0.6
if flag(corelint)
ghc-options: -dcore-lint -dsuppress-all
Expand Down
Loading

0 comments on commit b8b912a

Please sign in to comment.