summary refs log tree commit diff
path: root/nixos/lib
diff options
context:
space:
mode:
authorpennae <github@quasiparticle.net>2021-12-18 19:37:41 +0100
committerpennae <github@quasiparticle.net>2022-01-02 19:46:13 +0100
commit50954ad1c5847e04fe78fa155fed97ee52dcb9f6 (patch)
treec69cc5c22c72b1475c566d796b666200f06b30e3 /nixos/lib
parent1301bdb185c4d0d7c30d0400d76eae8669b5b64d (diff)
downloadnixpkgs-50954ad1c5847e04fe78fa155fed97ee52dcb9f6.tar
nixpkgs-50954ad1c5847e04fe78fa155fed97ee52dcb9f6.tar.gz
nixpkgs-50954ad1c5847e04fe78fa155fed97ee52dcb9f6.tar.bz2
nixpkgs-50954ad1c5847e04fe78fa155fed97ee52dcb9f6.tar.lz
nixpkgs-50954ad1c5847e04fe78fa155fed97ee52dcb9f6.tar.xz
nixpkgs-50954ad1c5847e04fe78fa155fed97ee52dcb9f6.tar.zst
nixpkgs-50954ad1c5847e04fe78fa155fed97ee52dcb9f6.zip
nixos/make-options-doc: treat missing descriptions as errors by default
this partially solves the problem of "missing description" warnings of the
options doc build being lost by nix build, at the cost of failing builds that
previously ran. an option to disable this behaviour is provided.
Diffstat (limited to 'nixos/lib')
-rw-r--r--nixos/lib/make-options-doc/default.nix4
-rw-r--r--nixos/lib/make-options-doc/mergeJSON.py20
2 files changed, 20 insertions, 4 deletions
diff --git a/nixos/lib/make-options-doc/default.nix b/nixos/lib/make-options-doc/default.nix
index cc4ddd55d02..57652dd5db1 100644
--- a/nixos/lib/make-options-doc/default.nix
+++ b/nixos/lib/make-options-doc/default.nix
@@ -25,6 +25,9 @@
 # used to split the options doc build into a static part (nixos/modules) and a dynamic part
 # (non-nixos modules imported via configuration.nix, other module sources).
 , baseOptionsJSON ? null
+# instead of printing warnings for eg options with missing descriptions (which may be lost
+# by nix build unless -L is given), emit errors instead and fail the build
+, warningsAreErrors ? true
 }:
 
 let
@@ -121,6 +124,7 @@ in rec {
           then "cp $options $dst/options.json"
           else ''
             ${pkgs.python3Minimal}/bin/python ${./mergeJSON.py} \
+              ${lib.optionalString warningsAreErrors "--warnings-are-errors"} \
               ${baseOptionsJSON} $options \
               > $dst/options.json
           ''
diff --git a/nixos/lib/make-options-doc/mergeJSON.py b/nixos/lib/make-options-doc/mergeJSON.py
index b7dfe2b88e7..029787a3158 100644
--- a/nixos/lib/make-options-doc/mergeJSON.py
+++ b/nixos/lib/make-options-doc/mergeJSON.py
@@ -41,8 +41,10 @@ def unpivot(options: Dict[Key, Option]) -> Dict[str, JSON]:
         result[opt.name] = opt.value
     return result
 
-options = pivot(json.load(open(sys.argv[1], 'r')))
-overrides = pivot(json.load(open(sys.argv[2], 'r')))
+warningsAreErrors = sys.argv[1] == "--warnings-are-errors"
+optOffset = 1 if warningsAreErrors else 0
+options = pivot(json.load(open(sys.argv[1 + optOffset], 'r')))
+overrides = pivot(json.load(open(sys.argv[2 + optOffset], 'r')))
 
 # fix up declaration paths in lazy options, since we don't eval them from a full nixpkgs dir
 for (k, v) in options.items():
@@ -65,10 +67,20 @@ for (k, v) in overrides.items():
             cur[ok] = ov
 
 # check that every option has a description
-# TODO: nixos-rebuild with flakes may hide the warning, maybe turn on -L by default for those?
+hasWarnings = False
 for (k, v) in options.items():
     if v.value.get('description', None) is None:
-        print(f"\x1b[1;31mwarning: option {v.name} has no description\x1b[0m", file=sys.stderr)
+        severity = "error" if warningsAreErrors else "warning"
+        hasWarnings = True
+        print(f"\x1b[1;31m{severity}: option {v.name} has no description\x1b[0m", file=sys.stderr)
         v.value['description'] = "This option has no description."
+if hasWarnings and warningsAreErrors:
+    print(
+        "\x1b[1;31m" +
+        "Treating warnings as errors. Set documentation.nixos.options.warningsAreErrors " +
+        "to false to ignore these warnings." +
+        "\x1b[0m",
+        file=sys.stderr)
+    sys.exit(1)
 
 json.dump(unpivot(options), fp=sys.stdout)