… and needing to set up a new Wordpress server to replace my aging one, I thought this might be a good exercise to try Nix.
Linode has a nice writeup on how to install Nix. About half way through it, but this is proving to be a good exercise on how to use the low level aspects of the Linode platform (booting from ISO installer image, etc). The Linode platform seems very flexible. Here is a screen shot of the NixOS installer boot menu displayed in the Linode Glish terminal:
Then running nixos-rebuid switch. This puts binaries in locations like:
[root@nixos:/etc]# which nvim
/run/current-system/sw/bin/nvim
I’ve been reading you can also use nix-env to install stuff, so I tried:
[root@nixos:/etc]# nix-env --install caddy
Killed
It appears to be running the machine out of memory. According to this thread, this is common on low memory machines and you can do the following instead:
nix-env -iA nixos.caddy
That works, and now caddy is located in:
[root@nixos:/etc]# which caddy
/root/.nix-profile/bin/caddy
[root@nixos:/etc]# which nvim
/run/current-system/sw/bin/nvim
Contrasting the install location of caddy with nvim is interesting – it appears nix-env populates binaries for that user only.
So where did it store this configuration information about install caddy for the user? Perhaps /root/.nix-profile/manifest.nix?
Its interesting this service is in the nixos/ directory, where the caddy service recipe is in the pkgs/ directory. This indicates you could install the caddy binary via nix on any OS, but to leverage the service configuration, you need to be running nixos – makes sense.
services.caddy = {
enable = true;
extraConfig = ''
hello.bec-systems.com {
respond "Hello, world!"
}
'';
};
services.wordpress = {
webserver = "caddy";
};
services.wordpress.sites."web2.bec-systems.com" = {
database.createLocally = true; # name is set to `wordpress` by default
virtualHost = {
adminAddr = "cbrake@bec-systems.com";
serverAliases = [ "web2.bec-systems.com" ];
};
};
services.wordpress.sites."miles.bec-systems.com" = {
database.createLocally = true; # name is set to `wordpress` by default
database.name = "wp_miles";
virtualHost = {
adminAddr = "miles@bec-systems.com";
serverAliases = [ "miles.bec-systems.com" ];
};
};
Its pretty neat that with this bit of declarative config, we set up a database, PHP, wordpress, webserver, accounts, and who knows what else. Notice how easy it is to add a 2nd site …
Https is still not working yet as Nixos is generating the following Caddyfile:
And Wordpress was updated from 5.9.3 to 6.0.3. However, there is Wordpress v6.1.1 out.
Kernel is:
[root@nixos:~]# cat /proc/version
Linux version 5.15.83 (nixbld@localhost) (gcc (GCC) 11.3.0, GNU ld (GNU Binutils) 2.39) #1-NixOS SMP Wed Dec 14 10:37:31 UTC 2022
6.0 kernel is out, but perhaps they stick with longterm releases?
Appears we still have the HTTPS issue with wordpress/caddy, so back to debugging that.
Upgrade was pretty slick – still trying to decide if this makes sense for managing my production web server.
[cbrake@nixos:~]$ cat /proc/version
Linux version 6.1.0 (nixbld@localhost) (gcc (GCC) 11.3.0, GNU ld (GNU Binutils) 2.39) #1-NixOS SMP PREEMPT_DYNAMIC Sun Dec 11 22:15:18 UTC 2022
I also watched the terminal during shutdown, and getting a significant delay in DHCP client shutting down: