Skip to content

Commit 37d4af4

Browse files
committed
refactor: expose project types as an option
which allows us to easily re-use them without inside the module system with the proper arguments.
1 parent 1c76776 commit 37d4af4

File tree

10 files changed

+65
-59
lines changed

10 files changed

+65
-59
lines changed

maintainers/types/default.nix

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,47 @@
33
...
44
}@args:
55
let
6-
inherit (lib.types)
7-
submodule
6+
inherit (lib)
7+
types
8+
mkOption
89
;
10+
11+
submodule =
12+
modules:
13+
types.submodule {
14+
imports = [
15+
{
16+
config._module.args = args // {
17+
ngiTypes = options.ngiTypes.default;
18+
};
19+
}
20+
]
21+
++ lib.toList modules;
22+
};
23+
24+
options.ngiTypes = mkOption {
25+
type = with types; attrs;
26+
default = {
27+
binary = submodule ./binary.nix;
28+
demo = submodule ./demo.nix;
29+
example = submodule ./example.nix;
30+
link = submodule ./link.nix;
31+
metadata = submodule ./metadata.nix;
32+
problem = import ./problem.nix args;
33+
program = submodule (import ./module.nix { type = "program"; });
34+
plugin = submodule ./plugin.nix;
35+
project = submodule ./project.nix;
36+
projects = mkOption {
37+
type = with types; attrsOf (submodule ./project.nix);
38+
description = "NGI-funded software application";
39+
};
40+
service = submodule (import ./module.nix { type = "service"; });
41+
subgrant = submodule ./subgrant.nix;
42+
test = submodule ./test.nix;
43+
};
44+
description = "";
45+
};
946
in
1047
{
11-
binary = submodule ./binary.nix;
12-
demo = submodule ./demo.nix;
13-
example = submodule ./example.nix;
14-
link = submodule ./link.nix;
15-
metadata = submodule ./metadata.nix;
16-
problem = import ./problem.nix args;
17-
program = submodule (import ./module.nix { type = "program"; });
18-
plugin = submodule ./plugin.nix;
19-
project = submodule ./project.nix;
20-
service = submodule (import ./module.nix { type = "service"; });
21-
subgrant = submodule ./subgrant.nix;
22-
test = submodule ./test.nix;
48+
inherit options;
2349
}

maintainers/types/demo.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
{
8888
lib,
8989
name,
90+
ngiTypes,
9091
...
9192
}:
9293

@@ -96,8 +97,6 @@ let
9697
mkOption
9798
;
9899

99-
ngiTypes = import ./. { inherit lib; };
100-
101100
inherit (ngiTypes)
102101
example
103102
problem

maintainers/types/example.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
{
4040
lib,
4141
name,
42+
ngiTypes,
4243
...
4344
}:
4445

@@ -48,8 +49,6 @@ let
4849
mkOption
4950
;
5051

51-
ngiTypes = import ./. { inherit lib; };
52-
5352
inherit (ngiTypes)
5453
test
5554
link

maintainers/types/metadata.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
{
1717
lib,
18+
ngiTypes,
1819
...
1920
}:
2021

@@ -24,8 +25,6 @@ let
2425
mkOption
2526
;
2627

27-
ngiTypes = import ./. { inherit lib; };
28-
2928
inherit (ngiTypes)
3029
link
3130
subgrant

maintainers/types/module.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ assert builtins.elem type [
9494
{
9595
lib,
9696
name,
97+
ngiTypes,
9798
...
9899
}:
99100

@@ -103,8 +104,6 @@ let
103104
mkOption
104105
;
105106

106-
ngiTypes = import ./. { inherit lib; };
107-
108107
inherit (ngiTypes)
109108
example
110109
link

maintainers/types/project.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
{
4343
lib,
4444
name,
45+
ngiTypes,
4546
...
4647
}:
4748
let
@@ -50,8 +51,6 @@ let
5051
mkOption
5152
;
5253

53-
ngiTypes = import ./. { inherit lib; };
54-
5554
inherit (ngiTypes)
5655
metadata
5756
binary

maintainers/types/projects.nix

Lines changed: 0 additions & 24 deletions
This file was deleted.

maintainers/types/test.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
*/
4040
{
4141
lib,
42+
ngiTypes,
4243
...
4344
}:
4445

@@ -48,8 +49,6 @@ let
4849
mkOption
4950
;
5051

51-
ngiTypes = import ./. { inherit lib; };
52-
5352
inherit (ngiTypes)
5453
problem
5554
;

overview/default.nix

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@ let
1717
toString
1818
;
1919

20-
ngiTypes = import ../maintainers/types { inherit lib; };
21-
22-
moduleArgs = {
23-
config._module.args.pkgs = pkgs;
24-
config._module.args.utils = utils;
25-
config._module.args.ngiTypes = ngiTypes;
26-
config._module.args.modulesPath = "${self.inputs.nixpkgs}/nixos/modules";
27-
};
20+
moduleArgs =
21+
{ options, ... }:
22+
{
23+
imports = [ ../maintainers/types ];
24+
25+
config._module.args.pkgs = pkgs;
26+
config._module.args.utils = utils;
27+
config._module.args.ngiTypes = options.ngiTypes.default;
28+
config._module.args.toplevelOptions = options;
29+
config._module.args.modulesPath = "${self.inputs.nixpkgs}/nixos/modules";
30+
};
2831

2932
submoduleWithArgs =
3033
modules:

projects/default.nix

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ let
4242
in
4343
rec {
4444
raw-projects = {
45-
imports = [ ../maintainers/types/projects.nix ];
45+
imports = [ ../maintainers/types ];
4646
config.projects = mapAttrs (name: directory: import directory args) projectDirectories;
4747
};
4848

@@ -59,6 +59,13 @@ rec {
5959
_module.args = args;
6060
};
6161
}
62+
# TODO: flatten when we fully migrate to the module system
63+
(
64+
{ options, ... }:
65+
{
66+
options.projects = options.ngiTypes.default.projects;
67+
}
68+
)
6269
];
6370
};
6471

0 commit comments

Comments
 (0)