Help with installing unstable packages

So i tried installing unstable packages but i’m getting this error:

[nilkamal9@nixos:~]$ sudo nixos-rebuild --upgrade switch
unpacking channels…
building Nix…
building the system configuration…
error: attribute ‘unstable-pkgs’ missing

   at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:512:28:

      511|         builtins.addErrorContext (context name)
      512|           (args.${name} or config._module.args.${name})
         |                            ^
      513|       ) (lib.functionArgs f);

(use ‘–show-trace’ to show detailed location information)

here are some relevant parts of my configuration.nix:
first

system info:

  • system: "x86_64-linux"
  • host os: Linux 6.1.59, NixOS, 23.05 (Stoat), 23.05.4448.5550a85a087c
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.13.6
  • channels(nilkamal9): ""
  • channels(root): "nixos-23.05, nixos-unstable"
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos

$NIX_PATH:
/home/nilkamal9/.nix-defexpr/channels:nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels

Try prepending pkgs. to the unstable packages.

I suggest to get rid of this altogether by setting environment.systemPackages = with pkgs; [. This way, pkgs. is prepended to every entry so you save yourself the work. Just remember to remove pkgs. from the the packages that are already there.

u mean something like pkgs.unstable-pkgs.<pkg_name>? but that not where the error is?

You’re right, there is an additional error. See my config as a reference (i’m on unstable and currently have no overrides enabled but you can see how it’s done):

{
  # config,
  # lib,
  pkgs,
  ...
}: {
  imports = [
    ./hardware-configuration.nix
    ./hardening.nix
    ./home.nix
  ];
  nixpkgs = {
    # config = {
    # allowUnfree = true;
    # allowUnfreePredicate = pkg:
    # builtins.elem (lib.getName pkg) ["nvidia-x11" "nvidia-settings"];
    # packageOverrides = pkgs: {
    # stable = import <nixos-stable> {config = config.nixpkgs.config;};
    # stable = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/nixos-23.05.tar.gz") {};
    # unstable = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz") {};
    # };
  };

if you don’t mind how do i use it? i’m new to nix though. i guess smth like unstable.?

In your case, try this at the beginning of your configuration.nix:

{
  # config,
  # lib,
  pkgs,
  ...
}: {
  imports = [
    ./hardware-configuration.nix
  ];
  nixpkgs = {
    config = {
    allowUnfree = true;
    packageOverrides = pkgs: {
    unstable = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz") {};
    };
  };
};

and this to replace your present entries (vim and emacs are just examples):

  environment.systemPackages = with pkgs; [
    vim
    unstable.emacs
   ];

As a suggestion: use nil and alejandra with a compatible editor (e.g. helix or neovim) to edit your config. It will make it easier and point out errors to you.

2 Likes

thank you so much for helping me

It does not look like OP used overlays so the unstable would not be inside pkgs.

The error is caused by adding unstable-pkgs argument to the NixOS configuration module – module system does not really care about default argument values specified in Nix and will always try to populate the argument values by itself. And because the argument is not defined anywhere, it will fail.

Using overlays to insert the value to the main pkgs set as mentioned above is a common option but you can also pass the module system the argument to make the original code work:

{ unstable-pkgs, ... }:

{
  environment.systemPackages = [
    unstable-pkgs.vscodium
  ];

  _module.args.unstable-pkgs = import <nixos-unstable> {};
}

Personally, I find using separate arguments for different package sets cleaner than putting everything into a single pkgs.

This worked. just needs an extra }; after the unstable line in the first code

Right, i just added it.