|
9 | 9 | inherit (builtins)
|
10 | 10 | filter
|
11 | 11 | head
|
| 12 | + length |
12 | 13 | map
|
13 | 14 | match
|
| 15 | + partition |
| 16 | + toString |
14 | 17 | ;
|
15 | 18 | inherit (lib.strings) concatMapStringsSep removePrefix removeSuffix;
|
| 19 | + inherit (lib.lists) last; |
16 | 20 | inherit (lib.attrsets) isDerivation;
|
17 | 21 | inherit (lib.options)
|
18 | 22 | isOption
|
|
37 | 41 |
|
38 | 42 | # Bad options do not use `literalExpression` in their `defaultText`,
|
39 | 43 | # or have a `defaultText` that doesn't start with "pkgs."
|
40 |
| - badOptions = filter ( |
41 |
| - opt: |
42 |
| - opt.defaultText._type or null != "literalExpression" |
43 |
| - || match ''pkgs[.].*'' (opt.defaultText.text or "") == null |
44 |
| - ) drvOptions; |
| 44 | + badOptions = lib.pipe drvOptions [ |
| 45 | + (filter ( |
| 46 | + opt: |
| 47 | + opt.defaultText._type or null != "literalExpression" |
| 48 | + || match ''pkgs[.].*'' (opt.defaultText.text or "") == null |
| 49 | + )) |
| 50 | + # Treat `plugins.*.package` errors as warnings |
| 51 | + # TODO: upgrade these to errors once all plugins are migrated |
| 52 | + (partition (opt: length opt.loc == 3 && last opt.loc == "package")) |
| 53 | + ( |
| 54 | + { right, wrong }: |
| 55 | + { |
| 56 | + warnings = right; |
| 57 | + errors = wrong; |
| 58 | + } |
| 59 | + ) |
| 60 | + ]; |
| 61 | + |
| 62 | + # Error strings to print |
| 63 | + toErrorStrings = |
| 64 | + let |
| 65 | + # A little hack to get the flake's source in the nix store |
| 66 | + # We will use this to make the option declaration sources more readable |
| 67 | + src = removeSuffix "modules/top-level/output.nix" ( |
| 68 | + head evaluatedNixvim.options.package.declarations |
| 69 | + ); |
| 70 | + in |
| 71 | + map ( |
| 72 | + opt: |
| 73 | + let |
| 74 | + # The default, as rendered in documentation. Will always be a literalExpression. |
| 75 | + default = builtins.addErrorContext "while evaluating the default text for `${showOption opt.loc}`" ( |
| 76 | + renderOptionValue (opt.defaultText or opt.default) |
| 77 | + ); |
| 78 | + in |
| 79 | + '' |
| 80 | + - ${showOption opt.loc} (${default.text}), declared in: |
| 81 | + ${concatMapStringsSep "\n" (file: " - ${removePrefix src file}") opt.declarations} |
| 82 | + '' |
| 83 | + ); |
| 84 | + |
| 85 | + # Used to print warnings during eval |
| 86 | + showWarnings = |
| 87 | + if badOptions.warnings == [ ] then |
| 88 | + lib.id |
| 89 | + else |
| 90 | + lib.warn '' |
| 91 | +
|
| 92 | + Found ${toString (length badOptions.warnings)} warnings: |
| 93 | + ${lib.concatStrings (toErrorStrings badOptions.warnings)} |
| 94 | + (${toString (length badOptions.warnings)} options with warnings) |
| 95 | + ''; |
45 | 96 | in
|
46 | 97 | runCommandNoCCLocal "validate-package-options"
|
47 |
| - { |
| 98 | + (showWarnings { |
48 | 99 | # Use structuredAttrs to avoid "Argument List Too Long" errors
|
49 | 100 | # and get proper bash array support.
|
50 | 101 | __structuredAttrs = true;
|
51 | 102 |
|
52 | 103 | # Passthroughs for debugging purposes
|
53 | 104 | passthru = {
|
54 | 105 | inherit evaluatedNixvim drvOptions badOptions;
|
| 106 | + warnings = toErrorStrings badOptions.warnings; |
55 | 107 | };
|
56 | 108 |
|
57 | 109 | # Error strings to print
|
58 |
| - errors = |
59 |
| - let |
60 |
| - # A little hack to get the flake's source in the nix store |
61 |
| - # We will use this to make the option declaration sources more readable |
62 |
| - src = removeSuffix "modules/top-level/output.nix" (head evaluatedNixvim.options.package.declarations); |
63 |
| - in |
64 |
| - map ( |
65 |
| - opt: |
66 |
| - let |
67 |
| - # The default, as rendered in documentation. Will always be a literalExpression. |
68 |
| - default = builtins.addErrorContext "while evaluating the default text for `${showOption opt.loc}`" ( |
69 |
| - renderOptionValue (opt.defaultText or opt.default) |
70 |
| - ); |
71 |
| - in |
72 |
| - '' |
73 |
| - - ${showOption opt.loc} (${default.text}), declared in: |
74 |
| - ${concatMapStringsSep "\n" (file: " - ${removePrefix src file}") opt.declarations} |
75 |
| - '' |
76 |
| - ) badOptions; |
77 |
| - } |
| 110 | + errors = toErrorStrings badOptions.errors; |
| 111 | + }) |
78 | 112 | ''
|
79 | 113 | if [ -n "$errors" ]; then
|
80 |
| - echo "Found ''${#errors[@]} issues:" |
| 114 | + echo "Found ''${#errors[@]} errors:" |
81 | 115 | for err in "''${errors[@]}"; do
|
82 | 116 | echo "$err"
|
83 | 117 | done
|
84 |
| - echo "(''${#errors[@]} options with issues)" |
| 118 | + echo "(''${#errors[@]} options with errors)" |
85 | 119 | exit 1
|
86 | 120 | fi
|
87 | 121 | touch $out
|
|
0 commit comments