Skip to content

Commit

Permalink
feat: add initial flake.nix
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjones2014 committed Mar 4, 2024
1 parent acb6582 commit f230b4e
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ plugins/registry.json

# 1Password
.op

# direnv
.direnv
.envrc
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
inputs = {
nixpkgs = { url = "github:nixos/nixpkgs/nixos-unstable"; };
flake-utils = { url = "github:numtide/flake-utils"; };
};
outputs = { nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let pkgs = import nixpkgs { inherit system; };
in {
devShell = pkgs.mkShell {
name = "Shell with Go toolchain";

packages = with pkgs; [ go gopls ];
};
});
}
67 changes: 67 additions & 0 deletions shell-plugins.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{ pkgs, lib, config, is-home-manager, ... }:
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
# Explanation:
# Map over `cfg.plugins` (the value of the `plugins` option provided by the user)
# and for each package specified, get the executable name, then create a shell alias
# of the form:
# `alias {pkg}="op plugin run -- {pkg}"`
# where `{pkg}` is the executable name of the package
aliases = ''
export OP_PLUGIN_ALIASES_SOURCED=1
${concatMapStrings
(plugin: ''alias ${plugin}="op plugin run -- ${plugin}"'')
(map (package: builtins.baseNameOf (lib.getExe package)) cfg.plugins)}
'';
# install the 1Password CLI, as well as any of the CLIs for which
# shell plugins are enabled
packages = [ pkgs._1password ] ++ cfg.plugins;
in mkIf cfg.enable (mkMerge [
({
# the option names are slightly different depending on whether you're using home-manager or not
programs = if is-home-manager then {
fish.interactiveShellInit = ''
${aliases}
'';
bash.initExtra = ''
${aliases}
'';
zsh.initExtra = ''
${aliases}
'';
} else {
fish.interactiveShellInit = "";
bash.interactiveShellInit = ''
${aliases}
'';
zsh.interactiveShellInit = ''
${aliases}
'';
};
} // optionalAttrs is-home-manager { home.packages = packages; }
// optionalAttrs (not is-home-manager) {
environment.systemPackages = packages;
})
]);
}

0 comments on commit f230b4e

Please sign in to comment.