Shell assertions in config phase #111

Closed
domenkozar opened this Issue Mar 2, 2013 · 8 comments

Comments

Projects
None yet
4 participants
@domenkozar
Member

domenkozar commented Mar 2, 2013

Feature request:

Software with DSL config files normally has a way to validate the config file before service is restarted. I'd like to assert that generated config file passes that test before systemd service is restarted.

For example, for nginx one can do nginx -t -c default.confg and non-zero exit code should stop nixos-rebuild script with an error.

PS: if such convention already exists, I'm happy to document it somewhere (wiki?)

@vcunat

This comment has been minimized.

Show comment
Hide comment
@vcunat

vcunat Mar 2, 2013

Member

Oh, this is IMO a really good idea. I don't know about any placed used, but that's not a useful information, as I know very little about NixOS expressions.

Member

vcunat commented Mar 2, 2013

Oh, this is IMO a really good idea. I don't know about any placed used, but that's not a useful information, as I know very little about NixOS expressions.

@garbas

This comment has been minimized.

Show comment
Hide comment
@garbas

garbas Mar 3, 2013

Contributor

i think you could do this in similar way that modules/services/networking/ircd-hybrid/default.nix is done. since there it creates derivation and you could run configtest in one of test phases

Contributor

garbas commented Mar 3, 2013

i think you could do this in similar way that modules/services/networking/ircd-hybrid/default.nix is done. since there it creates derivation and you could run configtest in one of test phases

@edolstra

This comment has been minimized.

Show comment
Hide comment
@edolstra

edolstra Mar 6, 2013

Member

We actually had something like that in the Upstart era. See e.g. https://github.com/NixOS/nixos/blob/ce3941d6e6d7c5f4f683d3ef25070cd1c803a79b/modules/services/web-servers/apache-httpd/default.nix (look for "buildHook"). The idea was that building the httpd job fails if the configuration file is not syntactically correct. (Well, that was the theory. It didn't actually work because "httpd -t" is impure.)

Member

edolstra commented Mar 6, 2013

We actually had something like that in the Upstart era. See e.g. https://github.com/NixOS/nixos/blob/ce3941d6e6d7c5f4f683d3ef25070cd1c803a79b/modules/services/web-servers/apache-httpd/default.nix (look for "buildHook"). The idea was that building the httpd job fails if the configuration file is not syntactically correct. (Well, that was the theory. It didn't actually work because "httpd -t" is impure.)

@domenkozar

This comment has been minimized.

Show comment
Hide comment
@domenkozar

domenkozar Mar 6, 2013

Member

There is no way to create user/group before the build check? Nginx seems to do the same:

nginx: [emerg] getpwnam("www-data2") failed in /etc/nginx/nginx.conf:1
nginx: configuration file /etc/nginx/nginx.conf test failed
Member

domenkozar commented Mar 6, 2013

There is no way to create user/group before the build check? Nginx seems to do the same:

nginx: [emerg] getpwnam("www-data2") failed in /etc/nginx/nginx.conf:1
nginx: configuration file /etc/nginx/nginx.conf test failed
@vcunat

This comment has been minimized.

Show comment
Hide comment
@vcunat

vcunat Mar 6, 2013

Member

Can't the needed files be built in a separate derivation? Then it could be given as another input.

Member

vcunat commented Mar 6, 2013

Can't the needed files be built in a separate derivation? Then it could be given as another input.

@domenkozar

This comment has been minimized.

Show comment
Hide comment
@domenkozar

domenkozar Mar 6, 2013

Member

Like the example garbas showed?

On Wed, Mar 6, 2013 at 3:55 PM, Vladimír Čunát notifications@github.comwrote:

Can't the needed files be built in a separate derivation? Then it could be
given as another input.


Reply to this email directly or view it on GitHubhttps://github.com/NixOS/nixos/issues/111#issuecomment-14503127
.

Member

domenkozar commented Mar 6, 2013

Like the example garbas showed?

On Wed, Mar 6, 2013 at 3:55 PM, Vladimír Čunát notifications@github.comwrote:

Can't the needed files be built in a separate derivation? Then it could be
given as another input.


Reply to this email directly or view it on GitHubhttps://github.com/NixOS/nixos/issues/111#issuecomment-14503127
.

@vcunat

This comment has been minimized.

Show comment
Hide comment
@vcunat

vcunat Mar 6, 2013

Member

Yes, that was an example of building a NixOS service by a derivation... so you want this and additionally a test phase that checks the config.

Moreover, I just speculated that if you're missing some other stuff (like /etc/passwd), IMHO it could be separated into another derivation and used as and additional input... but I would rather avoid this if possible.

Member

vcunat commented Mar 6, 2013

Yes, that was an example of building a NixOS service by a derivation... so you want this and additionally a test phase that checks the config.

Moreover, I just speculated that if you're missing some other stuff (like /etc/passwd), IMHO it could be separated into another derivation and used as and additional input... but I would rather avoid this if possible.

@domenkozar

This comment has been minimized.

Show comment
Hide comment
@domenkozar

domenkozar Mar 11, 2013

Member

OK, I'll play around and post here the results.

Member

domenkozar commented Mar 11, 2013

OK, I'll play around and post here the results.

@domenkozar domenkozar closed this May 20, 2016

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