From 46a69810cb95d2e7286089830dc535d6719eaa6f Mon Sep 17 00:00:00 2001 From: polykernel <81340136+polykernel@users.noreply.github.com> Date: Thu, 14 Oct 2021 23:39:01 -0400 Subject: [PATCH] fnott: remove global properties generation Rationale: As of release 1.1.2[1], the configuration ini file supports declaration of the `[main]` header as an alternative to global properties by enumerating all sections and mapping each to the respective parsing function. Global properties will still be parsed correctly by fnott however generation adds unnecessary complexity to the module. This commit removes the need for global properties generation. Changes: - Fixed the FIXME at L118. - Cleaned up unneeded let bindings. - Changed the generation method to use the `pkgs.formats.ini` from pkgs-lib instead of the raw `generators` library. This was done for consistency and clarity as the `pkgs.formats.ini` is still required for type declaration and uses `generators` internally. - Removed `global-properties` testcase. - Updated `example-settings` testcase. [1] - https://codeberg.org/dnkl/fnott/releases/tag/1.1.2 --- modules/services/fnott.nix | 23 ++++-------------- tests/modules/services/fnott/default.nix | 1 - .../fnott/example-settings-expected.ini | 5 ++-- .../fnott/global-properties-expected.ini | 2 -- .../services/fnott/global-properties.nix | 24 ------------------- 5 files changed, 7 insertions(+), 48 deletions(-) delete mode 100644 tests/modules/services/fnott/global-properties-expected.ini delete mode 100644 tests/modules/services/fnott/global-properties.nix diff --git a/modules/services/fnott.nix b/modules/services/fnott.nix index 5aaf525aa..d4e2addb4 100644 --- a/modules/services/fnott.nix +++ b/modules/services/fnott.nix @@ -8,15 +8,7 @@ let concatStringsSep' = sep: list: concatStringsSep sep (filter (x: x != "") list); - mkKeyValue = generators.mkKeyValueDefault { } "="; - genINI = generators.toINI { }; - - iniFormatType = with types; - let - iniAtom = types.nullOr (types.oneOf [ bool int float str ]) // { - description = "INI atom (null, bool, int, float or string)"; - }; - in attrsOf (attrsOf iniAtom); + iniFormat = pkgs.formats.ini { }; in { options = { services.fnott = { @@ -58,7 +50,7 @@ in { }; settings = mkOption { - type = iniFormatType; + type = iniFormat.type; default = { }; description = '' Configuration written to @@ -114,14 +106,7 @@ in { }; }; - xdg.configFile."fnott/fnott.ini" = { - # FIXME: Remove after next version release (https://codeberg.org/dnkl/fnott/pulls/24). - text = concatStringsSep' "\n" [ - (optionalString (cfg.settings ? main) '' - ${concatStringsSep "\n" (mapAttrsToList mkKeyValue cfg.settings.main)} - '') - (genINI (removeAttrs cfg.settings [ "main" ])) - ]; - }; + xdg.configFile."fnott/fnott.ini".source = + iniFormat.generate "fnott.ini" cfg.settings; }; } diff --git a/tests/modules/services/fnott/default.nix b/tests/modules/services/fnott/default.nix index 6b4bde383..e28250a48 100644 --- a/tests/modules/services/fnott/default.nix +++ b/tests/modules/services/fnott/default.nix @@ -1,5 +1,4 @@ { fnott-example-settings = ./example-settings.nix; - fnott-global-properties = ./global-properties.nix; fnott-systemd-user-service = ./systemd-user-service.nix; } diff --git a/tests/modules/services/fnott/example-settings-expected.ini b/tests/modules/services/fnott/example-settings-expected.ini index 153e456ca..6293f63d2 100644 --- a/tests/modules/services/fnott/example-settings-expected.ini +++ b/tests/modules/services/fnott/example-settings-expected.ini @@ -1,6 +1,7 @@ -notification-margin=5 - [low] timeout=5 title-color=ffffff title-font=Dina:weight=bold:slant=italic + +[main] +notification-margin=5 diff --git a/tests/modules/services/fnott/global-properties-expected.ini b/tests/modules/services/fnott/global-properties-expected.ini deleted file mode 100644 index a82646797..000000000 --- a/tests/modules/services/fnott/global-properties-expected.ini +++ /dev/null @@ -1,2 +0,0 @@ -max-icon-size=32 -notification-margin=5 diff --git a/tests/modules/services/fnott/global-properties.nix b/tests/modules/services/fnott/global-properties.nix deleted file mode 100644 index 3be88d787..000000000 --- a/tests/modules/services/fnott/global-properties.nix +++ /dev/null @@ -1,24 +0,0 @@ -{ config, lib, pkgs, ... }: - -# FIXME: Deprecate on next version release of fnott (https://codeberg.org/dnkl/fnott/pulls/24). -{ - config = { - services.fnott = { - enable = true; - package = config.lib.test.mkStubPackage { }; - - settings = { - main = { - max-icon-size = 32; - notification-margin = 5; - }; - }; - }; - - nmt.script = '' - assertFileContent \ - home-files/.config/fnott/fnott.ini \ - ${./global-properties-expected.ini} - ''; - }; -}