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

[Feature] Allow merging a .env file with other files from the nix store #268

Open
chrichrichri opened this issue Jul 11, 2024 · 0 comments

Comments

@chrichrichri
Copy link

Use-case: Many programs require config files containing secrets, but do not allow to load a file or environment variables for these variables easily. So the complete file needs to be age-encrypted, not only the actual secrets. This makes it more complicate to track the changes done on the config files.

Solution: Allow merging config files containing environment variables together with a file containing these environment variables which is coming from the age store and provide these files to the user.

Example:

  1. Config file

config_raw.json

{
  "secret"="$SECRET_1",
  "another_secret"="$SECRET_2",
}
  1. Age encrypted file:

.env

SECRET_1=foo
SECRET_2=bar
  1. Merged file, which is stored in the agenix folder and linked to the specified location:

config.json

{
  "secret"="foo",
  "another_secret"="bar",
}

Currently I am doing this with a separate service using envsubst to decrypt on startup, but this does not seem like the optimal solution:

systemd.services.config_file_creator = {
      after = [ "network.target"];

     serviceConfig = {
        Type= "oneshot";
        User = "<user>";
        EnvironmentFile=config.age.secrets.".env".path;
        ExecStart = ''${pkgs.bash}/bin/bash -c "${pkgs.gettext}/bin/envsubst < ${./config_raw.json} > /folder/path/config.json"'';
      };
    };

I am not sure if it fits to the scope of this project, but if it does, it would be great to have it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant