summaryrefslogtreecommitdiff
path: root/biz.nix
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2020-04-03 19:08:35 -0700
committerBen Sima <ben@bsima.me>2020-04-03 19:08:35 -0700
commit9214692fa60fce959d5fc34dc84c1aa682248222 (patch)
tree260afcb83b321f2d58961ef67cecd7b22c2891c8 /biz.nix
parente82440741295543769fa79ae05519d58fcb81b08 (diff)
Centralize hackage packages to deps.nix
This also allowes me to make 'repl' into a universal command. This makes it much easier to work across different projects.
Diffstat (limited to 'biz.nix')
-rw-r--r--biz.nix23
1 files changed, 18 insertions, 5 deletions
diff --git a/biz.nix b/biz.nix
index 1194758..576d3c4 100644
--- a/biz.nix
+++ b/biz.nix
@@ -9,22 +9,33 @@ let
# general functions to put in a lib
lines = s: strings.splitString "\n" s;
- seq = ls: builtins.filter (x: x!= null) ls;
+ removeNull = ls: builtins.filter (x: x != null) ls;
+
depsToPackageSet = packageSet: deps:
- map (s: builtins.getAttr s packageSet) deps;
+ attrsets.attrVals deps packageSet;
+
+ # returns true if a is a subset of b, where a and b are attrsets
+ subset = a: b: builtins.all
+ (x: builtins.elem x b) a;
+
+ allDeps = import ./deps.nix;
in {
buildGhc = main:
let
relpath = builtins.replaceStrings ["${root}/"] [""] (builtins.toString main);
module = builtins.replaceStrings ["/" ".hs"] ["." ""] relpath;
content = builtins.readFile main;
- exe = builtins.head (lists.flatten (seq
+ exe = builtins.head (lists.flatten (removeNull
(map (builtins.match "^-- : exe ([[:alnum:]._-]*)$")
(lines content))));
- deps = lists.flatten (seq
+ deps = lists.flatten (removeNull
(map (builtins.match "^-- : dep ([[:alnum:]._-]*)$")
(lines content)));
- ghc = pkgs.haskell.packages.ghc865.ghcWithHoogle (hp: depsToPackageSet hp deps);
+ ghc = pkgs.haskell.packages.ghc865.ghcWithHoogle (hp:
+ if (subset deps allDeps)
+ then depsToPackageSet hp deps
+ else throw ("missing from deps.nix: ${toString (lib.lists.subtractLists allDeps deps)}")
+ );
in stdenv.mkDerivation {
name = module;
version = "0";
@@ -82,4 +93,6 @@ in {
'';
installPhase = "exit 0";
} // { env = ghcjs; };
+
+ globalGhc = pkgs.haskell.packages.ghc865.ghcWithHoogle (hp: depsToPackageSet hp allDeps);
}