1
0
mirror of https://github.com/nix-community/home-manager synced 2024-06-02 21:13:33 +02:00

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 <robert@rycee.net>
This commit is contained in:
polykernel 2021-08-27 23:01:24 -04:00 committed by Robert Helgesson
parent 275f39611d
commit 039f786e60
No known key found for this signature in database
GPG Key ID: 36BDAA14C2797E89
5 changed files with 22 additions and 43 deletions

View File

@ -6,7 +6,7 @@ let
cfg = config.services.fnott; cfg = config.services.fnott;
concatStringsSep' = sep: list: concatStringsSep' = sep: list:
concatStringsSep sep (filter (str: str != "") list); concatStringsSep sep (filter (x: x != "") list);
mkKeyValue = generators.mkKeyValueDefault { } "="; mkKeyValue = generators.mkKeyValueDefault { } "=";
genINI = generators.toINI { }; genINI = generators.toINI { };
@ -31,6 +31,15 @@ in {
description = "Package providing <command>fnott</command>."; description = "Package providing <command>fnott</command>.";
}; };
extraFlags = mkOption {
type = types.listOf types.str;
default = [ ];
example = [ "-s" ];
description = ''
Extra arguments to use for executing fnott.
'';
};
configFile = mkOption { configFile = mkOption {
type = types.either types.str types.path; type = types.either types.str types.path;
default = "${config.xdg.configHome}/fnott/fnott.ini"; 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 { settings = mkOption {
type = iniFormatType; type = iniFormatType;
default = { }; default = { };
@ -107,24 +107,21 @@ in {
Type = "dbus"; Type = "dbus";
BusName = "org.freedesktop.Notifications"; BusName = "org.freedesktop.Notifications";
ExecStart = concatStringsSep' " " [ ExecStart = concatStringsSep' " " [
"${cfg.package}/bin/fnott -c ${cfg.configFile}" "${cfg.package}/bin/fnott"
"-c ${escapeShellArg cfg.configFile}"
(escapeShellArgs cfg.extraFlags) (escapeShellArgs cfg.extraFlags)
]; ];
}; };
}; };
# FIXME: Remove after next version release (https://codeberg.org/dnkl/fnott/pulls/24). xdg.configFile."fnott/fnott.ini" = {
xdg.configFile."fnott/fnott.ini" = mkIf (cfg.settings != { }) (mkMerge [ # FIXME: Remove after next version release (https://codeberg.org/dnkl/fnott/pulls/24).
{ text = genINI cfg.settings; } text = concatStringsSep' "\n" [
(mkIf (cfg.settings ? main) { (optionalString (cfg.settings ? main) ''
text = mkForce (concatStringsSep' "\n" [ ${concatStringsSep "\n" (mapAttrsToList mkKeyValue cfg.settings.main)}
'' '')
${concatStringsSep "\n" (genINI (removeAttrs cfg.settings [ "main" ]))
(mapAttrsToList mkKeyValue cfg.settings.main)} ];
'' };
(genINI (removeAttrs cfg.settings [ "main" ]))
]);
})
]);
}; };
} }

View File

@ -1,5 +1,4 @@
{ {
fnott-empty-settings = ./empty-settings.nix;
fnott-example-settings = ./example-settings.nix; fnott-example-settings = ./example-settings.nix;
fnott-global-properties = ./global-properties.nix; fnott-global-properties = ./global-properties.nix;
fnott-systemd-user-service = ./systemd-user-service.nix; fnott-systemd-user-service = ./systemd-user-service.nix;

View File

@ -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
'';
};
}

View File

@ -1,6 +1,6 @@
[Service] [Service]
BusName=org.freedesktop.Notifications 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 Type=dbus
[Unit] [Unit]

View File

@ -8,8 +8,6 @@
}; };
nmt.script = '' nmt.script = ''
assertPathNotExists home-files/.config/fnott/fnott.ini
assertFileContent \ assertFileContent \
home-files/.config/systemd/user/fnott.service \ home-files/.config/systemd/user/fnott.service \
${./systemd-user-service-expected.service} ${./systemd-user-service-expected.service}