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

nixos/gitea: don't configure the database if createDatabase == false #268849

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

uninsane
Copy link
Contributor

@uninsane uninsane commented Nov 21, 2023

fixes fallout from #266270.

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

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, the module then plumbs defaults which no longer make sense into the gitea config causing a failed connection at runtime:

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

instead, don't default any of the connection settings when createDatabase == false: error at eval time (instead of runtime) if the user hasn't explicitly configured the remaining connection settings.

Description of changes

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.11 Release Notes (or backporting 23.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Nov 21, 2023
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Nov 21, 2023
Copy link
Member

@Ma27 Ma27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context, there was a discussion in the past on when to declare dependencies (because requires will cause problems when undefined services are listed in there): #237544

If you declare createDatabase = false;, I'd expect that the module leaves the entire task of configuring the database connection to me.

I think the correct fix is to add an assertion here that ensures that the system user is equal to the database user (and thus the PAM authentication used by createDatabase = true; will work again) and ask everybody who doesn't do that (system user == db user == db name) to configure it themselves.

@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 4, 2024
@FliegendeWurst FliegendeWurst added the awaiting_changes (old Marvin label, do not use) label Dec 2, 2024
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Dec 22, 2024
fixes fallout from <NixOS#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 NixOS#266270, this requires setting
`services.gitea.database.createDatabase = false` (as recommended by the
assertion). however, the module then plumbs defaults which no longer
make sense into the gitea config causing a failed connection at runtime:

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

instead, don't default any of the connection settings when
`createDatabase == false`: error at eval time (instead of runtime) if
the user hasn't explicitly configured the remaining connection settings.
@uninsane
Copy link
Contributor Author

@Ma27 took me a bit to find something ergonomic, pushed a patch which i think does a good job.

if services.gitea.database.createDatabase == false, then the module just doesn't default any of the services.gitea.database connection settings. then, typical use case looks like:

services.gitea.enable = true;
services.gitea.database.type = "postgres";
services.gitea.database.createDatabase = false;
# if eval'd here, user will see an error about `config.services.gitea.database.{name,user,...}` being referenced but not defined
services.gitea.database.name = "gitea";
services.gitea.database.user = "git";
services.gitea.database.socket = "/run/postgresql";
# then user is expected to manually configure services.postgresql, and define a `requires` from gitea onto postgresql if applicable

@uninsane uninsane changed the title nixos/gitea: fix auth error for non-default database users nixos/gitea: don't configure the database if createDatabase == false Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 awaiting_changes (old Marvin label, do not use)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants