Skip to content

Commit b0b6867

Browse files
committed
wip: simplifying tools handling in buildRig via coercedTo
1 parent ed7d8fe commit b0b6867

File tree

2 files changed

+33
-57
lines changed

2 files changed

+33
-57
lines changed

lib/buildRig.nix

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,7 @@ let
7878
riglet.meta
7979
// {
8080
# Add computed command names to each riglet's metadata
81-
commandNames =
82-
let
83-
normalized = normalizeTools riglet.tools;
84-
in
85-
map getToolMainProgramName (normalized.wrapped ++ normalized.unwrapped);
81+
commandNames = map getToolMainProgramName (riglet.tools.wrapped ++ riglet.tools.unwrapped);
8682
}
8783
) evaluated.config.riglets;
8884

@@ -92,32 +88,10 @@ let
9288
paths = map (riglet: riglet.configFiles) (attrValues evaluated.config.riglets);
9389
};
9490

95-
normalizeTools =
96-
tools:
97-
let
98-
# Normalize a tool item: if it's a path, wrap it with wrapScriptPath; otherwise return as-is
99-
normalizeOne = tool: if builtins.isPath tool then riglib.wrapScriptPath tool else tool;
100-
in
101-
if builtins.isList tools then
102-
{
103-
wrapped = map normalizeOne tools;
104-
unwrapped = [ ];
105-
}
106-
else
107-
{
108-
wrapped = map normalizeOne tools.wrapped;
109-
unwrapped = map normalizeOne tools.unwrapped;
110-
};
111-
112-
accumRigletTools =
113-
acc: riglet:
114-
let
115-
normalized = normalizeTools riglet.tools;
116-
in
117-
{
118-
wrapped = acc.wrapped ++ normalized.wrapped;
119-
unwrapped = acc.unwrapped ++ normalized.unwrapped;
120-
};
91+
accumRigletTools = acc: riglet: {
92+
wrapped = acc.wrapped ++ riglet.tools.wrapped;
93+
unwrapped = acc.unwrapped ++ riglet.tools.unwrapped;
94+
};
12195

12296
wrapWithConfigHome =
12397
tools:

lib/rigletSchema.nix

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
11
# rigup flake's self
2-
_flake:
2+
flake:
33
# Base module that defines common riglet structure
44
{ pkgs, ... }:
55
with pkgs.lib;
66
let
7-
packageLike = types.oneOf [
8-
types.package
9-
types.path
10-
];
7+
riglib = flake.lib.mkRiglib { inherit pkgs; };
8+
9+
packageLike = types.coercedTo types.path riglib.wrapScriptPath types.package;
1110

1211
packageList = types.listOf packageLike;
1312

14-
toolset = types.oneOf [
15-
# If just a list of packages is given as a toolset, these tools are considered _wrapped_:
16-
packageList
17-
# Else, for more explicit control over which tools should be wrapped and which should not,
18-
# the toolset can be given as a { wrapped = [...]; unwrapped [...]; } attrset:
19-
(types.submodule {
20-
options = {
21-
wrapped = mkOption {
22-
description = "Tools that should be wrapped to use the rig's isolated XDG_CONFIG_HOME";
23-
type = packageList;
24-
default = [ ];
25-
};
26-
unwrapped = mkOption {
27-
description = "Tools that must directly use the user's XDG_CONFIG_HOME";
28-
type = packageList;
29-
default = [ ];
30-
};
31-
};
32-
})
33-
];
13+
toolset =
14+
types.coercedTo
15+
# If just a list of packages is given as a toolset, these tools are considered _wrapped_:
16+
packageList
17+
(x: { wrapped = x; })
18+
# Else, for more explicit control over which tools should be wrapped and which should not,
19+
# the toolset can be given as a { wrapped = [...]; unwrapped [...]; } attrset:
20+
(
21+
types.submodule {
22+
options = {
23+
wrapped = mkOption {
24+
description = "Tools that should be wrapped to use the rig's isolated XDG_CONFIG_HOME";
25+
type = packageList;
26+
default = [ ];
27+
};
28+
unwrapped = mkOption {
29+
description = "Tools that must directly use the user's XDG_CONFIG_HOME";
30+
type = packageList;
31+
default = [ ];
32+
};
33+
};
34+
}
35+
);
3436

3537
localMcpServer = types.submodule {
3638
options.command = mkOption {
@@ -238,7 +240,7 @@ in
238240
Optional entrypoint for the rig. Only ONE riglet in a rig should define this.
239241
Takes the rig attrset and should return a folder derivation with a SINGLE bin/xxx executable (e.g. via pkgs.writeShellScriptBin).
240242
'';
241-
type = types.nullOr (types.functionTo packageLike);
243+
type = types.nullOr (types.functionTo types.package);
242244
default = null;
243245
};
244246

0 commit comments

Comments
 (0)