Skip to content

Commit

Permalink
nixos/gitea: fix auth error for non-default database users
Browse files Browse the repository at this point in the history
fixes fallout from <#266270>.

a common idiom is to run the git server as user `git`, instead of
`gitea`, with configuration like this:

```nix
services.gitea.user = "git";
services.gitea.database.user = "git";
```

after #266270, this requires setting
`services.gitea.database.createDatabase = false` (as recommended by the
assertion). however, this causes a few other fields relevant to database
connection to no longer be set, and so that upgrade path would lead to a
failed connection:

```
gitea-pre-start: cmd/migrate.go:40:runMigrate() [F] Failed to initialize
    ORM engine: pq: password authentication failed for user "git"
```

instead, preserve the old connection settings (socket path) to make this
upgrade path work.
  • Loading branch information
uninsane committed Nov 21, 2023
1 parent a8a178b commit adc3949
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions nixos/modules/services/misc/gitea.nix
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ in

socket = mkOption {
type = types.nullOr types.path;
default = if (cfg.database.createDatabase && usePostgresql) then "/run/postgresql" else if (cfg.database.createDatabase && useMysql) then "/run/mysqld/mysqld.sock" else null;
default = if usePostgresql then "/run/postgresql" else if useMysql then "/run/mysqld/mysqld.sock" else null;
defaultText = literalExpression "null";
example = "/run/mysqld/mysqld.sock";
description = lib.mdDoc "Path to the unix socket file to use for authentication.";
Expand Down Expand Up @@ -398,7 +398,7 @@ in
message = ''
When creating a database via NixOS, the db user and db name must be equal!
If you already have an existing DB+user and this assertion is new, you can safely set
`services.gitea.createDatabase` to `false` because removal of `ensureUsers`
`services.gitea.database.createDatabase` to `false` because removal of `ensureUsers`
and `ensureDatabases` doesn't have any effect.
'';
}
Expand Down Expand Up @@ -517,7 +517,7 @@ in
systemd.services.gitea = {
description = "gitea";
after = [ "network.target" ] ++ optional usePostgresql "postgresql.service" ++ optional useMysql "mysql.service";
requires = optional (cfg.database.createDatabase && usePostgresql) "postgresql.service" ++ optional (cfg.database.createDatabase && useMysql) "mysql.service";
requires = optional usePostgresql "postgresql.service" ++ optional useMysql "mysql.service";
wantedBy = [ "multi-user.target" ];
path = [ cfg.package pkgs.git pkgs.gnupg ];

Expand Down

0 comments on commit adc3949

Please sign in to comment.