Skip to content

Commit

Permalink
feat(nix): Add home-manager module for 1Password Shell Plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjones2014 committed Feb 29, 2024
1 parent 291d9e5 commit 81993de
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
13 changes: 5 additions & 8 deletions home-manager/modules/fish.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ let
echo $PASSWORD
'';
op-shell-plugins = [ "gh" ];
in {
home.sessionVariables = {
DOTNET_CLI_TELEMETRY_OPTOUT = "1";
Expand All @@ -30,8 +29,11 @@ in {
[ thefuck tealdeer tokei cachix _1password btop ]
++ lib.lists.optionals isLinux [ xclip ];

programs.gh.enable = true;

imports = [ ./op-shell-plugins.nix ];
programs.op-shell-plugins = {
enable = true;
plugins = with pkgs; [ gh ];
};
programs.fish = {
enable = true;

Expand Down Expand Up @@ -95,11 +97,6 @@ in {
fish_vi_key_bindings
bind -M insert jk "if commandline -P; commandline -f cancel; else; set fish_bind_mode default; commandline -f backward-char force-repaint; end"
export OP_PLUGIN_ALIASES_SOURCED=1
${lib.concatMapStrings
(plugin: ''alias ${plugin}="op plugin run -- ${plugin}"'')
op-shell-plugins}
# I like to keep the prompt at the bottom rather than the top
# of the terminal window so that running `clear` doesn't make
# me move my eyes from the bottom back to the top of the screen;
Expand Down
45 changes: 45 additions & 0 deletions home-manager/modules/op-shell-plugins.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{ lib, config, ... }:
with lib;
let cfg = config.programs.op-shell-plugins;
in {
options = {
programs.op-shell-plugins = {
enable = mkEnableOption "1Password Shell Plugins";
plugins = mkOption {
type = types.listOf types.package;
default = [ ];
example = literalExpression ''
with pkgs; [
gh
awscli2
cachix
]
'';
description =
"CLI Packages to enable 1Password Shell Plugins for; ensure that a Shell Plugin exists by checking the docs: https://developer.1password.com/docs/cli/shell-plugins/";
};
};
};

config = let
aliases = ''
export OP_PLUGIN_ALIASES_SOURCED=1
${concatMapStrings
(plugin: ''alias ${plugin}="op plugin run -- ${plugin}"'')
(map (package: builtins.baseNameOf (lib.getExe package)) cfg.plugins)}
'';
in mkIf cfg.enable (mkMerge [{
home.packages = cfg.plugins;
programs = {
fish.interactiveShellInit = ''
${aliases}
'';
bash.initExtra = ''
${aliases}
'';
zsh.initExtra = ''
${aliases}
'';
};
}]);
}

0 comments on commit 81993de

Please sign in to comment.