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

ATTIC_SERVER_DATABASE_URL is ignored when using from flake #152

Open
ajgon opened this issue Jul 18, 2024 · 2 comments
Open

ATTIC_SERVER_DATABASE_URL is ignored when using from flake #152

ajgon opened this issue Jul 18, 2024 · 2 comments

Comments

@ajgon
Copy link

ajgon commented Jul 18, 2024

So, my use case is basically to avoid exposing a secret (postgres password) anywhere in repository or nix store. To do so, I'm leveraging sops-nix files with secrets. Here is the part of my config:

{ config, ... }:
{
  sops = {
    secrets = {
      "attic/server/credentials" = {
        restartUnits = [ "atticd.service" ];
      };
    };
  };

  services.atticd = {
    enable = true;

    credentialsFile = config.sops.secrets."attic/server/credentials".path;

    settings = ... my settings ...
  };
}

and in sops attic/server/credentials:

ATTIC_SERVER_DATABASE_URL="postgresql://postgres:<password which I want to keep secret>@localhost:5432/attic"
ATTIC_SERVER_TOKEN_HS256_SECRET_BASE64="..."
AWS_ACCESS_KEY_ID="..."
AWS_SECRET_ACCESS_KEY="..."

So far so good, credentials file is generated properly and loaded as environment file. But atticd still uses sqlite as it's DB. My assumption is, because nix sets a default in settings here: https://github.com/zhaofengli/attic/blob/main/nixos/atticd.nix#L174 and env var has lower priority.

As a workaround I tried to use configFile and pass full config from sops there, but because checkedConfigFile evaluates too early, the sops secret is not there yet.

Is there any way, to pass postgres password without exposing it? Also I think that env being effectively ignore, is a bug, and should be taking priority if set.

@ajgon
Copy link
Author

ajgon commented Jul 18, 2024

Ok, there "is" workaround, by using sqlx env vars as described here: https://docs.rs/sqlx/latest/sqlx/postgres/struct.PgConnectOptions.html#impl-PgConnectOptions .

So by setting:

{
  services.atticd.database.url = "postgresql://postgres@localhost:5432/attic";
}

and then adding PGPASSWORD=mypostgrespassword to credentials file, I managed to make it work. Still I think, it's a hack, and not a proper solution of the problem :)

@DaRacci
Copy link

DaRacci commented Jul 28, 2024

thanks for documenting this workaround, seems like the issue is because of the hardcoded default url for an sqlite db.

DaRacci added a commit to DaRacci/nix-config that referenced this issue Jul 28, 2024
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

2 participants