diff --git a/modules/services/flameshot.nix b/modules/services/flameshot.nix index 8a0d6db23..e30d82383 100644 --- a/modules/services/flameshot.nix +++ b/modules/services/flameshot.nix @@ -5,12 +5,35 @@ with lib; let cfg = config.services.flameshot; + package = pkgs.flameshot; + iniFormat = pkgs.formats.ini { }; + + iniFile = iniFormat.generate "flameshot.ini" cfg.settings; + in { meta.maintainers = [ maintainers.hamhut1066 ]; - options = { services.flameshot = { enable = mkEnableOption "Flameshot"; }; }; + options.services.flameshot = { + enable = mkEnableOption "Flameshot"; + + settings = mkOption { + type = iniFormat.type; + default = { }; + example = { + General = { + disabledTrayIcon = true; + showStartupLaunchMessage = false; + }; + }; + description = '' + Configuration to use for Flameshot. See + + for available options. + ''; + }; + }; config = mkIf cfg.enable { assertions = [ @@ -20,12 +43,17 @@ in { home.packages = [ package ]; + xdg.configFile = mkIf (cfg.settings != { }) { + "flameshot/flameshot.ini".source = iniFile; + }; + systemd.user.services.flameshot = { Unit = { Description = "Flameshot screenshot tool"; Requires = [ "tray.target" ]; After = [ "graphical-session-pre.target" "tray.target" ]; PartOf = [ "graphical-session.target" ]; + X-Restart-Triggers = mkIf (cfg.settings != { }) [ "${iniFile}" ]; }; Install = { WantedBy = [ "graphical-session.target" ]; }; diff --git a/tests/default.nix b/tests/default.nix index b08d74074..9694bc993 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -124,6 +124,7 @@ import nmt { ./modules/services/devilspie2 ./modules/services/dropbox ./modules/services/emacs + ./modules/services/flameshot ./modules/services/fluidsynth ./modules/services/fnott ./modules/services/git-sync diff --git a/tests/modules/services/flameshot/default.nix b/tests/modules/services/flameshot/default.nix new file mode 100644 index 000000000..826051f30 --- /dev/null +++ b/tests/modules/services/flameshot/default.nix @@ -0,0 +1,4 @@ +{ + flameshot-empty-settings = ./empty-settings.nix; + flameshot-example-settings = ./example-settings.nix; +} diff --git a/tests/modules/services/flameshot/empty-settings.nix b/tests/modules/services/flameshot/empty-settings.nix new file mode 100644 index 000000000..a5205660b --- /dev/null +++ b/tests/modules/services/flameshot/empty-settings.nix @@ -0,0 +1,13 @@ +{ ... }: + +{ + config = { + services.flameshot = { enable = true; }; + + test.stubs.flameshot = { }; + + nmt.script = '' + assertPathNotExists home-files/.config/flameshot/flameshot.ini + ''; + }; +} diff --git a/tests/modules/services/flameshot/example-settings.nix b/tests/modules/services/flameshot/example-settings.nix new file mode 100644 index 000000000..213e86b34 --- /dev/null +++ b/tests/modules/services/flameshot/example-settings.nix @@ -0,0 +1,30 @@ +{ ... }: + +{ + config = { + services.flameshot = { + enable = true; + + settings = { + General = { + disabledTrayIcon = true; + showStartupLaunchMessage = false; + }; + }; + }; + + test.stubs.flameshot = { }; + + nmt.script = '' + assertFileContent \ + home-files/.config/flameshot/flameshot.ini \ + ${ + builtins.toFile "expected.ini" '' + [General] + disabledTrayIcon=true + showStartupLaunchMessage=false + '' + } + ''; + }; +}