Skip to content

Commit

Permalink
try fixing templates on home-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
jobs62 committed Nov 28, 2024
1 parent 3433ea1 commit a86f043
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions modules/home-manager/sops.nix
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ let
sshKeyPaths = cfg.gnupg.sshKeyPaths;
ageKeyFile = cfg.age.keyFile;
ageSshKeyPaths = cfg.age.sshKeyPaths;
placeholderBySecretName = cfg.placeholder;
userMode = true;
logging = {
keyImport = builtins.elem "keyImport" cfg.log;
Expand Down
8 changes: 5 additions & 3 deletions modules/home-manager/templates.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ let
mapAttrs
types
;

hmConfig = config;
in
{
options.sops = {
Expand All @@ -33,7 +35,7 @@ in
description = "Path where the rendered file will be placed";
type = types.singleLineStr;
# Keep this in sync with `RenderedSubdir` in `pkgs/sops-install-secrets/main.go`
default = "${config.xdg.configHome}/sops-nix/secrets/rendered/${config.name}";
default = "${hmConfig.xdg.configHome}/sops-nix/secrets/rendered/${config.name}";
};
content = mkOption {
type = types.lines;
Expand Down Expand Up @@ -97,10 +99,10 @@ in
};

config = lib.optionalAttrs (options ? sops.secrets) (
lib.mkIf (config.sops.templates != { }) {
lib.mkIf (hmConfig.sops.templates != { }) {
sops.placeholder = mapAttrs (
name: _: mkDefault "<SOPS:${builtins.hashString "sha256" name}:PLACEHOLDER>"
) config.sops.secrets;
) hmConfig.sops.secrets;
}
);
}
6 changes: 5 additions & 1 deletion pkgs/sops-install-secrets/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,11 @@ func (app *appContext) validateManifest() error {
// The Nix module only defines placeholders for secrets if there are
// templates.
if len(m.Templates) > 0 {
placeholder := m.PlaceholderBySecretName[secret.Name]
placeholder, present := m.PlaceholderBySecretName[secret.Name]
if !present {
return fmt.Errorf("placeholder for %s not fount in manifest", secret.Name)
}

app.secretByPlaceholder[placeholder] = secret
}
}
Expand Down

0 comments on commit a86f043

Please sign in to comment.