Nixos configuration (fails) vs nix-env (works) # e.g. brscan5

  • system: "x86_64-linux"
  • host os: Linux 5.15.33, NixOS, 21.11 (Porcupine)
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.3.16
  • channels(root): "nixos-21.11.337040.a62ce97f92b"
  • channels(usera): "home-manager-21.11, nixos-21.11.337040.a62ce97f92b, nixos-hardware, nixpkgs-21.11.337040.a62ce97f92b, nixpkgs-unstable-22.05pre369462.d08394e7cd5"
  • nixpkgs: /home/usera/.nix-defexpr/channels/nixpkgs

environment.systemPackages = with pkgs; [
building '/nix/store/yvjvz08dn0a4fxyrzbzvykgdxs0v1ivg-unit-script-cups-pre-start.drv'...
building '/nix/store/kwai72hjyxhb22x529r5dm4nybcs123a-unit-cups.service.drv'...

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0
curl: (22) The requested URL returned error: 404
error: cannot download brscan5-1.2.6-0.amd64.deb from any mirror
builder for '/nix/store/35gcqaj8pnp1ckdlmwdzb64f2pl71dm7-brscan5-1.2.6-0.amd64.deb.drv' failed with exit code 1


nix-env -i brscan5

warning: unknown setting 'experimental-features'
warning: name collision in input Nix expressions, skipping '/home/usera/.nix-defexpr/channels_root/nixos'
installing 'brscan5-1.2.9-0'
these paths will be fetched (81.67 MiB download, 369.33 MiB unpacked):
copying path '/nix/store/ybvzxz191sbhac1bgjcq3slvzdkmfid7-brscan5-1.2.9-0' from ''...
building '/nix/store/q7dms5y4n625w2695bdrphrbl62mdhqa-user-environment.drv'...
created 7770 symlinks in user environment

Your system configuration points to a different version of nixpkgs than your nix-env uses from the users channels.

Probably upstream removed the sources for the old version.

Also, using -i is not really deterministic, it installs whatever it wants and matches the search term. You might want to prefer -iA to deterministically install same attributes in either version.

Currently it seems as if nix-env got 3 channels it could use to search, and then it picks the one with the seemingly highest version.

how to identify / verify this (difference in versions) [and how to keep others in sync]?

The easiest and obvious solution is to generally not use nix-env.

For the system channel, it might be that 21.11 just hasn’t the newest update and will never receive it, as a guess you’ll need to update the system to unstable or wait for 22.05 getting released properly.

I only use nix-env if this is the “only useful” way in nixos

nix-env -q


the point is that nixos config FAILS - but nix-env what wouldn’t be used WORKS

  • and I cannot see that other packages are used in one or the other

Nix-env uses some magic to get from name to package, searching everything below ~/.nix-defexp IIRC.

For your brscan it probably finds something that it considers “newest” in the configured unstable variant of the nixpkgs.

Your user has 3(!) different channels for nixpkgs that nix-env -i might pick from.

If you’d use nix-env -iA and specifying the one user channel that corresponds to the same stable as your system uses, it would probably fail as well.

Brother keeps removing the links to older brscan5 drivers, and since they’re non-free they don’t get cached (hence the 404 for 1.2.6-0 version). I’m not aware of a good way to workaround this issue.

I don’t expect installing brscan5 via nix-env (or via systemPackages) would work, there’s a bit of magic in the NixOS module to make the brscan5 sane backend function correctly (it’s got some hardcoded paths in the binary that look for files in specific locations, and needs to be integrated with the sane stuff).

Once you’ve got the NixOS config pulling from an updated channel, you should be able to add the scanner driver like this:

  hardware.sane = {
    enable = true;
    brscan5.enable = true;

(Thanks again for the information)

it looks not to be back-ported to 21.11 - so I would have to load it from unstable and use an overlay …