on angerman/fix-call-stack-to-nix-tests help sign in
haskell.nix/package-set.nix
88 lines 3.5 kB history raw
1let f = { hackage, pkgs, pkg-def, pkg-def-extras ? [], modules ? [] }: let
2 buildModules = f { inherit hackage pkg-def pkg-def-extras modules; pkgs = pkgs.buildPackages; };
3in pkgs.lib.evalModules {
4 modules = modules ++ [
5 ({ lib, ... }: {
6 # Provide all modules with haskellLib, pkgs, and pkgconfPkgs arguments
7 _module.args = {
8 # this is *not* the hasekllLib from nixpkgs; it is rather our own
9 # library from haskell.nix
10 haskellLib = let hl = import ./lib { inherit lib; haskellLib = hl; }; in hl;
12 # The package descriptions depend on pkgs, which are used to resolve system package dependencies
13 # as well as pkgconfPkgs, which are used to resolve pkgconfig name to nixpkgs names. We simply
14 # augment the existing pkgs set with the specific mappings:
15 pkgs = pkgs // (import ./lib/system-nixpkgs-map.nix pkgs);
16 pkgconfPkgs = pkgs // (import ./lib/pkgconf-nixpkgs-map.nix pkgs);
18 inherit buildModules;
19 };
21 # Set the hackage DB for modules/hackage.nix
22 hackage.db = hackage;
24 # Set the plan for modules/plan.nix
25 plan.pkg-def = hackage: with builtins;
26 # The desugar reason.
27 #
28 # it is quite combersome to write
29 # (hackage: { packages.x.revision = hackage...;
30 # packages.y.revision = import ./foo.nix; })
31 # where we'd rather write:
32 # (hackage: { x = hackage...; })
33 # or
34 # { y = ./foo.nix; }
35 # As such the desugarer desugars this short hand syntax.
36 let desugar = extras:
37 let
38 isPath = x: builtins.typeOf x == "path";
39 # rewrite
40 # { ... }
41 # into
42 # { package = { ... }; }
43 inject-packages = o: if o ? "packages" then o else { packages = o; };
44 # rewrite
45 # x = pkg;
46 # into
47 # x.revision = pkg;
48 inject-revision = pkg: if pkg ? "revision" then pkg else { revision = pkg; };
49 # rewrite
50 # x.revision = ./some/path;
51 # into
52 # x.revision = import ./some/path;
53 expand-paths = pkg: if !(isPath pkg.revision) then pkg else { revision = import pkg.revision; };
54 # apply injection and expansion to the "packages" in extras.
55 in lib.mapAttrs (k: v: if k != "packages"
56 then v
57 else lib.mapAttrs (_: pkg: (expand-paths (inject-revision pkg))) v)
58 (inject-packages extras);
59 # fold any potential `pkg-def-extras`
60 # onto the `pkg-def`.
61 #
62 # This means you can have a base definition (e.g. stackage)
63 # and augment it with custom packages to your liking.
64 in foldl' lib.recursiveUpdate
65 (pkg-def hackage)
66 (map (p: desugar (if builtins.isFunction p then p hackage else p)) pkg-def-extras)
67 ;
69 })
71 # Supplies metadata
72 ./modules/cabal.nix
74 # Converts config.packages into config.hsPkgs
75 # Replace this with compat-driver.nix to use nixpkgs haskell build infra
76 ./modules/component-driver.nix
78 # Converts config.hackage.db to config.hackage.configs
79 ./modules/hackage.nix
81 # Converts config.hackage.configs and pkg-def to config.packages
82 ./modules/plan.nix
84 # Configuration that applies to all plans
85 ./modules/configuration-nix.nix
86 ];
87};
88in f