How to use modules on other Linux distributions

There is a Debian server. I have persuaded people to use Nix as a package manager. Now I’d like to move one step ahead and try to use an existing (NixOS) module on it. Like I’d want to copy configuration.nix and everything to the machine but let it manage just one “aspect”.

Yes, easiest would be to just install NixOS and then nixos-rebuild but I am not really allowed to do nixos-infect or something during night :slight_smile:

What would be the easiest way to accomplish this? I know this is a broad and probably weird topic but can you perhaps just point me in the right direction how to use the module system with only Nix?

2 Likes

There is a Debian server. I have persuaded people to use Nix as a package manager. Now I’d like to move one step ahead and try to use an existing (NixOS) module on it. Like I’d want to copy configuration.nix and everything to the machine but let it manage just one “aspect”.

Yes, easiest would be to just install NixOS and then nixos-rebuild but I am not really allowed to do nixos-infect or something during night :slight_smile:

What would be the easiest way to accomplish this? I know this is a broad and probably weird topic but can you perhaps just point me in the right direction how to use the module system with only Nix?

I guess you are effectively allowed to build NixOS, just not to boot it…

And you do not seem to need the module system per se, just a module to use.

I hope that analysing and running the following command can give you some options on how to proceed:

cat "$(nix-build --no-out-link -E 'let nixos = import <nixpkgs/nixos> { configuration = { services.openssh.enable = true; }; }; in nixos.config.systemd.units."sshd.service"' )/sshd.service"
5 Likes

I am not sure what your usecase is, but there is also the option to start imperative nixos container or qemu vms. This one should also work: GitHub - Mic92/nixos-shell: Spawns lightweight nixos vms in a shell

2 Likes

I don’t have a solution, but I think it’d be really cool if someone made something akin to nix-darwin for other Linux distros. i.e. It’d configure systemd services and etc files and whatnot for e.g. Ubuntu. Wouldn’t be too hard to make it so most NixOS modules would be compatible with it.

I don’t have a solution, but I think it’d be really cool if someone made something akin to nix-darwin for other Linux distros. i.e. It’d configure systemd services and etc files and whatnot for e.g. Ubuntu. Wouldn’t be too hard to make it so most NixOS modules would be compatible with it.

If you want just to configure a few things then symlink configs/launcher scripts/systemd units, then it is enough to use what I mentioned in the previous reply plus the tricks I have collected in https://github.com/7c6f434c/lang-os/blob/811cfc94231e8df60fcf43891ab0a5e98ca909fa/use-from-nixos.nix

I do like to say we need a nix-darwin port to Linux, but I think it is only worth the effort if we actually structure it closer to Nixpkgs. So that there are individual service config generators — functions, or overridable packages — and then the module system would be used to assemble a whole, if desired (which could ideally be a NixOS system or a bunch of units to install or even, dunno, an s6-friendly daemon list)

Still guessing at the use-case, but maybe home-manager is what you actually want if you don’t care so much about the underlying OS and just want to manage your user’s setup.

Thanks. Until now I always thought of NixOS as some kind of separate wrapper around Nix, some tooling from a different repo + Nix if you wish. But apparently nixpkgs has all nixos derivations inside. That means Nix has “bateries included”. I mean in hindsight it’s obvious, but I never thought about that.
Like a compiler that can be used to compile itself. Wow.

nixos-shell is a really nice thing. It does quite some stuff, but am I correct that the “essence” of it is:

nix-build '<nixpkgs/nixos>' -A vm

?

My use-case would be similar to the sshd example. Run a few services on Debian but have all the configuration in exactly one place (and versioned with git, I know there is etckeeper but don’t want to go there). The desired outcomes would be easier maintenance and have a show-case to perhaps eventually also move/boot that machine to “full” NixOS.

So basically I could instantiate <nixpkgs/nixos> and then symlink systemd services?

Thanks. Until now I always thought of NixOS as some kind of separate wrapper around Nix, some tooling from a different repo + Nix if you wish. But apparently nixpkgs has all nixos derivations inside. That means Nix has “bateries included”. I mean in hindsight it’s obvious, but I never thought about that.

At some point NixOS was a separate repository (But coordination became annoying). And Nix per se definitely doesn’t require using specifically Nixpkgs!

nixos-shell is a really nice thing. It does quite some stuff, but am I correct that the “essence” of it is:

nix-build '<nixpkgs/nixos>' -A vm

I think it was more towards a container, but generally yes.

So basically I could instantiate <nixpkgs/nixos> and then symlink systemd services?

Yes, you can also do that. My example does not build a full NixOS system and does not have sufficient config for that, but you can even build «the NixOS you would prefer to run here» and use a few units out of it.

Of course, as you will not want to use some (that overlap with Debian-provided ones), you need to be careful and keep track of NixOS unit names changing. It doesn’t seem to be a frequent event, but NixOS does not promise anything about the unit names… You can probably automatically assert the existence of the chosen units, but in principle there might also be a problem with NixOS changing the unit dependencies.

1 Like

I’m also waiting for a solution about this, I perfer nixos module than home-manager, so if there is a way to use nixos module on other distributions it will be wonderful!