Specifying unstable commit directly in configuration.nix

As the title says, instead of the channel being managed by nix, I’d like to specify it directly in the configuration.nix file. Is this possible?

1 Like

Yup, I have deleted all my channels and do this:

let
  channelRelease = "nixos-19.09pre182429.98e3b90b6c8";  # 2019-06-11 02:29:22
  channelName = "unstable";
  url = "https://releases.nixos.org/nixos/${channelName}/${channelRelease}/nixexprs.tar.xz";
  sha256 = "1x5c4w5yh839zvinjiprl4gj8w8cpqg215iab1qy62rrfpwyx55b";

  pinnedNixpkgs = builtins.fetchTarball {
    inherit url sha256;
  };
in
....
nix.nixPath = [
  "nixpkgs=${pinnedNixpkgs}"
];
programs.command-not-found = {
  enable = true;
  dbPath = "${pinnedNixpkgs}/programs.sqlite";
};

I fetch from releases.nixos.org becaues there a programs.sqlite database was generated with all the programs and in which package they are.

4 Likes

Seems to work fine for me, thanks! A question though: How do I find out the channelRelease for the most current nixos-unstable?
Edit: Also, after removing my only channel via nix-channel --remove, nix-shell gives me a an error about file 'nixpkgs' was not found. Do I simply have to re-login so some environment variable gets updated?

Yes this option set an environment variable used by the nix commands, you will have to relogin or open a new shell to use it.

1 Like

Oh yes and also you have to rebuild twice because for the first rebuild your current channel will be used.
To have it build in one go, you can use

sudo nixos-rebuild -I nixpkgs=https://releases.nixos.org/nixos/unstable/nixos-19.09pre182429.98e3b90b6c8/nixexprs.tar.xz test

You can find the latest channel information here: https://nixos.org/channels/nixos-unstable

If you wanted, you could also fetch a commit directly from the source repo, but as I said, those don’t contain programs.sqlite and you command-not-found will not work. (Well you could use that from the channel. It doesn’t really matter if it’s out of date)

1 Like

Excellent, seems to work fine. Thanks!

Strange. Now when I try to nixos-rebuild switch, I get:

error: file 'nixos-config' was not found in the Nix search path (add it using $NIX_PATH or -I), at /nix/store/4xv8ps2vlsaz8gam9w4kvq2rz54fp8kp-nixexprs.tar.xz/nixos/default.nix:1:60

My NIX_PATH is:

/root/.nix-defexpr/channels:nixpkgs=/nix/store/3k66012dfv1cw5bybm1jcx64gg98ymaf-source

Edit: After manually augmenting my NIX_PATH with nixos-config=/etc/nixos/configuration.nix, rebuilding works. But you apparently don’t need that @JohnAZoidberg?
Edit 2: Also, rebuilding now doesn’t work with sudo anymore.

I do need os-config=/etc/nixos/configuration.nix, sorry. It’s in my config but I omitted it because I thought it wasn’t needed.

Should work with sudo though.

I’ve also got this (zoid being my username) but I think I needed that for a different reason (I think for installing unsigned derivations e.g. from cachix)

    nix.trustedUsers = [ "root" "zoid" ];