From 039f786e609fdb3cfd9c5520ff3791750c3eaebf Mon Sep 17 00:00:00 2001 From: polykernel <81340136+polykernel@users.noreply.github.com> Date: Fri, 27 Aug 2021 23:01:24 -0400 Subject: [PATCH] fnott: refactor module - Change generation behavior to always generate a configuration file and pass it explicitly to fnott, it enforces the module to be hermetic instead of offloading the configuration selection to heuristics. - Various style changes. - Fix issue where fnott would abort due to an invalid config file when both the configFile and settings options are unset. - Remove the empty-settings test as a configuration file is now already generated. Suggested-by: Robert Helgesson --- modules/services/fnott.nix | 45 +++++++++---------- tests/modules/services/fnott/default.nix | 1 - .../modules/services/fnott/empty-settings.nix | 15 ------- .../systemd-user-service-expected.service | 2 +- .../services/fnott/systemd-user-service.nix | 2 - 5 files changed, 22 insertions(+), 43 deletions(-) delete mode 100644 tests/modules/services/fnott/empty-settings.nix diff --git a/modules/services/fnott.nix b/modules/services/fnott.nix index a6a1aa690..0e3254f49 100644 --- a/modules/services/fnott.nix +++ b/modules/services/fnott.nix @@ -6,7 +6,7 @@ let cfg = config.services.fnott; concatStringsSep' = sep: list: - concatStringsSep sep (filter (str: str != "") list); + concatStringsSep sep (filter (x: x != "") list); mkKeyValue = generators.mkKeyValueDefault { } "="; genINI = generators.toINI { }; @@ -31,6 +31,15 @@ in { description = "Package providing fnott."; }; + extraFlags = mkOption { + type = types.listOf types.str; + default = [ ]; + example = [ "-s" ]; + description = '' + Extra arguments to use for executing fnott. + ''; + }; + configFile = mkOption { type = types.either types.str types.path; default = "${config.xdg.configHome}/fnott/fnott.ini"; @@ -48,15 +57,6 @@ in { ''; }; - extraFlags = mkOption { - type = types.listOf types.str; - default = [ ]; - example = [ "-s" ]; - description = '' - Extra arguments to use for executing fnott. - ''; - }; - settings = mkOption { type = iniFormatType; default = { }; @@ -107,24 +107,21 @@ in { Type = "dbus"; BusName = "org.freedesktop.Notifications"; ExecStart = concatStringsSep' " " [ - "${cfg.package}/bin/fnott -c ${cfg.configFile}" + "${cfg.package}/bin/fnott" + "-c ${escapeShellArg cfg.configFile}" (escapeShellArgs cfg.extraFlags) ]; }; }; - # FIXME: Remove after next version release (https://codeberg.org/dnkl/fnott/pulls/24). - xdg.configFile."fnott/fnott.ini" = mkIf (cfg.settings != { }) (mkMerge [ - { text = genINI cfg.settings; } - (mkIf (cfg.settings ? main) { - text = mkForce (concatStringsSep' "\n" [ - '' - ${concatStringsSep "\n" - (mapAttrsToList mkKeyValue cfg.settings.main)} - '' - (genINI (removeAttrs cfg.settings [ "main" ])) - ]); - }) - ]); + 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" ])) + ]; + }; }; } diff --git a/tests/modules/services/fnott/default.nix b/tests/modules/services/fnott/default.nix index 4ce849ff5..6b4bde383 100644 --- a/tests/modules/services/fnott/default.nix +++ b/tests/modules/services/fnott/default.nix @@ -1,5 +1,4 @@ { - fnott-empty-settings = ./empty-settings.nix; 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/empty-settings.nix b/tests/modules/services/fnott/empty-settings.nix deleted file mode 100644 index 85d2c9d6a..000000000 --- a/tests/modules/services/fnott/empty-settings.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ config, lib, pkgs, ... }: - -{ - config = { - services.fnott = { - enable = true; - package = pkgs.writeScriptBin "dummy-fnott" ""; - settings = { }; - }; - - nmt.script = '' - assertPathNotExists home-files/.config/fnott - ''; - }; -} diff --git a/tests/modules/services/fnott/systemd-user-service-expected.service b/tests/modules/services/fnott/systemd-user-service-expected.service index c39a7b19b..1d09bfad5 100644 --- a/tests/modules/services/fnott/systemd-user-service-expected.service +++ b/tests/modules/services/fnott/systemd-user-service-expected.service @@ -1,6 +1,6 @@ [Service] BusName=org.freedesktop.Notifications -ExecStart=@fnott@/bin/fnott -c /home/hm-user/.config/fnott/fnott.ini +ExecStart=@fnott@/bin/fnott -c '/home/hm-user/.config/fnott/fnott.ini' Type=dbus [Unit] diff --git a/tests/modules/services/fnott/systemd-user-service.nix b/tests/modules/services/fnott/systemd-user-service.nix index a356f2ae9..05859277b 100644 --- a/tests/modules/services/fnott/systemd-user-service.nix +++ b/tests/modules/services/fnott/systemd-user-service.nix @@ -8,8 +8,6 @@ }; nmt.script = '' - assertPathNotExists home-files/.config/fnott/fnott.ini - assertFileContent \ home-files/.config/systemd/user/fnott.service \ ${./systemd-user-service-expected.service}