I set up NginX on my Pi running NixOS. Everything works as expected, but when I reboot, the service does not start. It doesn’t even exist! When I run sudo nixos-rebuild switch
the service is up and running again.
Do you have any idea why that might be? Is it possible somehow the boot entry is not to the new generation?
nginx.nix:
{ config, pkgs, ... }:
{
networking.firewall.allowedTCPPorts = [ 80 443 ];
security.acme.acceptTerms = true;
security.acme.defaults.email = "vanousekmikulas@gmail.com";
services.nginx = {
enable = true;
virtualHosts."pi.vanousek.com" = {
forceSSL = true;
enableACME = true;
root = "/var/www";
};
};
}
miki in nixpi in 130.89.163.252 ~ took 34s
❯ sudo systemctl status nginx
● nginx.service - Nginx Web Server
Loaded: loaded (/etc/systemd/system/nginx.service; enabled; preset: enabled)
Active: active (running) since Tue 2022-10-04 10:11:34 CEST; 8s ago
Process: 6642 ExecStartPre=/nix/store/mpm1nza9s56474bbc0y0hvpfaak1d0v1-unit-script-nginx-pre-start/bin/nginx-pre-start (code=exited, status=0/SUCCESS)
Process: 6921 ExecReload=/nix/store/silrxmqlassgkq0kvpi26gwx82y8msas-nginx-1.22.0/bin/nginx -c /nix/store/nlk2fpww36rmfgd9aap1a5g9y45pa3nq-nginx.conf -t (code=exited, status=0/SUCCESS)
Process: 6923 ExecReload=/nix/store/j02ma9llhq4hc8s28aby33lf92jdbfhx-coreutils-9.1/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCESS)
Main PID: 6720 (nginx)
IP: 0B in, 0B out
IO: 15.1M read, 0B written
Tasks: 2 (limit: 4374)
CPU: 709ms
CGroup: /system.slice/nginx.service
├─6720 "nginx: master process /nix/store/silrxmqlassgkq0kvpi26gwx82y8msas-nginx-1.22.0/bin/nginx -c /nix/store/nlk2fpww36rmfgd9aap1a5g9y45pa3nq-nginx.conf"
└─6925 "nginx: worker process"
Oct 04 10:11:34 nixpi systemd[1]: Starting Nginx Web Server...
Oct 04 10:11:34 nixpi nginx-pre-start[6703]: nginx: the configuration file /nix/store/nlk2fpww36rmfgd9aap1a5g9y45pa3nq-nginx.conf syntax is ok
Oct 04 10:11:34 nixpi nginx-pre-start[6703]: nginx: configuration file /nix/store/nlk2fpww36rmfgd9aap1a5g9y45pa3nq-nginx.conf test is successful
Oct 04 10:11:34 nixpi systemd[1]: Started Nginx Web Server.
Oct 04 10:11:37 nixpi systemd[1]: Reloading Nginx Web Server...
Oct 04 10:11:37 nixpi nginx[6921]: nginx: the configuration file /nix/store/nlk2fpww36rmfgd9aap1a5g9y45pa3nq-nginx.conf syntax is ok
Oct 04 10:11:37 nixpi nginx[6921]: nginx: configuration file /nix/store/nlk2fpww36rmfgd9aap1a5g9y45pa3nq-nginx.conf test is successful
Oct 04 10:11:37 nixpi systemd[1]: Reloaded Nginx Web Server.
miki in nixpi in 130.89.163.252 ~
❯ reboot
Failed to set wall message, ignoring: Access denied
Failed to reboot system via logind: Access denied
miki in nixpi in 130.89.163.252 ~
❯ sudo !!
sudo reboot
miki in nixpi in 130.89.163.252 ~
❯ Connection to pi.vanousek.com closed by remote host.
Connection to pi.vanousek.com closed.
~ took 3m25s
❯ ssh-pi
(miki@pi.vanousek.com) Password:
Last login: Tue Oct 4 10:10:02 2022 from 130.89.168.252
miki in nixpi in 130.89.163.252 ~
❯ sudo systemctl status nginx
[sudo] password for miki:
Unit nginx.service could not be found.
miki in nixpi in 130.89.163.252 ~ took 2s
❯ snrs
building Nix...
building the system configuration...
would stop swap device: /dev/disk/by-uuid/12bcc21b-f474-4c1c-8abc-283d7889b677
stopping the following units: NetworkManager-wait-online.service, NetworkManager.service, audit.service, cpufreq.service, kmod-static-nodes.service, mount-pstore.service, network-local-commands.service, network-setup.service, nscd.service, resolvconf.service, syncthing-init.service, syncthing.service, systemd-modules-load.service, systemd-sysctl.service, systemd-timesyncd.service, systemd-udev-trigger.service, systemd-udevd-control.socket, systemd-udevd-kernel.socket, systemd-udevd.service, wpa_supplicant.service
NOT restarting the following changed units: getty@tty1.service, serial-getty@ttyAMA0.service, systemd-fsck@dev-disk-by\x2duuid-FC14\x2dA4D6.service, systemd-journal-flush.service, systemd-logind.service, systemd-random-seed.service, systemd-remount-fs.service, systemd-tmpfiles-setup.service, systemd-update-utmp.service, systemd-user-sessions.service, user-runtime-dir@1000.service, user@1000.service
activating the configuration...
reviving group 'acme' with GID 996
reviving group 'dhcpcd' with GID 999
reviving group 'nscd' with GID 991
removing group ‘networkmanager’
removing group ‘polkituser’
removing group ‘nm-openvpn’
reviving user 'acme' with UID 998
reviving user 'dhcpcd' with UID 999
reviving user 'nscd' with UID 992
removing user ‘nm-openvpn’
removing user ‘polkituser’
removing user ‘nm-iodine’
setting up /etc...
removing obsolete symlink ‘/etc/modprobe.d/nixos-initrd.conf’...
removing obsolete symlink ‘/etc/polkit-1/rules.d/10-nixos.rules’...
removing obsolete symlink ‘/etc/NetworkManager/NetworkManager.conf’...
removing obsolete symlink ‘/etc/NetworkManager/VPN/nm-vpnc-service.name’...
removing obsolete symlink ‘/etc/NetworkManager/VPN/nm-openvpn-service.name’...
removing obsolete symlink ‘/etc/NetworkManager/VPN/nm-fortisslvpn-service.name’...
removing obsolete symlink ‘/etc/NetworkManager/VPN/nm-sstp-service.name’...
removing obsolete symlink ‘/etc/NetworkManager/VPN/nm-openconnect-service.name’...
removing obsolete symlink ‘/etc/NetworkManager/VPN/nm-l2tp-service.name’...
removing obsolete symlink ‘/etc/NetworkManager/VPN/nm-iodine-service.name’...
removing obsolete symlink ‘/etc/pam.d/polkit-1’...
restarting systemd...
reloading user units for miki...
setting up tmpfiles
reloading the following units: dbus.service, firewall.service, reload-systemd-vconsole-setup.service, tmp.mount
restarting the following units: sshd.service, systemd-journald.service
starting the following units: audit.service, cpufreq.service, kmod-static-nodes.service, mount-pstore.service, network-local-commands.service, network-setup.service, nscd.service, resolvconf.service, syncthing-init.service, syncthing.service, systemd-modules-load.service, systemd-sysctl.service, systemd-timesyncd.service, systemd-udev-trigger.service, systemd-udevd-control.socket, systemd-udevd-kernel.socket
the following new units were started: acme-finished-pi.vanousek.com.target, acme-fixperms.service, acme-pi.vanousek.com.timer, dev-sda3.swap, dhcpcd.service, logrotate-checkconf.service, nginx.service, nixos-upgrade.timer, swapfile.swap, systemd-vconsole-setup.service
miki in nixpi in 130.89.163.252 ~ took 59s
❯ sudo systemctl status nginx
● nginx.service - Nginx Web Server
Loaded: loaded (/etc/systemd/system/nginx.service; enabled; preset: enabled)
Active: active (running) since Tue 2022-10-04 10:14:38 CEST; 1min 52s ago
Process: 1982 ExecStartPre=/nix/store/mpm1nza9s56474bbc0y0hvpfaak1d0v1-unit-script-nginx-pre-start/bin/nginx-pre-start (code=exited, status=0/SUCCESS)
Process: 2176 ExecReload=/nix/store/silrxmqlassgkq0kvpi26gwx82y8msas-nginx-1.22.0/bin/nginx -c /nix/store/nlk2fpww36rmfgd9aap1a5g9y45pa3nq-nginx.conf -t (code=exited, status=0/SUCCESS)
Process: 2177 ExecReload=/nix/store/j02ma9llhq4hc8s28aby33lf92jdbfhx-coreutils-9.1/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCESS)
Main PID: 2052 (nginx)
IP: 3.8K in, 24.1K out
IO: 15.7M read, 0B written
Tasks: 2 (limit: 4374)
CPU: 656ms
CGroup: /system.slice/nginx.service
├─2052 "nginx: master process /nix/store/silrxmqlassgkq0kvpi26gwx82y8msas-nginx-1.22.0/bin/nginx -c /nix/store/nlk2fpww36rmfgd9aap1a5g9y45pa3nq-nginx.conf"
└─2179 "nginx: worker process"
Oct 04 10:14:38 nixpi systemd[1]: Starting Nginx Web Server...
Oct 04 10:14:38 nixpi nginx-pre-start[2035]: nginx: the configuration file /nix/store/nlk2fpww36rmfgd9aap1a5g9y45pa3nq-nginx.conf syntax is ok
Oct 04 10:14:38 nixpi nginx-pre-start[2035]: nginx: configuration file /nix/store/nlk2fpww36rmfgd9aap1a5g9y45pa3nq-nginx.conf test is successful
Oct 04 10:14:38 nixpi systemd[1]: Started Nginx Web Server.
Oct 04 10:14:43 nixpi systemd[1]: Reloading Nginx Web Server...
Oct 04 10:14:43 nixpi nginx[2176]: nginx: the configuration file /nix/store/nlk2fpww36rmfgd9aap1a5g9y45pa3nq-nginx.conf syntax is ok
Oct 04 10:14:43 nixpi nginx[2176]: nginx: configuration file /nix/store/nlk2fpww36rmfgd9aap1a5g9y45pa3nq-nginx.conf test is successful
Oct 04 10:14:43 nixpi systemd[1]: Reloaded Nginx Web Server.
Oct 04 10:16:44 nixpi nginx[2179]: 2022/10/04 10:16:44 [error] 2179#2179: *3 directory index of "/var/www/" is forbidden, client: 130.89.168.252, server: pi.vanousek.com, request: "GET / HTT>