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/postgresql: add ensureDatabases.*.withOptions #339195

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

luochen1990
Copy link
Contributor

@luochen1990 luochen1990 commented Sep 3, 2024

Description of changes

Make services.postgresql.ensureDatabases support not only str as dbname, but also submodule to specify withOptions like OWNER, TEMPLATE, ENCODING, LOCALE, etc.

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.11 Release Notes (or backporting 23.11 and 24.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.

Add a 👍 reaction to pull requests you find important.

Copy link
Contributor

@drupol drupol left a comment

Choose a reason for hiding this comment

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

Nice changes, diff LGTM at first sight. I haven't tested it.

Copy link
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.

Could the option use apply instead to convert stringly-typed options to the module, with an empty withOptions?

This would make the module implementation simpler.

@luochen1990
Copy link
Contributor Author

Could the option use apply instead

I don't quite understand the meaning of this sentence, possibly because I am not a native English speaker. Do you mean assigning a separate type to each option rather than using str for all of them?

@ambroisie
Copy link
Contributor

ambroisie commented Sep 3, 2024

@luochen1990 apply is a function that can be used to apply arbitrary modifications to a (merged) option.

In this instance, I'm suggesting using it to convert from the stringly-typed option to the full-featured module, which would mean not having to worry about handling bare strings in the rest of the module.

EDIT: I'm having trouble finding the documentation for this in the manual, I could have sworn it was explained somewhere in the NixOS manual...

@luochen1990
Copy link
Contributor Author

apply is a function that can be used to apply arbitrary modifications to a (merged) option

Good suggestion! thanks for telling me this, I will change to use that now!

Copy link
Contributor

@drupol drupol left a comment

Choose a reason for hiding this comment

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

Can you please adjust the PR title and commit log message... and make sure there's only 1 commit in here?

@luochen1990
Copy link
Contributor Author

Can you please adjust the PR title and commit log message... and make sure there's only 1 commit in here?

What should the PR title look like?

@luochen1990 luochen1990 force-pushed the feat-pg-ensure-databases-options branch from e6ee66e to 15ef01d Compare September 9, 2024 08:42
@drupol
Copy link
Contributor

drupol commented Sep 9, 2024

Can you please adjust the PR title and commit log message... and make sure there's only 1 commit in here?

What should the PR title look like?

Please read again: https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md#commit-conventions

@luochen1990 luochen1990 force-pushed the feat-pg-ensure-databases-options branch from 15ef01d to f885fef Compare September 9, 2024 08:45
@luochen1990 luochen1990 changed the title services.postgresql: Improve ensureDatabases nixos/postgresql: ensureDatabases support withOptions Sep 9, 2024
@luochen1990 luochen1990 force-pushed the feat-pg-ensure-databases-options branch from f885fef to 296301b Compare September 9, 2024 08:48
@luochen1990 luochen1990 changed the title nixos/postgresql: ensureDatabases support withOptions nixos/postgresql: add ensureDatabases.*.withOptions Sep 9, 2024
@luochen1990
Copy link
Contributor Author

make sure there's only 1 commit

Because GitLab supports selecting the squash option when merging, I originally thought GitHub also supported this feature, so I would usually try to keep the commit history as much as possible, but I didn't expect GitHub to have fewer features than GitLab ..

@drupol
Copy link
Contributor

drupol commented Sep 9, 2024

make sure there's only 1 commit

Because GitLab supports selecting the squash option when merging, I originally thought GitHub also supported this feature, so I would usually try to keep the commit history as much as possible, but I didn't expect GitHub to have fewer features than GitLab ..

There's no consensus on this in nixpkgs yet, but Github does support it partially. IMHO, it's up to the contributor to make sure its commits are properly organised.

@luochen1990
Copy link
Contributor Author

Can you please adjust the PR title and commit log message... and make sure there's only 1 commit in here?

I think this is already solved, but I don't know how to mark it as solved.

@drupol
Copy link
Contributor

drupol commented Sep 9, 2024

Yes, I received all the notifications and saw it. The Diff LGTM but I'll let someone else handle the review carefully.

@luochen1990
Copy link
Contributor Author

luochen1990 commented Sep 9, 2024

@drupol There might be string literal escaping issue, I'm not sure if there are existing codes to reuse.

@drupol
Copy link
Contributor

drupol commented Sep 9, 2024

I won't be able to test it, I'm not using postgresql. That's the reason why I left this PR for someone else.

@luochen1990 luochen1990 force-pushed the feat-pg-ensure-databases-options branch from a1ac31e to 6ca042d Compare September 14, 2024 12:42
@luochen1990 luochen1990 mentioned this pull request Sep 21, 2024
10 tasks
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.

AFAIU the options part is a tombstone as soon as the DB is created, correct? I.e. if the DB exists and you change one of the options, nothing happens.

Doesn't seem very intuitive (or declarative!) to me.

I think the entire approach here is inherently flawed. Also, the reminder that the ensure* stuff caused major pain during the last two NixOS releases for the postgresql maintainers: #318777, #266270.

\I'd rather not merge.

@luochen1990
Copy link
Contributor Author

Thanks for your reply. I have give my opinion about "the ensure anti-pattern"* in #107342 (comment)

I think we can improve it instead of just delete it and use a worse solution to just make less promise to user.

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 the current state of the change, all of my criticism voiced above still applies, hence "requesting changes" for now.

Will get back to you in the other thread this afternoon (CEST), OK? :)

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

Successfully merging this pull request may close these issues.

4 participants