Skip to content

nixos/postgresql: allow specifying multiple databases in ensureDBOwnership#287788

Closed
icewind1991 wants to merge 2 commits intoNixOS:masterfrom
icewind1991:postgres-ensureDBOwnership-list
Closed

nixos/postgresql: allow specifying multiple databases in ensureDBOwnership#287788
icewind1991 wants to merge 2 commits intoNixOS:masterfrom
icewind1991:postgres-ensureDBOwnership-list

Conversation

@icewind1991
Copy link
Copy Markdown
Contributor

@icewind1991 icewind1991 commented Feb 10, 2024

Description of changes

Allow settings services.postgresql.ensureUsers.*.ensureDBOwnership to a list of database names instead of only booleans.

This allows using it for setups where the database name doesn't match the user name or there are multiple databases accessed by a single db user.

This should make ensureDBOwnership able to cover more use cases from the deprecated ensurePermissions option.

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/)
  • 24.05 Release Notes (or backporting 23.05 and 23.11 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.

Add a 👍 reaction to pull requests you find important.

@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 Feb 10, 2024
@jian-lin
Copy link
Copy Markdown
Contributor

FYI, there are related discussions in #266270 and you can request people interested to review this PR.

@github-actions github-actions bot added 8.has: documentation This PR adds or changes documentation 8.has: changelog This PR adds or changes release notes labels Feb 11, 2024
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Feb 11, 2024
Copy link
Copy Markdown
Contributor

@ambroisie ambroisie left a comment

Choose a reason for hiding this comment

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

This is what I had in mind, so let me approve the PR :-).

Tiny nit to DRY it up.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rather than repeat this multiple time, you can use apply in the option definition to tranform a true into a singleton list [ name ].

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried that but couldn't figure out how to use the value of name within the apply function

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

types.submodule can use an argument list which would allow you to get at the name IIRC.

Currently on my phone so it's difficult to check.

@Ma27
Copy link
Copy Markdown
Member

Ma27 commented Feb 12, 2024

I still don't think we should expand the features that pretend to be declarative, but in fact aren't.
Instead I'd prefer to see a solution as described in #206467 / #252071 instead of another ad-hoc mechanism like this.

👎 from me.

@cmm
Copy link
Copy Markdown
Member

cmm commented Mar 11, 2024

So I happen to have a database owned by a differently-named user and the database has data in it.
I'm not a Postgres expert by any stretch and find the ensurePermissions migration instructions in the manual pretty scary.

Now I understand that I can just comment out the whole bit and the existing database will not be impacted, but I'd rather modernize the config properly, so: what's up with this PR? It's been quiet for a month, how do the prospects look?

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Mar 20, 2024
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Apr 9, 2024
Comment on lines +569 to +570
in concatStringsSep "\n"
(builtins.map (db: ''$PSQL -tAc 'ALTER DATABASE "${db}" OWNER TO "${user.name}";' '') dbOwnershipList);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
in concatStringsSep "\n"
(builtins.map (db: ''$PSQL -tAc 'ALTER DATABASE "${db}" OWNER TO "${user.name}";' '') dbOwnershipList);
in concatMapStringsSep "\n"
(db: ''$PSQL -tAc 'ALTER DATABASE "${db}" OWNER TO "${user.name}";' '') dbOwnershipList;

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label May 3, 2024
@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 2, 2025
@icewind1991 icewind1991 closed this by deleting the head repository May 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog This PR adds or changes release notes 8.has: documentation This PR adds or changes documentation 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 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants