on imp/fix-cabal-patches help sign in
haskell.nix/package-set.nix
103 lines 4.3 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 ({ config, 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; inherit (pkgs) stdenv runCommand recurseIntoAttrs git srcOnly; 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 # pkg-def's may reference boot packages, but those
27 # are not guaranteed to be available on hackage, as
28 # it is a manual process. They might eventually show
29 # up much later on hackage; but are not installable
30 # anyway. Therefore we just strip them out of the
31 # pkg-def's packages.
32 #
33 # Note: these will need to be provided by alternative
34 # means outside of hackage.
35 let strip-pkg-def = pkg-def: hackage:
36 lib.mapAttrs (k: v: if k == "packages"
37 then lib.filterAttrs (k: _: !(builtins.elem k config.bootPkgs)) v
38 else v)
39 (pkg-def hackage);
40 in let pkg-def' = strip-pkg-def pkg-def;
41 # The desugar reason.
42 #
43 # it is quite combersome to write
44 # (hackage: { packages.x.revision = hackage...;
45 # packages.y.revision = import ./foo.nix; })
46 # where we'd rather write:
47 # (hackage: { x = hackage...; })
48 # or
49 # { y = ./foo.nix; }
50 # As such the desugarer desugars this short hand syntax.
51 in let desugar = extras:
52 let
53 isPath = x: builtins.typeOf x == "path";
54 # rewrite
55 # { ... }
56 # into
57 # { package = { ... }; }
58 inject-packages = o: if o ? "packages" then o else { packages = o; };
59 # rewrite
60 # x = pkg;
61 # into
62 # x.revision = pkg;
63 inject-revision = pkg: if pkg ? "revision" then pkg else { revision = pkg; };
64 # rewrite
65 # x.revision = ./some/path;
66 # into
67 # x.revision = import ./some/path;
68 expand-paths = pkg: if !(isPath pkg.revision) then pkg else { revision = import pkg.revision; };
69 # apply injection and expansion to the "packages" in extras.
70 in lib.mapAttrs (k: v: if k != "packages"
71 then v
72 else lib.mapAttrs (_: pkg: (expand-paths (inject-revision pkg))) v)
73 (inject-packages extras);
74 # fold any potential `pkg-def-extras`
75 # onto the `pkg-def`.
76 #
77 # This means you can have a base definition (e.g. stackage)
78 # and augment it with custom packages to your liking.
79 in foldl' lib.recursiveUpdate
80 (pkg-def' hackage)
81 (map (p: desugar (if builtins.isFunction p then p hackage else p)) pkg-def-extras)
82 ;
84 })
86 # Supplies metadata
87 ./modules/cabal.nix
89 # Converts config.packages into config.hsPkgs
90 # Replace this with compat-driver.nix to use nixpkgs haskell build infra
91 ./modules/component-driver.nix
93 # Converts config.hackage.db to config.hackage.configs
94 ./modules/hackage.nix
96 # Converts config.hackage.configs and pkg-def to config.packages
97 ./modules/plan.nix
99 # Configuration that applies to all plans
100 ./modules/configuration-nix.nix
101 ];
102};
103in f