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
nginx: expose generated config and allow nginx reloads #57429
Changes from all commits
8b036d5
128d1a5
deb8cfd
5f86231
e6ff708
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,6 +162,10 @@ let | |
${cfg.appendConfig} | ||
''; | ||
|
||
configPath = if cfg.enableReload | ||
then "/etc/nginx/nginx.conf" | ||
else configFile; | ||
|
||
vhosts = concatStringsSep "\n" (mapAttrsToList (vhostName: vhost: | ||
let | ||
onlySSL = vhost.onlySSL || vhost.enableSSL; | ||
|
@@ -431,6 +435,16 @@ in | |
"; | ||
}; | ||
|
||
enableReload = mkOption { | ||
default = false; | ||
type = types.bool; | ||
description = '' | ||
Reload nginx when configuration file changes (instead of restart). | ||
The configuration file is exposed at <filename>/etc/nginx/nginx.conf</filename>. | ||
See also <literal>systemd.services.*.restartIfChanged</literal>. | ||
''; | ||
}; | ||
|
||
stateDir = mkOption { | ||
default = "/var/spool/nginx"; | ||
description = " | ||
|
@@ -638,17 +652,32 @@ in | |
preStart = | ||
'' | ||
${cfg.preStart} | ||
${cfg.package}/bin/nginx -c ${configFile} -p ${cfg.stateDir} -t | ||
${cfg.package}/bin/nginx -c ${configPath} -p ${cfg.stateDir} -t | ||
''; | ||
serviceConfig = { | ||
ExecStart = "${cfg.package}/bin/nginx -c ${configFile} -p ${cfg.stateDir}"; | ||
ExecStart = "${cfg.package}/bin/nginx -c ${configPath} -p ${cfg.stateDir}"; | ||
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; | ||
Restart = "always"; | ||
RestartSec = "10s"; | ||
StartLimitInterval = "1min"; | ||
}; | ||
}; | ||
|
||
environment.etc."nginx/nginx.conf" = mkIf cfg.enableReload { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, why is this only enabled if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ohhh, the original commit actually called that right 8b036d5#diff-795fa65a7c41a479084de826e4e2e65cR460 It just people suggested that Actually, I'd like to write that file in some other place, but only |
||
source = configFile; | ||
}; | ||
|
||
systemd.services.nginx-config-reload = mkIf cfg.enableReload { | ||
wantedBy = [ "nginx.service" ]; | ||
restartTriggers = [ configFile ]; | ||
script = '' | ||
if ${pkgs.systemd}/bin/systemctl -q is-active nginx.service ; then | ||
${pkgs.systemd}/bin/systemctl reload nginx.service | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
fi | ||
''; | ||
serviceConfig.RemainAfterExit = true; | ||
}; | ||
|
||
security.acme.certs = filterAttrs (n: v: v != {}) ( | ||
let | ||
vhostsConfigs = mapAttrsToList (vhostName: vhostConfig: vhostConfig) virtualHosts; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought everybody agreed to make this true by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 Maybe I'm just too cautious to change default behavior. Would you like to do that? 😁