From c27055ed80f3a32b47e4b612814c33d9669067b8 Mon Sep 17 00:00:00 2001 From: Krzysztof Saczuk Date: Sun, 25 Aug 2024 05:32:36 +0200 Subject: [PATCH] refactor(apps): make 1password use new dynamic secrets utils --- modules/desktop/apps/_1password.nix | 49 ++++++++++------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/modules/desktop/apps/_1password.nix b/modules/desktop/apps/_1password.nix index f0b65c0..56d2963 100644 --- a/modules/desktop/apps/_1password.nix +++ b/modules/desktop/apps/_1password.nix @@ -16,36 +16,9 @@ with lib.my.utils; let monitor = getLayoutMonitor layout "wayland"; class = "1Password"; - mkAgentEntrySecretName = entry: slot: "1password/ssh_agent/${entry}/${slot}"; - mkAgentEntrySecret = entry: slot: { - name = mkAgentEntrySecretName entry slot; - value = {}; - }; - mkAgentEntry = entry: - listToAttrs ( - builtins.map - ( - slot: { - name = slot; - value = config.sops.placeholder.${mkAgentEntrySecretName entry.name slot}; - } - ) (builtins.attrNames entry.value) - ); - agentEntries = (mapper.fromYAML config.sops.defaultSopsFile)."1password".ssh_agent; - - agentEntrySecrets = listToAttrs (builtins.concatLists ( - builtins.map - ( - { - name, - value, - }: - builtins.map - (slot: mkAgentEntrySecret name slot) - (builtins.attrNames value) - ) - (attrsToList agentEntries) - )); + base = "1password/ssh_agent"; + secretNames = utils.recursiveReadSecretNames {inherit config base;}; + secrets = utils.readSecrets {inherit config base;}; in { programs = { _1password.enable = true; @@ -67,14 +40,24 @@ in { sops = { templates = { - "agent.toml" = { + "1password/agent.toml" = { mode = "0644"; owner = username; path = "${configDirectory}/1Password/ssh/agent.toml"; - file = mapper.toTOML "agent.toml" {ssh-keys = builtins.map mkAgentEntry (lib.attrsToList agentEntries);}; + file = mapper.toTOML "agent.toml" { + ssh-keys = + builtins.map + ( + entry: + builtins.mapAttrs + (slot: _: utils.mkSecretPlaceholder config [base entry slot]) + (attrByPath [entry] {} secrets) + ) + (builtins.attrNames secrets); + }; }; }; - secrets = agentEntrySecrets; + secrets = listToAttrs (builtins.map (v: nameValuePair v {}) secretNames); }; home-manager.users.${username} = {