Skip to content

Commit

Permalink
Prototyping 1password nixos module.
Browse files Browse the repository at this point in the history
  • Loading branch information
iivvaannxx committed Sep 6, 2023
1 parent af34edb commit 3742b8f
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 13 deletions.
1 change: 1 addition & 0 deletions hosts/avalon/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ in {
];

programs._1password-gui.enable = true;
programs._1password-gui.package = upkgs._1password-gui;
programs._1password-gui.polkitPolicyOwners = [ "iivvaannxx" ];

programs.zsh.enable = true;
Expand Down
3 changes: 0 additions & 3 deletions lib/attrsets.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ in {
# Maps the given function to the given attribute set. Then filters the result based on the given predicate.
mapAndFilterAttrs = pred: fn: attrs: filterAttrs pred (mapAttrs' fn attrs);

# Returns all the keys of the given attribute set.
attrKeys = attrs: mapAttrsToList (key: _: key) attrs;

# Returns all the keys of the given attribute set, recursively.
attrKeysRecursive = attrs: let

Expand Down
3 changes: 1 addition & 2 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ in {
inherit (attrsets)

mapAndFilterAttrs

attrKeys
attrKeysRecursive
;

Expand Down Expand Up @@ -61,6 +59,7 @@ in {
mkStrListOption

mkSubmoduleOption
mkSubmoduleListOption
mkDynamicAttrsetOption

mkPackageListOption
Expand Down
10 changes: 10 additions & 0 deletions lib/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ in {
}
);

# Shorthand for creating submodule lists options in custom modules.
mkSubmoduleListOption = default: description: submodule: (

mkOption {

inherit default description;
type = types.listOf (types.submodule { options = submodule; });
}
);

# Shorthand for creating dynamic submodules in custom modules. (ex: my.module.<anything here>)
mkDynamicAttrsetOption = default: description: mkSubmodule: (

Expand Down
71 changes: 71 additions & 0 deletions modules/nixos/tools/onepassword/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# -------------------------------------------------------------------------------------------------
#
# Home Manager module for the Performant Node Package Manager (pnpm).
# See: https://pnpm.io/
#
# -------------------------------------------------------------------------------------------------

{ config, lib, pkgs, upkgs, ... } @ args: let

inherit (builtins) map fromToml concatStringsSep;

inherit (lib) mkEnableOption mkPackageOption mkIf;
inherit (lib.custom) mkSubmoduleOption mkSubmoduleListOption mkStrOption;

# The current configuration values.
cfg = options.modules.tools.onepassword;

in {

options.modules.tools.onepassword = {

gui = mkSubmoduleOption { } "Options for the 1Password GUI." {

enable = mkEnableOption "the 1Password password manager GUI.";
package = mkPackageOption "1Password GUI" { default = [ "_1password-gui" ] };

polkitPolicyOwners = mkStrListOption [ ] "The users that should be able to integrate 1Password with polkit-based authentication mechanisms.";
};

cli = mkSubmoduleOption { } "Options for the 1Password CLI." {

enable = mkEnableOption "the 1Password password manager CLI.";
package = mkPackageOption "1Password CLI" { default = [ "_1password" ] };
};

# See: https://developer.1password.com/docs/ssh/agent/config
agentConfig = mkSubmoduleListOption [ ] "The config to write to the 1Password 'agent.toml' file." {

item = mkStrOption "" "The item name or ID";
vault = mkStrOption "" "The vault name or ID";
account = mkStrOption "" "The account name or ID";
};
};

config = let

agentSections = (map (config: concatStringsSep "\n" [

"[[ssh-keys]]"

# Add each key-value pair as a separate line (if present).
(mkIf (config.item != "") ''item = "${config.item}"'')
(mkIf (config.vault != "") ''vault = "${config.vault}"'')
(mkIf (config.account != "") ''account = "${config.account}"'')
]));

# The agent config file.
agentToml = concatStringsSep "\n\n" agentSections;

in mkIf (cfg.gui.enable || cfg.cli.enable) {

# Configuration for the 1Password CLI.
programs._1password.enable = cfg.cli.enable;
programs._1password.package = cfg.cli.package;

# Configuration for the 1Password GUI.
programs._1password-gui.enable = cfg.gui.enable;
programs._1password-gui.package = cfg.gui.package;
programs._1password-gui.polkitPolicyOwners = cfg.gui.polkitPolicyOwners;
};
}
8 changes: 0 additions & 8 deletions packages/scripts/json2nix.nix

This file was deleted.

0 comments on commit 3742b8f

Please sign in to comment.