2.home-manager/modules/programs/password-store.nix
Austin Horstman 1eb0549a1a password-store: silence settings default warning
Use the deferred state-version helper mode for programs.password-store.settings
so explicit empty and explicit legacy values silence the warning correctly,
while partial legacy-era settings still inherit PASSWORD_STORE_DIR until the
user resolves the migration.

Add integration coverage for password-store and pass-secret-service to verify
legacy, explicit empty, explicit legacy, and partial-settings behavior.

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
2026-03-24 14:08:36 -05:00

86 lines
2.3 KiB
Nix

{
config,
lib,
options,
pkgs,
...
}:
let
inherit (lib) literalExpression mkOption types;
cfg = config.programs.password-store;
settingsStateVersion = lib.hm.deprecations.mkStateVersionOptionDefault {
inherit (config.home) stateVersion;
inherit config options;
since = "25.11";
optionPath = [
"programs"
"password-store"
"settings"
];
legacy = {
value = {
PASSWORD_STORE_DIR = "${config.xdg.dataHome}/password-store";
};
text = ''{ PASSWORD_STORE_DIR = "$XDG_DATA_HOME/password-store"; }'';
};
current.value = { };
deferWarningToConfig = true;
};
legacyCompatibleSettings =
lib.optionalAttrs settingsStateVersion.shouldWarn settingsStateVersion.effectiveDefault
// cfg.settings;
in
{
meta.maintainers = with lib.maintainers; [ euxane ];
options.programs.password-store = {
enable = lib.mkEnableOption "Password store";
package = lib.mkPackageOption pkgs "pass" {
example = "pkgs.pass.withExtensions (exts: [ exts.pass-otp ])";
extraDescription = "Can be used to specify extensions.";
};
settings = mkOption {
type = with types; attrsOf str;
inherit (settingsStateVersion) default defaultText;
example = literalExpression ''
{
PASSWORD_STORE_DIR = "$\{config.xdg.dataHome\}/password-store";
PASSWORD_STORE_KEY = "12345678";
PASSWORD_STORE_CLIP_TIME = "60";
}
'';
description = ''
The `pass` environment variables dictionary.
See the "Environment variables" section of
{manpage}`pass(1)`
and the extension man pages for more information about the
available keys.
'';
};
};
config = lib.mkIf cfg.enable {
warnings = lib.optional settingsStateVersion.shouldWarn settingsStateVersion.warning;
home = {
packages = [ cfg.package ];
sessionVariables = legacyCompatibleSettings;
};
services.pass-secret-service =
lib.mkIf (builtins.hasAttr "PASSWORD_STORE_DIR" legacyCompatibleSettings)
{
storePath = legacyCompatibleSettings.PASSWORD_STORE_DIR;
};
xsession.importedVariables = lib.mkIf config.xsession.enable (
lib.mapAttrsToList (name: _value: name) legacyCompatibleSettings
);
};
}