Switching from 24.11 to unstable declaratively (without channels)

Hey there!

I have a relatively freshly setup NixOS 24.11. I have added the unstable channel using the nix-channel command (not declarative).

I am not sure if by default a channel is set. I heard that people run NixOS without channels?

By default NixOS is configured stable. Editing the /etc/nixos/configuration.nix and setting the system.stateVersion to unstable does not work. I have no idea why, as this would make a lot of sense.

Non-Declarative way

I removed the stable channel and added the unstable one

sudo nix-channel --remove nixos
sudo nix-channel --add https://nixos.org/channels/nixos-unstable nixos
sudo nix-channel --update

(Btw what is the difference between nixos-unstable and nixpkgs-unstable ?)

This does not seem to work, I get issues for packages that are not on stable

Never change stateVersion. Change channels or flake inputs.

Yes I did so, I changed the stateVersion to 25.05 (as mentioned in the error message). But I still get that issue.

The question is, how can I change the channel in the config?

Erm, read that message again. Also maybe read this thread, and the comment in your configuration.nix that you hopefully didn’t just blindly delete: Using hashes for `stateVersion` instead of human-readable strings

You cannot, this is an inherent flaw in the design of channels.

If you want to have a fully declarative NixOS configuration, you need to stop using channels and either use flakes or niv.

Using flakes can be helpful since it also enforces pure evaluation, which means that you cannot accidentally depend on something without realizing it’s impure (e.g. importing from something included via <>, or a builtins.readFile outside your flake or such), but they’re experimental and come with a bunch of baggage. niv is fully usable today, but you still need to know what you’re doing to avoid having reproducibility holes in your configuration.

1 Like

@tlater I dont use flakes (yet) and tried using channels with no success. So no reason for such annoyed comments.

I have read the comment in the config now and it makes sense. I have changed that back to the initial 24.11 and added the unstable channel as per the docs

sudo nix-channel --add https://channels.nixos.org/nixos-unstable nixos

I realized there was an identical channel called nixos-unstable which I then removed and updated the channels.

I try to rebuild my system with the same error

      error: undefined variable 'nix-index-database'
       at /etc/nixos/configuration/packages.nix:57:9:
           56|         nix-index
           57|         nix-index-database #only in unstable
             |         ^
           58|         home-manager

I am thinking about switching my system to flakes, but until then I would like to make this work?

I have already setup a flake.nix

{
  description = "General Flake";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  };

  outputs = { self, nixpkgs, ... }@inputs: {
    nixosConfigurations.nixos = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        ./configuration.nix
      ];
    };
  };
}

It seems that here I can set a different input URL declaratively. But rebuilding the system still shows the undefined packages, even though the only channel is the unstable channel, and the input is unstable??

I removed the channel, still the same issue. The package only in unstable is not found.

I’m not sure what you’re referring to here, I’m just explaining that precisely what you’re asking for is not possible, and giving you alternatives.

Unless it’s the thing about stateVersion, in which case sorry if the tone came off wrong, but I think you genuinely just misread what @waffle8946 was saying.

Is what you actually want to do just using unstable with channels then?

If I understand what you did correctly, you now have only one channel on your system, which is named nixos and points to nixos-unstable. This should let you use unstable, yes, assuming you also updated your channels at some point.

nix-index-database doesn’t seem to be a package in nixpkgs, though, so switching to unstable will not make it exist.

What is it that you’re actually trying to achieve by switching to unstable? Why do you think this package exists, and why do you think it’s in unstable? I think we’ll be able to help better if you explain the background here.

1 Like

The package is called nix-index and it’s on stable too.
nix-index-database is a separate project.

Since you don’t use flakes, one option would be to use the ad-hoc download instructions: https://github.com/nix-community/nix-index-database?tab=readme-ov-file#ad-hoc-download

1 Like

I have no idea why I thought that this was packaged there? I will just remove it and generate the search db locally, thanks!

So it worked

  • switching to flakes (that one config I posted above)
  • changing the flake input to use unstable
  • keeping the version in configuration.nix at the default
  • removing all channels and updating them