on iko/ghcjs-patch-master help sign in
Adds desugar logic.
2a3b261Moritz Angermann
new-package-set.nix+35−2
@@ -23,14 +23,47 @@ in pkgs.lib.evalModules {
23
23
24 # Set the plan for modules/plan.nix
24 # Set the plan for modules/plan.nix
25 plan.pkg-def = hackage: with builtins;
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 = overlay:
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 overlay.
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 overlay);
26 # fold any potential `pkg-def-overlays`
59 # fold any potential `pkg-def-overlays`
27 # onto the `pkg-def`.
60 # onto the `pkg-def`.
28 #
61 #
29 # This means you can have a base definition (e.g. stackage)
62 # This means you can have a base definition (e.g. stackage)
30 # and augment it with custom packages to your liking.
63 # and augment it with custom packages to your liking.
31− foldl' lib.recursiveUpdate
64+ in foldl' lib.recursiveUpdate
32 (pkg-def hackage)
65 (pkg-def hackage)
33− (map (p: p hackage) pkg-def-overlays)
66+ (map (p: desugar (if builtins.isFunction p then p hackage else p)) pkg-def-overlays)
34 ;
67 ;
35
68
36 })
69 })