From 4deba95f3fae35940271c8d54a39760272d307d8 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 75f8ac461..953d1706b 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -138,6 +138,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 000000000..5ea097be0 --- /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 2eaaaa436..76c04b5db 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -95,6 +95,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 000000000..c8171cba4 --- /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 000000000..14c949763 --- /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 000000000..359b3f757 --- /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 000000000..fe0c2b15b --- /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