diff --git a/modules/programs/keepassxc.nix b/modules/programs/keepassxc.nix index eb7ae6e2c..6b6c63380 100644 --- a/modules/programs/keepassxc.nix +++ b/modules/programs/keepassxc.nix @@ -46,16 +46,36 @@ in for the full list of options. ''; }; + + autostart = lib.mkOption { + type = lib.types.bool; + default = false; + example = true; + description = '' + Whether to start Keepassxc automatically on login through the XDG autostart mechanism. + ''; + }; }; config = lib.mkIf cfg.enable ( lib.mkMerge [ { - xdg.configFile = { - "keepassxc/keepassxc.ini" = lib.mkIf (cfg.settings != { }) { - source = iniFormat.generate "keepassxc-settings" cfg.settings; - }; + assertions = [ + { + assertion = cfg.autostart -> config.xdg.autostart.enable; + message = '' + {option}`xdg.autostart.enable` has to be enabled in order for + {option}`programs.keepassxc.autostart` to be effective. + ''; + } + ]; + + xdg.autostart.entries = lib.mkIf cfg.autostart [ + "${cfg.package}/share/applications/org.keepassxc.KeePassXC.desktop" + ]; + xdg.configFile."keepassxc/keepassxc.ini" = lib.mkIf (cfg.settings != { }) { + source = iniFormat.generate "keepassxc-settings" cfg.settings; }; } diff --git a/tests/modules/programs/keepassxc/autostart.nix b/tests/modules/programs/keepassxc/autostart.nix new file mode 100644 index 000000000..481e8f458 --- /dev/null +++ b/tests/modules/programs/keepassxc/autostart.nix @@ -0,0 +1,14 @@ +{ + programs.keepassxc = { + enable = true; + autostart = true; + }; + xdg.autostart.enable = false; + + test.asserts.assertions.expected = [ + '' + {option}`xdg.autostart.enable` has to be enabled in order for + {option}`programs.keepassxc.autostart` to be effective. + '' + ]; +} diff --git a/tests/modules/programs/keepassxc/default.nix b/tests/modules/programs/keepassxc/default.nix index 14c949763..1aafed561 100644 --- a/tests/modules/programs/keepassxc/default.nix +++ b/tests/modules/programs/keepassxc/default.nix @@ -1,4 +1,5 @@ { + keepassxc-autostart = ./autostart.nix; keepassxc-default-settings = ./default-settings.nix; keepassxc-example-settings = ./example-settings.nix; }