nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ config, lib, ... }:
2let
3 inherit (builtins)
4 storeDir
5 ;
6 inherit (lib)
7 types
8 mkOption
9 ;
10
11 m = {
12 options = {
13 enableQux = mkOption {
14 type = types.bool;
15 default = false;
16 };
17 };
18 };
19in
20{
21 options = {
22 check = mkOption { };
23 # NB: types are tested in multiple places, so this list is far from exhaustive
24 pathInStore = mkOption { type = types.lazyAttrsOf types.pathInStore; };
25 attrNamesToTrue = mkOption { type = types.lazyAttrsOf types.attrNamesToTrue; };
26 attrNamesToSet = mkOption { type = types.lazyAttrsOf types.attrNamesToSet; };
27 attrNamesToSubmodules = mkOption { type = types.lazyAttrsOf (types.attrNamesToSubmodules m); };
28 };
29 config = {
30 pathInStore.ok1 = "${storeDir}/0lz9p8xhf89kb1c1kk6jxrzskaiygnlh-bash-5.2-p15.drv";
31 pathInStore.ok2 = "${storeDir}/0fb3ykw9r5hpayd05sr0cizwadzq1d8q-bash-5.2-p15";
32 pathInStore.ok3 = "${storeDir}/0fb3ykw9r5hpayd05sr0cizwadzq1d8q-bash-5.2-p15/bin/bash";
33 pathInStore.bad1 = "";
34 pathInStore.bad2 = "${storeDir}";
35 pathInStore.bad3 = "${storeDir}/";
36 pathInStore.bad4 = "${storeDir}/.links"; # technically true, but not reasonable
37 pathInStore.bad5 = "/foo/bar";
38 attrNamesToTrue.justNames = [
39 "a"
40 "b"
41 "c"
42 ];
43 attrNamesToTrue.mixed = lib.mkMerge [
44 {
45 a = true;
46 b = false;
47 }
48 [ "c" ]
49 ];
50 attrNamesToTrue.trivial = {
51 a = true;
52 b = false;
53 c = true;
54 };
55 attrNamesToSet.justNames = [
56 "a"
57 "b"
58 "c"
59 ];
60 attrNamesToSet.mixed = lib.mkMerge [
61 {
62 a = { };
63 b = { };
64 }
65 [ "c" ]
66 ];
67 attrNamesToSet.trivial = {
68 a = { };
69 b = { };
70 c = { };
71 };
72 attrNamesToSubmodules.justNames = [
73 "a"
74 "b"
75 "c"
76 ];
77 attrNamesToSubmodules.mixed = lib.mkMerge [
78 {
79 a = { };
80 b.enableQux = true;
81 }
82 [ "c" ]
83 ];
84 attrNamesToSubmodules.trivial = {
85 a = { };
86 b.enableQux = true;
87 c = { };
88 };
89 check =
90 assert
91 config.attrNamesToTrue.justNames == {
92 a = true;
93 b = true;
94 c = true;
95 };
96 assert
97 config.attrNamesToTrue.mixed == {
98 a = true;
99 b = false;
100 c = true;
101 };
102 assert
103 config.attrNamesToTrue.trivial == {
104 a = true;
105 b = false;
106 c = true;
107 };
108 assert
109 config.attrNamesToSet.justNames == {
110 a = { };
111 b = { };
112 c = { };
113 };
114 assert
115 config.attrNamesToSet.mixed == {
116 a = { };
117 b = { };
118 c = { };
119 };
120 assert
121 config.attrNamesToSet.trivial == {
122 a = { };
123 b = { };
124 c = { };
125 };
126 assert
127 config.attrNamesToSubmodules.justNames == {
128 a.enableQux = false;
129 b.enableQux = false;
130 c.enableQux = false;
131 };
132 assert
133 config.attrNamesToSubmodules.mixed == {
134 a.enableQux = false;
135 b.enableQux = true;
136 c.enableQux = false;
137 };
138 assert
139 config.attrNamesToSubmodules.trivial == {
140 a.enableQux = false;
141 b.enableQux = true;
142 c.enableQux = false;
143 };
144 "ok";
145 };
146}