From 6ad7575d6f6416f1e7098e4b3cf7572977e90246 Mon Sep 17 00:00:00 2001 From: Alexander Nortung Date: Sun, 22 Jan 2023 20:31:23 +0100 Subject: [PATCH] Added assertions --- lib/option-warnings.nix | 18 ++++++++++-------- modules/warnings.nix | 5 +++++ wrappers/darwin.nix | 14 ++++++++++---- wrappers/hm.nix | 1 + wrappers/nixos.nix | 1 + 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/lib/option-warnings.nix b/lib/option-warnings.nix index bedf8e3c..658e7a02 100644 --- a/lib/option-warnings.nix +++ b/lib/option-warnings.nix @@ -1,31 +1,33 @@ { lib, ... }: with lib; -rec { +{ + # This should be used instead of mkRemovedOptionModule, when the option still works, + # but is just deprecated and should be changed now and for the future mkDeprecatedOption = { option # an array of the path to the option , alternative ? null , message ? null , visible ? false - , ... }: { options, ... }: let fromOpt = getAttrFromPath option options; - fullMessage = "The option `${showOption option}` has been deprecated." + + fullMessage = "The option `${showOption option}` has been deprecated, but might still work." + (optionalString (alternative != null) " You may want to use `${showOption alternative}` instead.") + (optionalString (message != null) " Message: ${message}"); in { - options = setAttrByPath option - (mkOption { - inherit visible; - description = fullMessage; - }); config = mkIf (fromOpt.isDefined) { warnings = [ ("Nixvim: ${fullMessage}") ]; }; }; + + # For removed options, we can just use nixpkgs mkRemovedOptionModule, which is already in lib + mkRemovedOption = mkRemovedOptionModule; + + # For renamed options, we can also use the function from nixpkgs + mkRenamedOption = mkRenamedOptionModule; # use the function from nixpkgs } diff --git a/modules/warnings.nix b/modules/warnings.nix index 52c5fc80..27905187 100644 --- a/modules/warnings.nix +++ b/modules/warnings.nix @@ -8,5 +8,10 @@ with lib; visible = false; default = []; }; + assertions = mkOption { + type = types.listOf types.attrs; # Not sure what the correct type is here + visible = false; + default = []; + }; }; } diff --git a/wrappers/darwin.nix b/wrappers/darwin.nix index 1a51535b..0267a40b 100644 --- a/wrappers/darwin.nix +++ b/wrappers/darwin.nix @@ -11,13 +11,19 @@ in programs.nixvim = mkOption { type = types.submodule ((modules pkgs) ++ [{ options.enable = mkEnableOption "nixvim"; - config.wrapRc = mkForce true; + config.wrapRc = mkForce true; }]); }; nixvim.helpers = shared.helpers; }; - config = mkIf cfg.enable { - environment.systemPackages = [ cfg.finalPackage ]; - }; + config = mkIf cfg.enable mkMerge [ + { + environment.systemPackages = [ cfg.finalPackage ]; + } + { + warnings = cfg.warnings; + assertions = cfg.assertions; + } + ]; } diff --git a/wrappers/hm.nix b/wrappers/hm.nix index 8d860aea..971c255a 100644 --- a/wrappers/hm.nix +++ b/wrappers/hm.nix @@ -24,6 +24,7 @@ in }) ({ warnings = cfg.warnings; + assertions = cfg.assertions; }) ]); } diff --git a/wrappers/nixos.nix b/wrappers/nixos.nix index 326cd8e5..66eadbcb 100644 --- a/wrappers/nixos.nix +++ b/wrappers/nixos.nix @@ -25,6 +25,7 @@ in }) ({ warnings = cfg.warnings; + assertions = cfg.assertions; }) ]); }