2019-02-08 04:21:54 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.keychain;
|
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
flags = cfg.extraFlags ++ optional (cfg.agents != [ ])
|
|
|
|
"--agents ${concatStringsSep "," cfg.agents}"
|
2019-02-08 04:21:54 +00:00
|
|
|
++ optional (cfg.inheritType != null) "--inherit ${cfg.inheritType}";
|
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
shellCommand =
|
|
|
|
"${cfg.package}/bin/keychain --eval ${concatStringsSep " " flags} ${
|
|
|
|
concatStringsSep " " cfg.keys
|
|
|
|
}";
|
2019-02-08 04:21:54 +00:00
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
in {
|
2019-02-08 04:21:54 +00:00
|
|
|
meta.maintainers = [ maintainers.marsam ];
|
|
|
|
|
|
|
|
options.programs.keychain = {
|
|
|
|
enable = mkEnableOption "keychain";
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.keychain;
|
2019-08-27 22:12:28 +00:00
|
|
|
defaultText = literalExample "pkgs.keychain";
|
2019-02-08 04:21:54 +00:00
|
|
|
description = ''
|
|
|
|
Keychain package to install.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
keys = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ "id_rsa" ];
|
|
|
|
description = ''
|
|
|
|
Keys to add to keychain.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
agents = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2020-02-01 23:39:17 +00:00
|
|
|
default = [ ];
|
2019-02-08 04:21:54 +00:00
|
|
|
description = ''
|
|
|
|
Agents to add.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
inheritType = mkOption {
|
2020-02-01 23:39:17 +00:00
|
|
|
type =
|
|
|
|
types.nullOr (types.enum [ "local" "any" "local-once" "any-once" ]);
|
2019-02-08 04:21:54 +00:00
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Inherit type to attempt from agent variables from the environment.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraFlags = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ "--quiet" ];
|
|
|
|
description = ''
|
|
|
|
Extra flags to pass to keychain.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
enableBashIntegration = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Whether to enable Bash integration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-12-27 09:56:47 +00:00
|
|
|
enableFishIntegration = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Whether to enable Fish integration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-02-08 04:21:54 +00:00
|
|
|
enableZshIntegration = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Whether to enable Zsh integration.
|
|
|
|
'';
|
|
|
|
};
|
2019-12-28 16:14:03 +00:00
|
|
|
|
|
|
|
enableXsessionIntegration = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
visible = pkgs.stdenv.hostPlatform.isLinux;
|
|
|
|
description = ''
|
|
|
|
Whether to run keychain from your <filename>~/.xsession</filename>.
|
|
|
|
'';
|
|
|
|
};
|
2019-02-08 04:21:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
home.packages = [ cfg.package ];
|
2019-12-27 09:56:47 +00:00
|
|
|
programs.bash.initExtra = mkIf cfg.enableBashIntegration ''
|
|
|
|
eval "$(${shellCommand})"
|
|
|
|
'';
|
|
|
|
programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration ''
|
|
|
|
eval (${shellCommand})
|
|
|
|
'';
|
|
|
|
programs.zsh.initExtra = mkIf cfg.enableZshIntegration ''
|
|
|
|
eval "$(${shellCommand})"
|
|
|
|
'';
|
2019-12-28 16:14:03 +00:00
|
|
|
xsession.initExtra = mkIf cfg.enableXsessionIntegration ''
|
|
|
|
eval "$(${shellCommand})"
|
|
|
|
'';
|
2019-02-08 04:21:54 +00:00
|
|
|
};
|
|
|
|
}
|