From b08b0bcbbec77046e5a7082177cedc12fbf1dc6c Mon Sep 17 00:00:00 2001 From: Robin Gloster Date: Wed, 25 Sep 2019 17:13:29 +0200 Subject: [PATCH] mkRemovedOptionModule: assert on removed options We don't want to ignore config that can mess up machines. In general this should always fail evaluation, as you think you are changing behaviour and don't, which can easily create run-time errors we can catch early. --- lib/modules.nix | 11 +++++++---- .../monitoring/prometheus/exporters/nginx.nix | 2 +- nixos/modules/tasks/network-interfaces.nix | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/modules.nix b/lib/modules.nix index c3c903c1dfa..00c7712487b 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -592,11 +592,14 @@ rec { { options = setAttrByPath optionName (mkOption { visible = false; }); - config.warnings = - let opt = getAttrFromPath optionName options; in - optional opt.isDefined '' + config.assertions = + let opt = getAttrFromPath optionName options; in [{ + assertion = !opt.isDefined; + message = '' The option definition `${showOption optionName}' in ${showFiles opt.files} no longer has any effect; please remove it. - ${replacementInstructions}''; + ${replacementInstructions} + ''; + }]; }; /* Return a module that causes a warning to be shown if the diff --git a/nixos/modules/services/monitoring/prometheus/exporters/nginx.nix b/nixos/modules/services/monitoring/prometheus/exporters/nginx.nix index 554377df37b..ba852fea433 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters/nginx.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters/nginx.nix @@ -49,6 +49,6 @@ in (mkRemovedOptionModule [ "insecure" ] '' This option was replaced by 'prometheus.exporters.nginx.sslVerify'. '') - ({ options.warnings = options.warnings; }) + ({ options.warnings = options.warnings; options.assertions = options.assertions; }) ]; } diff --git a/nixos/modules/tasks/network-interfaces.nix b/nixos/modules/tasks/network-interfaces.nix index 5bf7b0d227f..ee3ae2e91f2 100644 --- a/nixos/modules/tasks/network-interfaces.nix +++ b/nixos/modules/tasks/network-interfaces.nix @@ -305,7 +305,7 @@ let optional (defined ipv6Address && defined ipv6PrefixLength) { address = ipv6Address; prefixLength = ipv6PrefixLength; })) - ({ options.warnings = options.warnings; }) + ({ options.warnings = options.warnings; options.assertions = options.assertions; }) ]; };