Skip to content

nixos/postgresql: check config file syntax at build time #92929

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

Merged
merged 1 commit into from
Apr 2, 2021

Conversation

symphorien
Copy link
Member

Motivation for this change

Don't crash postgresql when there is a typo in extraConfig

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

Sorry, something went wrong.

@symphorien
Copy link
Member Author

@GrahamcOfBorg build nixosTests.postgresql

@@ -23,6 +23,11 @@ let
${cfg.extraConfig}
'';

configFileCheck = pkgs.runCommand "postgresql-configfile-check" {} ''
${cfg.package}/bin/postgres -D${configFile} -C config_file >/dev/null
Copy link
Member

Choose a reason for hiding this comment

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

See also #62853 for cross-compile support.

Copy link
Member Author

Choose a reason for hiding this comment

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

this approach does not work so well for postgresql because the right version of the package should be used...

@@ -279,6 +290,8 @@ in
"/share/postgresql"
];

system.extraDependencies = lib.optional (cfg.checkConfig && pkgs.stdenv.hostPlatform == pkgs.stdenv.buildPlatform) configFileCheck;
Copy link
Member

Choose a reason for hiding this comment

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

It's not good UX to silently skip the syntax check when cross-building a system and having checkConfig set to true. In that case an assertion should be thrown IMHO.

Copy link
Member Author

Choose a reason for hiding this comment

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

I copied the semantics of nix.checkConfig.

https://github.com/NixOS/nixpkgs/blob/release-20.03/nixos/modules/services/misc/nix-daemon.nix#L60

I don't find it good ux that this module throws an assertion error by default when cross compiling.

@ofborg ofborg bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog 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 10.rebuild-linux: 1 labels Jul 11, 2020

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
@symphorien symphorien force-pushed the postgresql-check-config-file branch from 523baf4 to 1b7ca69 Compare September 20, 2020 11:43
@symphorien
Copy link
Member Author

I fixed the merge conflict

@symphorien
Copy link
Member Author

cc @aanderse @flokli as they last touched the file.

@aanderse
Copy link
Member

aanderse commented Jan 9, 2021

This seems like a larger problem that should be addressed more generally ... the only problem being that I have no idea how 🤔

It is entirely conceivable that a package doesn't have an equivalent on a different platform, or is broken on another platform, has a different feature set on a different platform, etc...

I'm not sure we should assume this will even work in a cross compile/platform scenario (generally speaking).

I think further discussion is required here. Or at least I'd like to know more before we proceed because I don't know enough about cross compilation to have any solid answers.

@Ma27
Copy link
Member

Ma27 commented Jan 9, 2021

This seems like a larger problem that should be addressed more generally

I don't think that's a good idea: you have very specific tools where you sometimes have to hack around on your own (e.g. for the sshd validation I had to generate a temporary keypair in the openssh module), so I don't see how a general approach is really possible.

@symphorien
Copy link
Member Author

I also agree that there is probably no good solution for cross, this is why this PR disables it for cross altogether. But for the easy-case (non-cross) I think checking the configuration file is a net plus.

@aanderse
Copy link
Member

Are there a small number of entries in this config file which can contain reference to an external file?

@symphorien
Copy link
Member Author

I don't know for sure, but at least it's possible to include configuration files outside of the store. https://www.postgresql.org/docs/9.3/config-setting.html

@aanderse
Copy link
Member

This seems like a larger problem that should be addressed more generally

I don't think that's a good idea: you have very specific tools where you sometimes have to hack around on your own (e.g. for the sshd validation I had to generate a temporary keypair in the openssh module), so I don't see how a general approach is really possible.

Sure, we can't standardize to the degree of a specific implementation, but at a high level how can we do things consistently? I think @symphorien has a fantastic point in their comment: #92929 (comment)

If we use that approach as a standard way to approach the problem at least users can have consistent expectations.

@symphorien
Copy link
Member Author

A lot has been said, but I don't know how to make this progress forward, and I'd like to get this in before 21.05...

@aanderse
Copy link
Member

I've stated my opinion... in that I agree with your opinion: ignore checking on cross compile and print a warning. That seems like the most reasonable and scales as a generic (enough) solution we can use anywhere.

If @Ma27 didn't tell me not to then I'd merge that. 🤷‍♂️

@symphorien
Copy link
Member Author

Well I'll merge in a few days unless someone speaks up.

@symphorien
Copy link
Member Author

@GrahamcOfBorg test postgresql postgresql-wal-receiver

@symphorien symphorien merged commit fe0e0af into NixOS:master Apr 2, 2021
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: changelog 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 10.rebuild-linux: 1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants