2019-02-08 05:21:54 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.keychain;
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
flags = cfg.extraFlags ++ optional (cfg.agents != [ ])
|
|
|
|
"--agents ${concatStringsSep "," cfg.agents}"
|
2019-02-08 05:21:54 +01:00
|
|
|
++ optional (cfg.inheritType != null) "--inherit ${cfg.inheritType}";
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
shellCommand =
|
|
|
|
"${cfg.package}/bin/keychain --eval ${concatStringsSep " " flags} ${
|
|
|
|
concatStringsSep " " cfg.keys
|
|
|
|
}";
|
2019-02-08 05:21:54 +01:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
in {
|
2023-06-22 10:16:28 +02:00
|
|
|
meta.maintainers = [ ];
|
2019-02-08 05:21:54 +01:00
|
|
|
|
|
|
|
options.programs.keychain = {
|
2023-07-01 01:30:13 +02:00
|
|
|
enable = mkEnableOption (lib.mdDoc "keychain");
|
2019-02-08 05:21:54 +01:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.keychain;
|
2021-10-09 11:14:08 +02:00
|
|
|
defaultText = literalExpression "pkgs.keychain";
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-02-08 05:21:54 +01:00
|
|
|
Keychain package to install.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
keys = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ "id_rsa" ];
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-02-08 05:21:54 +01:00
|
|
|
Keys to add to keychain.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
agents = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2020-02-02 00:39:17 +01:00
|
|
|
default = [ ];
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-02-08 05:21:54 +01:00
|
|
|
Agents to add.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
inheritType = mkOption {
|
2020-02-02 00:39:17 +01:00
|
|
|
type =
|
|
|
|
types.nullOr (types.enum [ "local" "any" "local-once" "any-once" ]);
|
2019-02-08 05:21:54 +01:00
|
|
|
default = null;
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-02-08 05:21:54 +01:00
|
|
|
Inherit type to attempt from agent variables from the environment.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraFlags = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ "--quiet" ];
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-02-08 05:21:54 +01:00
|
|
|
Extra flags to pass to keychain.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
enableBashIntegration = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-02-08 05:21:54 +01:00
|
|
|
Whether to enable Bash integration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-12-27 10:56:47 +01:00
|
|
|
enableFishIntegration = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-12-27 10:56:47 +01:00
|
|
|
Whether to enable Fish integration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-02-08 05:21:54 +01:00
|
|
|
enableZshIntegration = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-02-08 05:21:54 +01:00
|
|
|
Whether to enable Zsh integration.
|
|
|
|
'';
|
|
|
|
};
|
2019-12-28 17:14:03 +01:00
|
|
|
|
2023-02-13 19:49:31 +01:00
|
|
|
enableNushellIntegration = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2023-02-13 19:49:31 +01:00
|
|
|
Whether to enable Nushell integration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-12-28 17:14:03 +01:00
|
|
|
enableXsessionIntegration = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
visible = pkgs.stdenv.hostPlatform.isLinux;
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Whether to run keychain from your {file}`~/.xsession`.
|
2019-12-28 17:14:03 +01:00
|
|
|
'';
|
|
|
|
};
|
2019-02-08 05:21:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
home.packages = [ cfg.package ];
|
2019-12-27 10:56:47 +01:00
|
|
|
programs.bash.initExtra = mkIf cfg.enableBashIntegration ''
|
2022-06-30 01:02:38 +02:00
|
|
|
eval "$(SHELL=bash ${shellCommand})"
|
2019-12-27 10:56:47 +01:00
|
|
|
'';
|
|
|
|
programs.fish.interactiveShellInit = mkIf cfg.enableFishIntegration ''
|
2022-04-17 00:33:07 +02:00
|
|
|
SHELL=fish eval (${shellCommand})
|
2019-12-27 10:56:47 +01:00
|
|
|
'';
|
|
|
|
programs.zsh.initExtra = mkIf cfg.enableZshIntegration ''
|
2022-06-30 01:02:38 +02:00
|
|
|
eval "$(SHELL=zsh ${shellCommand})"
|
2019-12-27 10:56:47 +01:00
|
|
|
'';
|
2023-02-13 19:49:31 +01:00
|
|
|
programs.nushell.extraConfig = mkIf cfg.enableNushellIntegration ''
|
|
|
|
${shellCommand} | parse -r '(\w+)=(.*); export \1' | transpose -ird | load-env
|
|
|
|
'';
|
2019-12-28 17:14:03 +01:00
|
|
|
xsession.initExtra = mkIf cfg.enableXsessionIntegration ''
|
2023-02-26 19:55:27 +01:00
|
|
|
eval "$(SHELL=bash ${shellCommand})"
|
2019-12-28 17:14:03 +01:00
|
|
|
'';
|
2019-02-08 05:21:54 +01:00
|
|
|
};
|
|
|
|
}
|