on angerman/src-dist help sign in
haskell.nix/dimension.nix
114 lines 3.0 kB history raw
1# Borrowed from https://github.com/cachix/ghcide-nix/pull/4/files#diff-70bfff902f4dec33e545cac10ee5844d
2# Tweaked to use builtins.mapAttrs instead of needing the one from nixpkgs lib
3{
4 /*
5 dimension: name -> attrs -> function -> attrs
6 where
7 function: keyText -> value -> attrsOf package
9 WARNING: Attribute names must not contain periods (".").
10 See https://github.com/NixOS/nix/issues/3088
12 NOTE: The dimension name will be picked up by agent and web ui soon.
14 Specifies a dimension of the build matrix. For example
16 dimension "Example" {
17 withP = { p = true; }
18 withoutP = { p = false; }
19 } (key: # either "withP" or "withoutP"
20 { p }: # either p = true or p = false
21 myProject p
22 )
24 evaluates roughly to
26 {
27 withP = myProject true;
28 withoutP = myProject false;
29 }
31 Use nested calls for multiple dimensions.
33 Example:
35 dimension "System" {
36 "x86_64-linux" = {};
37 # ...
38 }: (system: {}:
40 dimension "Nixpkgs release" (
41 {
42 "nixpkgs-19_03".nixpkgs = someSource
43 } // optionalAttrs (system != "...") {
44 "nixpkgs-unstable".nixpkgs = someOtherSource
45 }
46 ) (_key: { nixpkgs }:
48 myProject system nixpkgs
50 )
51 )
53 evaluates roughly to
55 {
56 x86_64-linux.nixpkgs-19_03 = myProject "x86_64-linux" someSource;
57 x86_64-linux.nixpkgs-unstable = myProject "x86_64-linux" someOtherSource;
58 ...
59 }
61 If you need to make references across attributes, you can do so by binding
62 the result. Wherever you write
64 dimension "My dimension" {} (key: value: f1 key value)
66 You can also write
68 let
69 myDimension = dimension "My dimension" {} (key: value: f2 key value myDimension)
70 in
71 myDimension
73 This example builds a single test runner to reuse across releases:
75 let
76 overlay =
77 testRunnerPkgs: self: super: {
78 # ...
79 };
80 myProject =
81 { nixpkgs,
82 pkgs ? import nixpkgs { overlays = [ overlay ]; },
83 testRunnerPkgs ? pkgs
84 }: pkgs;
85 in
87 let
88 latest = "nixpkgs-19_03";
89 releases =
90 dimension "Nixpkgs release"
91 {
92 nixpkgs-18_09.nixpkgs = someSource
93 nixpkgs-19_03.nixpkgs = someOtherSource
94 }
95 (_key: { nixpkgs }:
97 myProject {
98 inherit nixpkgs;
99 testRunnerPkgs = releases."${latest}";
100 }
102 );
103 in releases;
105 */
106 dimension = name: attrs: f:
107 builtins.mapAttrs
108 (k: v:
109 let o = f k v;
110 in o // { recurseForDerivations = o.recurseForDerivations or true; }
111 )
112 attrs
113 // { meta.dimension.name = name; };