{ config, lib, pkgs, ... }: let cfg = config.programs.keepassxc; iniFormat = pkgs.formats.ini { }; in { meta.maintainers = with lib.maintainers; [ bmrips d-brasher ]; options.programs.keepassxc = { enable = lib.mkEnableOption "keepassxc"; package = lib.mkPackageOption pkgs "keepassxc" { nullable = true; }; settings = lib.mkOption { type = iniFormat.type; default = { }; example = lib.literalExpression '' { Browser.Enabled = true; GUI = { AdvancedSettings = true; ApplicationTheme = "dark"; CompactMode = true; HidePasswords = true; }; SSHAgent.Enabled = true; } ''; description = '' Configuration written to {file}`$XDG_CONFIG_HOME/keepassxc/keepassxc.ini`. See 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 [ { 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; }; } (lib.mkIf (cfg.package != null) { home.packages = [ cfg.package ]; programs.brave.nativeMessagingHosts = [ cfg.package ]; programs.chromium.nativeMessagingHosts = [ cfg.package ]; programs.firefox.nativeMessagingHosts = [ cfg.package ]; programs.floorp.nativeMessagingHosts = [ cfg.package ]; programs.vivaldi.nativeMessagingHosts = [ cfg.package ]; }) ] ); }