News for hackers. Stuff that matters.
Re:NixOS 21.05 by Nullabillity on Wednesday June 02, 2021 @11:58AM (#27370224)
> So if I understand correctly, I could declaratively specify my workstation, say I want vim, podman, codium, kubectl, curl, tmux, firefox, zettlr. I could put this in a configuration and have my workstation anywhere I can grab that from?

Kind of. It works very well if you own multiple computers that you want to be configured similarly (like a dotfiles repo on steroids).

It doesn't work so well for I borrowed my coworker's computer for 5 minutes and want to use my own Vim configuration.

However, Nix does also supply the "nix run" command, which allows you to use software without installing it permanently (but without NixOS' configuration support).

> Is there some way I can boot-to-git-configuration? So I could do this in RAM on someone else's hardware, like a network boot?

Yes. You could either build an image with a service that git clones your configuration and switches to it, or you could build an image containing a prebuilt snapshot of your configuration.

Either approach should be possible for basically any medium (USB drive, DVD, netboot, whatever). That said, for the build-and-switch setup I'd recommend something that can give at least /nix/store a writable partition (to avoid having to rebuild/redownload the whole world on every reboot).

Re:NixOS 21.05 by Sleepytime on Wednesday June 02, 2021 @12:31PM (#27370694)
>It doesn't work so well for I borrowed my coworker's computer for 5 minutes and want to use my own Vim configuration

You could use something like nixos-shell[1] to spin up a headless VM of your machine into your current shell.

[1]https://github.com/Mic92/nixos-shell

Re:NixOS 21.05 by gmfawcett on Wednesday June 02, 2021 @01:57PM (#27371878)
Well that is pretty neat. Thanks for the mention of nixos-shell. I've been a NixOS daily-driver for the past 6 months or so, but I am still picking up new ideas on a daily basis. :)
Re:NixOS 21.05 by Sleepytime on Friday June 04, 2021 @10:57PM (#27401672)
It's been my daily for not much longer than that, and almost every time I play with NixOS itself I get the sense of wonder and possibility in computers that I haven't had since I was a teenager. It's definitely a force multiplier.
Re:NixOS 21.05 by alias_neo on Wednesday June 02, 2021 @03:32PM (#27372984)
Ive seen mention to "switching" to a configuration a few times now, what does that mean technically? Is it a reboot and select a different grub option, does it take time/have to download things? What really is "switching"?
Re:NixOS 21.05 by Gaelan on Wednesday June 02, 2021 @04:50PM (#27373858)
Each NixOS machine has a current configuration, symlinked from /run/current-system. For example, my NixOS laptop currently has this:

    /run/current-system -> /nix/store/95n5xr5n8bw6xbab8fiz6cqc6mydryg8-nixos-system-Sweetpea-21.11pre291991.ea7d4aa9b82
My $PATH contains /run/current-system/sw/bin, so all of my machine's (globally-installed) software comes from whatever the current configuration is. There's also some other stuff in there, like /run/current-system/kernel and /run/current-system/etc, which contain what you'd expect.

Let's say I want to change something. I edit /etc/nixos/configuration.nix, then run "nixos-rebuild build", which produces this:

    /nix/store/0fhxjqbv20psbkjvw70wni9ww2cxfqgm-nixos-system-Sweetpea-21.11pre292748.6933d068c5d
That step does all of the downloading, etc, but it doesn't actually change anything on my system—the /run/current-system symlink hasn't changed, so I'm still running on the old configuration.

When I'm ready to change, I run "/nix/store/0fhxj.../bin/switch-to-configuration". This step actually changes the /run/current-system symlink, updates /etc, restarts any daemons that were updated, etc. Obviously, if your configuration has a new kernel, that won't be applied until you reboot.

In practice, we almost always just run "nixos-rebuild switch", which does the build and switch in one go.

This whole process is entirely idempotent and reversible; I can switch back to any configuration I've ever built (unless I've since removed them to save space, of course). GRUB also displays a list of every configuration you've ever built, so you can always boot into a stable configuration even if you've somehow made a royal mess of things.

Re:NixOS 21.05 by alias_neo on Wednesday June 02, 2021 @06:57PM (#27375055)
Thanks for taking the time to describe that, it makes sense now.

I'm impressed that it manages restarting everything on the fly without a reboot on a running system.

Re:NixOS 21.05 by pxc on Thursday June 03, 2021 @12:12AM (#27377144)
On rare occasions, there can be problems restarting a service, like if the service in the new configuration in fact relies on a newer kernel module than what you've got in your running configuration. In addition, sometimes Nix's garbage collector won't dispose of something because it can tell you've still got some processes running that use it or something like that, and so there's a bit of space you can't free up until after reboot. And of course, kernel changes still require reboots on NixOS.

All in all, the service management stuff is handled very gracefully imo. I've never run into real trouble with it (and one time I had a power outage in the middle of a `nixos-rebuild switch`).

Re:NixOS 21.05 by Nullabillity on Wednesday June 02, 2021 @04:48PM (#27373833)
Building the new configuration (and downloading or building dependencies), adding the bootloader entry, and activating the new configuration (stopping removed services, starting new services, reloading changed services, that kind of thing).

You don't need to do all three: you can skip the bootloader if you want to try something temporarily, and you can skip activation if you want to wait with that until the next reboot. There are also some changes that can't be activated without a reboot, such as changing the kernel.

> Does it take time/have to download things?

Building has to download or build stuff that isn't in the cache. But contrary to, say, Docker it understands the build graph, so it only rebuilds actual dependees.

Activation depends on how many services you've changed, and how quickly they restart. Updating the bootloader is nearly instant.

Re:NixOS 21.05 by alias_neo on Wednesday June 02, 2021 @06:59PM (#27375068)
Thats pretty incredible. So I can work on configs, switch back and forth until it's exactly right and then switch to it permanently.

Where's a good place to start? Some of the configs people are throwing about are quite involved and look like they need a bunch of specialist knowledge.

Thanks for taking the time to explain. Can't wait to start trying this out.

Re:NixOS 21.05 by pxc on Thursday June 03, 2021 @12:23AM (#27377201)
Just take a few minutes to skim the NixOS manual, then keep it in front of you on another device while you do an install. Enable a web browser, a desktop environment, and NetworkManager in your initial configuration.nix.

Then just start adding software that you want to be able to use. Search for it first in the NixOS options[1]. If you see it there, enable it and configure it using the options that make sense to you. If you don't see it there, search for it in the package collection[2], then use the name you find for it there to add it to `environment.systemPackages` in your `configuration.nix` file.

Just kinda take it easy and continue with that process until you have an environment that's more or less comfy. Then you're free to revisit your config and think about stuff like tying it in with your dotfiles, using Nix to manage your home directory, services you might want to run, etc.

—

1: https://search.nixos.org/options?channel=21.05&

2: https://search.nixos.org/packages?channel=21.05&

Re:NixOS 21.05 by kaba0 on Wednesday June 02, 2021 @02:44PM (#27372388)
> However, Nix does also supply the "nix run" command, which allows you to use software without installing it permanently (but without NixOS' configuration support).

What do you mean without config support? It runs a nix derivation which can be arbitrarily complex. Do you mean your /etc/nixos/configuration.nix file? Because you are not really using it either, only for creating a derivation that will become your system. A nix-shell of a user will by default use the user’s channel and may not do anything with the global config.

Re:NixOS 21.05 by pxc on Wednesday June 02, 2021 @03:23PM (#27372874)
Yeah, I think they just mean without the conveniences of the NixOS module system. You can definitely bundle config with an app and store it in a repository's shell.nix or a flake or whatever.