Skip to content

Commit dbabf36

Browse files
committed
Refactor checkPlugins using lib.throwIf
1 parent 4c4a471 commit dbabf36

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

flake.nix

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
in
88
{
99
lib.packagesFromVersionsFile =
10+
1011
{ versionsFile
1112
, system ? builtins.currentSystem
1213
, plugins ? { }
@@ -29,32 +30,34 @@
2930
let
3031
hasPlugin = builtins.hasAttr name plugins;
3132
in
32-
if skipMissingPlugins
33-
then builtins.traceVerbose (if hasPlugin then "Plugin ${name} found" else "Skipping plugin ${name}") hasPlugin
34-
else hasPlugin || throw ''
35-
No plugin found for "${name}", try adding the missing plugin:
33+
lib.throwIf (!skipMissingPlugins && !hasPlugin)
34+
''
35+
No plugin found for "${name}", try adding the missing plugin:
3636
37-
```
38-
asdf2nix.lib.packagesFromToolVersions = {
39-
plugins = {
40-
${name} = asdf-${name}.lib.packageFromVersion;
37+
```
38+
asdf2nix.lib.packagesFromToolVersions = {
39+
plugins = {
40+
${name} = asdf-${name}.lib.packageFromVersion;
41+
...
42+
};
4143
...
4244
};
43-
...
44-
};
45-
```
45+
```
4646
47-
Or enable `skipMissingPlugins` to skip this error:
47+
Or enable `skipMissingPlugins` to skip this error:
4848
49-
```
50-
asdf2nix.lib.packagesFromToolVersions = {
51-
plugins = { ... };
52-
skipMissingPlugins = true;
53-
...
54-
};
55-
```
56-
'');
57-
findPackage = plugin: version: plugins.${plugin} { inherit system version; };
49+
```
50+
asdf2nix.lib.packagesFromToolVersions = {
51+
plugins = { ... };
52+
skipMissingPlugins = true;
53+
...
54+
};
55+
```
56+
''
57+
hasPlugin);
58+
findPackage = plugin: version: plugins.${plugin} {
59+
inherit system version;
60+
};
5861
in
5962
builtins.mapAttrs findPackage
6063
(builtins.listToAttrs

0 commit comments

Comments
 (0)