I use home-manager in my MacOs already and I love it. I want to translate that same experience to my VPS, some of my homelab virtual machines, and if I can remove the “configure the system first” part, then better. I want one click deployment of a personal dev environment. After that I will consider the same for other more production systems.
That’s not how that works at all. One of the really nice things about the kernel is that it abstracts a lot of that stuff away so not even NixOS needs to care about it. NixOS (and really most distros, at least on PCs) pretty much just uses a kernel that can support any and all hardware and then lets the kernel level stuff get discovered and configured at runtime automatically. e.g. Device drivers are just automatically loaded by udev whenever the kernel discovers them, using the device modaliases that the kernel knows for them. Hardware (for the most part) gets presented to userspace with standard interfaces, so you don’t really need to know anything about the hardware in order to use it. That’s why you don’t have to configure specific sound drivers for your audio hardware, or specifically hook your mouse up to your desktop environment.
Like I said, generic configs that are not hardware specific are entirely possible. The stuff in hardware-configuration.nix is generally not very interesting and pretty able to be abstracted over.
Right. Sorry - I worded that badly. I meant to say it needs to know all the things about your hardware that it can’t autodiscover - I was thinking in particular that it needs to know which partitions you want to mount and boot from.
Sure, here’s how it looks like for both a VPS and a laptop.
I use flakes personally. That has be set up before anything. You can look at my personal devices flake or my homelab flake, but I don’t know how useful they’ll be.
Note that you can effectively bypass hardware-configuration.nix with disko. You can pull in modules from nix-hardware if needed.
New VPS Steps
Provision a new VPS with my ssh key (with Hetzner this is automatic).
Add a new nixos configuration under ./hosts in my flake, with a diskos config. I found an example config for hetzner, so I started with that.
Run nixos-anywhere, e.g. nix run github:nix-community/nixos-anywhere -- --flake '.#myconfig' --target-host root@my-host
The way I originally set up my hosts was moving the files that a nixos install generates (/etc/nixos/configuration.nix, /etc/nixos/hardware-configuration.nix) under ./hosts/<machine>.
New Laptop Steps
Either download a vanilla nixos iso, or make a custom image, and flash it to a USB drive. For my laptop I just installed nixos manually with a vanilla iso.
Once the installation is finished, I edit /etc/nixos/configuration.nix to enable openssh (services.openssh.enabled = true;).
I ssh in from an existing machine with my flake, copy the configuration.nix and hardware-configuration.nix files to ./hosts/<machine>.
I edit the configuration to my liking, then run a remote nixos-rebuild switch, e.g. nixos-rebuild switch \ --flake ".#myconfig" \ --build-host "root@machine" \ --target-host "root@machine" \ --use-remote-sudo
5. Add hardware modules if needed. E.g. I installed nixos on my thinkpad amd t14s, so I pulled in nix-hardware.nixosModules.lenovo-thinkpad-t14s.
Once the machine is bootstrapped this way, it’s onto nix configurations as usual.
I’m sure there’s a more efficient way, but I do this process less than once per year usually, so meh.
But you don’t do that anymore, right? disko takes care of that?
Do you mean that you remote copy into your existing machine from the new laptop, right? Not that you ssh and then copy the flake and then do the thing locally (or you do?)
Thank you very much for sharing your resources and knowledge!
Disko only specifies configs for the disk partioning of the system, which you’d otherwise manually do as part of the install. Nixos-anywhere will handle the other hardware-configuration stuff.
Actually you can do both. I prefer to do it remotely from the host machine, especially on local networks. But if the ssh connection is slow, I’ve found it better to ssh in → git pull/update the flake locally → do nixos-rebuild switch locally. And for low power devices, you can still deploy remotely but build on the host machine’s store (with the --build-host and --target-host flags for nixos-rebuild switch).