Why nixos-rebuild won't use my updated nixpkgs flake?

So here I am trying to use flakes to manage my NixOS systems. I maintain my own fork of Nixpkgs in a branch called myChannel on github:doronbehar/nixpkgs. Hence:

$ nix registry list
user   flake:nixpkgs github:doronbehar/nixpkgs/myChannel
global flake:blender-bin github:edolstra/nix-warez
global flake:dwarffs github:edolstra/dwarffs
global flake:hydra github:NixOS/hydra
global flake:nimble github:nix-community/flake-nimble
global flake:nix github:NixOS/nix
global flake:nixops github:NixOS/nixops
global flake:nixos-hardware github:NixOS/nixos-hardware
global flake:nixos-homepage github:NixOS/nixos-homepage/flake
global flake:nur github:nix-community/NUR
global flake:nixpkgs/release-19.09 github:edolstra/nixpkgs/release-19.09
global flake:nixpkgs github:NixOS/nixpkgs
global flake:templates github:NixOS/templates
global flake:patchelf github:NixOS/patchelf

Overall this works fine - some packages defined only on my fork are evaluated on nixos-rebuild. Today, I wanted to get a zoom-us update quicker then the channels, and so I went to my nixpkgs clone and committed the update to myChannel and pushed it to my fork. Now, nixos-rebuild switch won’t update zoom-us, i.e:

sudo nixos-rebuild switch --impure --flake '/etc/nixos/#'
readlink $(where zoom-us)

Shows zoom-us wasn’t updated (rebooting or logging in and out won’t help). I think I can notice nixos-rebuild checks the last commit of the defined nixpkgs flake, but it won’t update it still, apparently.

Maybe this has to do something with NIX_PATH? Before I started using flakes, I had in /etc/nixos/nixpkgs a Nixpkgs clone always checked out on myChannel. And so I set (via nix.nixPath):

$ echo $NIX_PATH
nixpkgs=/etc/nixos/nixpkgs:nixos-config=/etc/nixos/configuration.nix:nixpkgs-overlays=/etc/nixos/overlays-compat/

Part of the motivation for me to use flakes and nixUnstable in general was to allow me not to manually go to /etc/nixos/nixpkgs and git pull there. Does nixUnstable even adheres NIX_PATH? (Excluding of course the compatibility nix- commands).

Setting and unsetting NIX_PATH won’t help. I also tried:

sudo env -u NIX_PATH nixos-rebuild switch -I nixpkgs=https://github.com/doronbehar/nixpkgs/archive/myChannel.tar.gz --impure --flake '/etc/nixos/#'

And:

sudo nixos-rebuild switch -I nixpkgs=$PWD --impure --flake '/etc/nixos/#'

Where $PWD was where my Nixpkgs clone was checked out on myChannel.

The only way around this I could find is to switch back to nixStable by:

  1. Removing /etc/nixos/flake.nix
  2. Commenting nix.package = pkgs.nixUnstable
  3. Running once (with nixos-rebuild using nixUnstable):
sudo nixos-rebuild switch -I nixpkgs=https://github.com/doronbehar/nixpkgs/archive/myChannel.tar.gz --impure
  1. And once more with nixos-rebuild using nixStable
sudo nixos-rebuild switch -I nixpkgs=https://github.com/doronbehar/nixpkgs/archive/myChannel.tar.gz

Got it! All I needed was:

diff --git i/flake.nix w/flake.nix
index 8860a90..84833d4 100644
--- i/flake.nix
+++ w/flake.nix
@@ -1,4 +1,7 @@
 {
+  inputs = {
+    nixpkgs.url = "github:doronbehar/nixpkgs/myChannel";
+  };
   outputs = { self, nixpkgs }: {
     nixosConfigurations = (
       nixpkgs.lib.genAttrs [ "ZENIX" "NUX" ]
1 Like

not necessarily related but one thing that messed with my nerves is the autolocking. I override several flakes with local paths and you have to be careful to commit every file and run nixos-rebuild with --no-write-lock-file otherwise it wont take into account new changes.

I’m getting the issue now as well, no idea why:

building the system configuration...
error: --- Error ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ nix
cannot write modified lock file of flake 'git+file:///etc/nixos?ref=master&rev=159d4d1b33e5b2917308f41d11bb8b0e50c209a7' (use '--no-write-lock-file' to ignore)

Indeed using --no-write-lock-file helps, but I don’t understand what’s going on and why can’t I just tell it to grab the latest version and write the lock file and commit it…

1 Like

Make sure all flakes have a lock file. Checking your nixpkgs/myChannel it seems to be missing there.

edit:
At least, I think it was something like that when I encountered the issue. However, nixpkgs itself does not have a lock file either, so it must be something else then…

…how is nixos-rebuild build without sudo?

IIRC at some point I ran nixos-rebuild --update-input nixpkgs and I had my lock file updated but not committed. Then I committed it manually, and then I got the no-write-lock-file issue and now I need to run sudo nix flake update nixpkgs and then sudo nixos-rebuild --update-input nixpkgs --no-write-lock-file which does grab the latest nixpkgs I want but it indeed doesn’t touch the lock file :man_shrugging:.

But, I learned that git rm flake.lock and then:

sudo nixos-rebuild switch --impure --flake '/etc/nixos/#' --update-input nixpkgs --commit-lock-file

Worked.

1 Like