From be33c3f932af4ff6949a55327fa49f885bb7e4fa Mon Sep 17 00:00:00 2001 From: d-brasher <175485311+d-brasher@users.noreply.github.com> Date: Tue, 16 Jul 2024 21:34:38 +0200 Subject: [PATCH] keepassxc: add module --- modules/modules.nix | 1 + modules/programs/keepassxc.nix | 50 +++++++++++++++++++ tests/default.nix | 1 + .../programs/keepassxc/default-settings.nix | 11 ++++ tests/modules/programs/keepassxc/default.nix | 4 ++ .../programs/keepassxc/example-settings.nix | 24 +++++++++ .../keepassxc/keepassxc-example-config.ini | 11 ++++ 7 files changed, 102 insertions(+) create mode 100644 modules/programs/keepassxc.nix create mode 100644 tests/modules/programs/keepassxc/default-settings.nix create mode 100644 tests/modules/programs/keepassxc/default.nix create mode 100644 tests/modules/programs/keepassxc/example-settings.nix create mode 100644 tests/modules/programs/keepassxc/keepassxc-example-config.ini diff --git a/modules/modules.nix b/modules/modules.nix index dbeebfbf..2dbf17b6 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -135,6 +135,7 @@ let ./programs/just.nix ./programs/k9s.nix ./programs/kakoune.nix + ./programs/keepassxc.nix ./programs/keychain.nix ./programs/khal.nix ./programs/khard.nix diff --git a/modules/programs/keepassxc.nix b/modules/programs/keepassxc.nix new file mode 100644 index 00000000..5ea097be --- /dev/null +++ b/modules/programs/keepassxc.nix @@ -0,0 +1,50 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.programs.keepassxc; + + iniFormat = pkgs.formats.ini { }; +in { + meta.maintainers = [ lib.maintainers.d-brasher ]; + + options.programs.keepassxc = { + enable = lib.mkEnableOption "keepassxc"; + + package = lib.mkPackageOption pkgs "keepassxc" { }; + + 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. + ''; + }; + }; + + config = lib.mkIf cfg.enable { + home.packages = [ cfg.package ]; + xdg.configFile = { + "keepassxc/keepassxc.ini" = lib.mkIf (cfg.settings != { }) { + source = iniFormat.generate "keepassxc-settings" cfg.settings; + }; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 28ce4f64..2459703e 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -92,6 +92,7 @@ in import nmtSrc { ./modules/programs/joplin-desktop ./modules/programs/k9s ./modules/programs/kakoune + ./modules/programs/keepassxc ./modules/programs/khal ./modules/programs/khard ./modules/programs/kitty diff --git a/tests/modules/programs/keepassxc/default-settings.nix b/tests/modules/programs/keepassxc/default-settings.nix new file mode 100644 index 00000000..c8171cba --- /dev/null +++ b/tests/modules/programs/keepassxc/default-settings.nix @@ -0,0 +1,11 @@ +{ ... }: + +{ + programs.keepassxc = { enable = true; }; + + test.stubs.keepassxc = { }; + + nmt.script = '' + assertPathNotExists home-files/.config/keepassxc/keepassxc.ini + ''; +} diff --git a/tests/modules/programs/keepassxc/default.nix b/tests/modules/programs/keepassxc/default.nix new file mode 100644 index 00000000..14c94976 --- /dev/null +++ b/tests/modules/programs/keepassxc/default.nix @@ -0,0 +1,4 @@ +{ + keepassxc-default-settings = ./default-settings.nix; + keepassxc-example-settings = ./example-settings.nix; +} diff --git a/tests/modules/programs/keepassxc/example-settings.nix b/tests/modules/programs/keepassxc/example-settings.nix new file mode 100644 index 00000000..359b3f75 --- /dev/null +++ b/tests/modules/programs/keepassxc/example-settings.nix @@ -0,0 +1,24 @@ +{ ... }: + +{ + programs.keepassxc = { + enable = true; + settings = { + Browser.Enabled = true; + GUI = { + AdvancedSettings = true; + ApplicationTheme = "dark"; + CompactMode = true; + HidePasswords = true; + }; + SSHAgent.Enabled = true; + }; + }; + + test.stubs.keepassxc = { }; + + nmt.script = '' + configFile=home-files/.config/keepassxc/keepassxc.ini + assertFileContent $configFile ${./keepassxc-example-config.ini} + ''; +} diff --git a/tests/modules/programs/keepassxc/keepassxc-example-config.ini b/tests/modules/programs/keepassxc/keepassxc-example-config.ini new file mode 100644 index 00000000..fe0c2b15 --- /dev/null +++ b/tests/modules/programs/keepassxc/keepassxc-example-config.ini @@ -0,0 +1,11 @@ +[Browser] +Enabled=true + +[GUI] +AdvancedSettings=true +ApplicationTheme=dark +CompactMode=true +HidePasswords=true + +[SSHAgent] +Enabled=true