Manage non-nixos hosts with flakes - how to?

Hi there

I am fairly new to Nix, I have been evaluating / playing around with both Nix and NixOS for a few days now (mostly in virtual machines).

Currently, it is not an option to switch to NixOS completely, so I am looking into a way to configure all my hosts running arbitrary Linux distributions with the Nix package manager, Flakes, and Home Manager.

My systems

  • Laptop from work (running Tuxedo OS)
  • Macbook Pro (2017, MacOS / Darwin, x86-64)
  • Virtual Private Server (running Ubuntu, limited choice of operating systems)
  • Private PC (willing to switch to NixOS)
  • Raspberry Pi 4 (willing to switch to NixOS if properly supported)

I have been reading some documentation and watched a few videos

what I would like to achieve

  • work with non-NixOS systems
  • have a configuration using flakes
  • make use of home manager
  • have modules reusable on other systems
  • (and this is the part where I struggle) have some config that applies system-wide (like basically installing all my cli tools for all users)

This should be possible, and zmre has shown a way for MacOS - but how would I approach this? which config options to use? (like darwinConfigurations on MacOS or nixosConfigurations on NixOS)

This cannot be done with home-manager, and cannot be done on non-NixOS linux distributions.

MacOS is the exception because of nix-darwin, which is quite invasive and behaves very differently from home-manager. I’m not aware of such a project for other distros, perhaps because it’s usually easier to just switch to NixOS than try to subvert a host Linux distro’s packaging mechanisms (and all the distro-specific quirks).

There are tools for installing NixOS on arbitrary server, for example GitHub - numtide/nixos-anywhere: install nixos everywhere via ssh

What does “properly supported” mean?

1 Like

If there’s a limited number of users on each host, you can just make a home configuration for each of them. You can factor out the common packages into a separate home-manager module to DRY.

I haven’t checked yet, but I would like to use an official image of NixOS for my RasPi4

yes, I only have a limited number of users per host in mind.
And I have already seen configs with multiple users and also with modules.

How would that work in practice? Does each user have to run the nix command to update their own profiles? or can I do this with one command for all users?

With GitHub - pftf/RPi4: Raspberry Pi 4 UEFI Firmware Images you can use regular aarch64 iso image and install NixOS as any other uefi system.
If you don’t want uefi - Installing NixOS on a Raspberry Pi — nix.dev documentation

They’d have to do it individually, yeah.

You can make a flake that contains multiple home configurations, each named user@hostname, presumably somewhere all user have write access so they can edit. Then symlink flake.nix to each of their ~/.config/home-manager. Then yeah, they would have to individually run home-manager switch to activate their own profiles, although a single nix flake update of the flake to lock the latest nixpkgs would affect all users the next time each of them rebuilt their config.

Maybe you could also setup a script for the root user that would update all other users’ profiles, using su or sudo?

1 Like