about summary refs log tree commit diff
path: root/nixos/modules/installer
diff options
context:
space:
mode:
authorThomas Strobel <ts468@cam.ac.uk>2016-02-20 01:47:01 +0100
committerThomas Strobel <ts468@cam.ac.uk>2016-02-29 01:09:00 +0100
commitcad8957eabcbf73062226d28366fd446c15c8737 (patch)
tree0299e96391c14f612e7bd1cf3b2274198425fd61 /nixos/modules/installer
parentc483224c82c8e94324c03576e64c5dfbf16bd2f8 (diff)
downloadnixlib-cad8957eabcbf73062226d28366fd446c15c8737.tar
nixlib-cad8957eabcbf73062226d28366fd446c15c8737.tar.gz
nixlib-cad8957eabcbf73062226d28366fd446c15c8737.tar.bz2
nixlib-cad8957eabcbf73062226d28366fd446c15c8737.tar.lz
nixlib-cad8957eabcbf73062226d28366fd446c15c8737.tar.xz
nixlib-cad8957eabcbf73062226d28366fd446c15c8737.tar.zst
nixlib-cad8957eabcbf73062226d28366fd446c15c8737.zip
Add the tool "nixos-typecheck" that can check an option declaration to:
 - Enforce that an option declaration has a "defaultText" if and only if the
   type of the option derives from "package", "packageSet" or "nixpkgsConfig"
   and if a "default" attribute is defined.

 - Enforce that the value of the "example" attribute is wrapped with "literalExample"
   if the type of the option derives from "package", "packageSet" or "nixpkgsConfig".

 - Warn if a "defaultText" is defined in an option declaration if the type of
   the option does not derive from "package", "packageSet" or "nixpkgsConfig".

 - Warn if no "type" is defined in an option declaration.
Diffstat (limited to 'nixos/modules/installer')
-rw-r--r--nixos/modules/installer/tools/nixos-option.sh4
-rw-r--r--nixos/modules/installer/tools/nixos-typecheck.sh52
-rw-r--r--nixos/modules/installer/tools/tools.nix8
3 files changed, 61 insertions, 3 deletions
diff --git a/nixos/modules/installer/tools/nixos-option.sh b/nixos/modules/installer/tools/nixos-option.sh
index 17c17d05e288..dd21dc71ee2b 100644
--- a/nixos/modules/installer/tools/nixos-option.sh
+++ b/nixos/modules/installer/tools/nixos-option.sh
@@ -115,8 +115,8 @@ let
       let name = head attrsNames; rest = tail attrsNames; in
       if isOption result.options then
         walkOptions rest {
-          options = result.options.type.getSubOptions "";
-          opt = ''(\${result.opt}.type.getSubOptions "")'';
+          options = result.options.type.getSubOptionsPrefix "";
+          opt = ''(\${result.opt}.type.getSubOptionsPrefix "")'';
           cfg = ''\${result.cfg}."\${name}"'';
         }
       else
diff --git a/nixos/modules/installer/tools/nixos-typecheck.sh b/nixos/modules/installer/tools/nixos-typecheck.sh
new file mode 100644
index 000000000000..f9557be0c50e
--- /dev/null
+++ b/nixos/modules/installer/tools/nixos-typecheck.sh
@@ -0,0 +1,52 @@
+#! /bin/sh
+#! @shell@
+
+if [ -x "@shell@" ]; then export SHELL="@shell@"; fi;
+
+set -e
+
+showSyntax() {
+cat >&1 << EOF
+nixos-typecheck
+usage:
+  nixos-typecheck [action] [args]
+where:
+  action = silent | printAll | printUnspecified | getSpecs
+    with default action: printUnspecified
+  args = any argument supported by nix-build
+EOF
+}
+
+
+# Parse the command line.
+extraArgs=()
+action=printUnspecified
+
+while [ "$#" -gt 0 ]; do
+    i="$1"; shift 1
+    case "$i" in
+      --help)
+        showSyntax
+        ;;
+      silent|printAll|printUnspecified|getSpecs)
+        action="$i"
+        ;;
+      *)
+        extraArgs="$extraArgs $i"
+        ;;
+    esac
+done
+
+
+if [ "$action" = silent ]; then
+    nix-build --no-out-link '<nixpkgs/nixos>' -A typechecker.silent $extraArgs
+elif [ "$action" = printAll ]; then
+    nix-build --no-out-link '<nixpkgs/nixos>' -A typechecker.printAll $extraArgs
+elif [ "$action" = printUnspecified ]; then
+    nix-build --no-out-link '<nixpkgs/nixos>' -A typechecker.printUnspecified $extraArgs
+elif [ "$action" = getSpecs ]; then
+    ln -s $(nix-build --no-out-link '<nixpkgs/nixos>' -A typechecker.specifications $extraArgs)/share/doc/nixos/options-specs.json specifications.json
+else
+    showSyntax
+    exit 1
+fi
diff --git a/nixos/modules/installer/tools/tools.nix b/nixos/modules/installer/tools/tools.nix
index 9ac3b7a5b16f..69bd0d26b773 100644
--- a/nixos/modules/installer/tools/tools.nix
+++ b/nixos/modules/installer/tools/tools.nix
@@ -54,6 +54,11 @@ let
     inherit (config.system) nixosVersion nixosCodeName nixosRevision;
   };
 
+  nixos-typecheck = makeProg {
+    name = "nixos-typecheck";
+    src = ./nixos-typecheck.sh;
+  };
+
 in
 
 {
@@ -67,10 +72,11 @@ in
         nixos-generate-config
         nixos-option
         nixos-version
+        nixos-typecheck
       ];
 
     system.build = {
-      inherit nixos-install nixos-generate-config nixos-option nixos-rebuild;
+      inherit nixos-install nixos-generate-config nixos-option nixos-rebuild nixos-typecheck;
     };
 
   };