I’ve reached a point in my configuration where I realise my understanding of flakes is lacking. Are there any guides that would help clarify the fundamental concepts?
While I have read some guides, none quite fulfil my need. In case it helps, these are some of the questions I’m asking myself. While direct answers are welcome, I’m really looking for something to give me better understanding (so I don’t have to ask even more basic questions later!)
If using flakes, what is the role of channels? I’m starting to think they are not relevant…
Are the inputs (for example nixpkgs.url = “nixpkgs/nixos-unstable” analogous to channels
To follow stable packages, what commands are needed to perform an update to current packages. Is it: nix flake update followed by nixos-rebuild switch --upgrade (I have two machines with very similar configs that yield 2 different versions of the Brave browser, and so I am starting to doubt my updates)
Advanced question: How do I specify a particular version of a package (rather than follow the nixpkgs-unstable “set” of packages). At the moment nvidia-drivers seems broken in both unstable and 23.05. So can I find a different version and use that separately?
flakes and channels are orthogonal. If you use one, you probably don’t want to use the other. On my machine, I don’t have channels:
$ nix-channel --list
$ doas nix-channel --list
yes, inputs + flake.lock is analogous to channels. input says what “symbolic name” to follow, while .lock pins down the exact version.
I use nix flake update && nixos-rebuild switch. I think--upgrade is channel-specific thing.
You can specify particular version of the whole nixpkgs-unstable by editing the flake.lock. I didn’t have to use specific version for just one package (as opposed to everything); this should be possible, but,as i said, i am no pro
So having checked I am really using updating flakes (rather than channels, which I have now removed), I still have an issue - the Brave web browser is not being updated. If I do nix flake update, some elements change (home manager last time). If I add something, the rebuild takes it into account. But still no update.
I have home-manager as a module, and brave as a “user” app (I also tried globally installing it, but no change). I tried changing my input style (see below)
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs.url = "nixpkgs/nixos-unstable"; # old version
which: no brave in (/run/wrappers/bin:/root/.nix-profile/bin:/etc/profiles/per-user/root/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin)
which: no print in (/run/wrappers/bin:/root/.nix-profile/bin:/etc/profiles/per-user/root/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin)
I think the removing channels did something ?)
I’d be happy to show my full config, but I have lots of files and haven’t yet got my head around how to store it on github (or similar). I#m not experienced enough yet to either post the full issue or work out where to start my investigation, so your help is much appreciated!
Just to ensure there’s no confusion about this; nix flake update only updates the flake.lock file, nothing else. If you have it in a repo and pull the new version of the lockfile, you don’t have to run nix flake update again before nixos-rebuild switch. What’s in the flake.lock determines what gets installed reproducibly. Once you ran nixos-rebuild build, the same paths will be in your store on both machines.
Some running programs will not get notified about the changes, though. This is why @NoobZ asked how you’re opening Brave, as your Desktop Environment will not know that there’s a new version of Brave installed, and as the old version doesn’t get deleted, it can still successfully open that one.
So to make 100% sure the same environment is loaded fully on both machines, you have to reboot. I know this is super cliché, but have you tried that?
These are most likely equivalent. I quickly tried this to see the difference. So, with nixpkgs/nixos-unstable and nix flake update, my flake contains this:
You can see that all the relevant parts of github:NixOS/nixpkgs are part of the locked ref already. But in the original ref, it says "type": "indirect". That basically means “check the flake registry and use that”. And what does the registry contain?
$ nix registry list
global flake:nur github:nix-community/NUR
global flake:nixpkgs github:NixOS/nixpkgs/nixpkgs-unstable
global flake:templates github:NixOS/templates
So as you scan see, nixpkgs maps to github:NixOS/nixpkgs/nixpkgs-unstable already, so adding nixpkgs-unstable is redundant. In fact, even declaring nixpkgs as an input is redundant! You can remove it completely. When your outputs function contains nixpkgs in its argument set, it will be automatically inserted from the registry. Whether that’s a good idea is another story.
And indeed, when I swap out nixpkgs/nixpkgs-unstable for the longer github:NixOS/nixpkgs/nixpkgs-unstable and run nix flake update again, I see this in my flake.lock:
As @matklad already suggested, adding nixpkgs again as another input is a good solution. The tricky part can be how to actually find that old version. Ideally, it’s in 22.11 or 22.05 or something like that, so you would just add nixpkgs-22-11.url = "nixpkgs/release-22.11"; to your inputs and explicitly use the nivdia-driver from that. If you need a version in between, you have to check the NixOS channel on hydra to find the correct revision to use so that binary downloads are available. Let’s climb that hill when we get to it, though
global flake:nixpkgs github:NixOS/nixpkgs/nixpkgs-unstable
So I am using unstable. I also note that brave is the same version on 23.05 and unstable, so that has been a red herring (but I have learnt lots about flakes from everyone’s comments on this, so that is great!)
So I have been very silly…while I do reboot to ensure all changes have been made it wasn’t enough!
As @NobbZ predicted, the KDE toolbar hasn’t updated the location of brave (it has never happened before in the 6 months or so I have been using Nixos with KDE).
Many thanks to everyone who joined in the conversation - I have learnt so much more about Nix which is very useful.
Update for clarification:
The pinned app in the taskbar had not updated (It is just an icon with a location after all). It looks as though the start menu entry itself had updated, but when you select from the start menu, or run from the command line when brave is already open, it simply uses the same session.
I already had the old brave open for easy comparison with version number, so alternative routes just had me open more of the old one. Shutting down the old brave and selecting from the start menu.
This behaviour made me think there was only one version of brave on the system!