Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try fixing templates on home-manager #686

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .mergify.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
queue_rules:
- name: default
queue_conditions:
- base=master
- label~=merge-queue|dependencies
merge_conditions:
- check-success=buildbot/nix-build
merge_method: rebase

pull_request_rules:
- name: refactored queue action rule
conditions: []
conditions:
- base=master
- label~=merge-queue|dependencies
actions:
queue:
8 changes: 7 additions & 1 deletion checks/darwin.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@

{
config,
...
}:
{
imports = [
../modules/nix-darwin/default.nix
];
documentation.enable = false;
sops.secrets.test_key = { };
sops.templates."template.toml".content = ''
password = "${config.sops.placeholder.test_key}";
'';
sops.defaultSopsFile = ../pkgs/sops-install-secrets/test-assets/secrets.yaml;
sops.age.generateKey = true;
system.stateVersion = 5;
Expand Down
7 changes: 5 additions & 2 deletions checks/home-manager.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

{ config, ... }: {
{ config, ... }:
{
imports = [
../modules/home-manager/sops.nix
];
Expand All @@ -11,5 +11,8 @@
sops.age.generateKey = true;
sops.age.keyFile = "${config.home.homeDirectory}/.age-key.txt";
sops.secrets.test_key = { };
sops.templates."template.toml".content = ''
password = "${config.sops.placeholder.test_key}";
'';
sops.defaultSopsFile = ../pkgs/sops-install-secrets/test-assets/secrets.yaml;
}
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 found in manifest", secret.Name)
}

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