# Mixing stable and unstable packages on flake-based NixOS system

**URL:** https://discourse.nixos.org/t/mixing-stable-and-unstable-packages-on-flake-based-nixos-system/50351
**Category:** Help
**Created:** [August 9, 2024, 4:26am UTC](https://discourse.nixos.org/t/mixing-stable-and-unstable-packages-on-flake-based-nixos-system/50351 "2024-08-09T04:26:02Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![blit](https://discourse.nixos.org/user_avatar/discourse.nixos.org/blit/32/17052_2.png) [@blit](https://discourse.nixos.org/u/blit)
#### Post date: [August 9, 2024, 4:26am UTC](https://discourse.nixos.org/t/mixing-stable-and-unstable-packages-on-flake-based-nixos-system/50351/1 "2024-08-09T04:26:02Z")

</div>

Hello everyone. My system is based on flakes (nix-channel is disabled). How can I use some packages from nixos-unstable while keeping the rest of my system on the stable branch? I’d like to achieve something like this:

```nix
environment.systemPackages = with pkgs; [
    firefox
    thunderbird
    unstable.osu-lazer-bin
];

```

In other words, I wanna be able to access osu-lazer-bin from the unstable branch via pkgs.unstable.osu-lazer-bin.  
I’ve already seen multiple approaches to achieve this, but none of them worked for me, maybe it’s because my system uses flakes, idk.

_translated with llama 3.1 405b :3_

---

<div class="post-metadata">

### Author: ![aos](https://discourse.nixos.org/user_avatar/discourse.nixos.org/aos/32/26570_2.png) [@aos](https://discourse.nixos.org/u/aos)
#### Post date: [August 9, 2024, 4:44am UTC](https://discourse.nixos.org/t/mixing-stable-and-unstable-packages-on-flake-based-nixos-system/50351/2 "2024-08-09T04:44:00Z")

</div>

You should be able to add the unstable nixpkgs as part of your inputs, then import it and add that package directly. Something like this:

```nix
 inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/release-24.05";
    nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
 };

 outputs = {nixpkgs, nixpkgs-unstable, ... }:
 let
   system = "x86_64-linux";
   pkgs = import nixpkgs { inherit system; };
   pkgsUnstable = import nixpkgs-unstable { inherit system; };
 in
 {
    # now along with `pkgs` you also have `pkgsUnstable`
    # and can do: pkgsUnstable.osu-lazer-bin
 }
```

---

<div class="post-metadata">

### Author: ![Nebucatnetzer](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nebucatnetzer/32/5770_2.png) [@Nebucatnetzer](https://discourse.nixos.org/u/Nebucatnetzer)
#### Post date: [August 9, 2024, 8:00am UTC](https://discourse.nixos.org/t/mixing-stable-and-unstable-packages-on-flake-based-nixos-system/50351/3 "2024-08-09T08:00:52Z")

</div>

Something like this should work:

```nix
  overlay-unstable = final: prev: {
    unstable = import nixpkgs-unstable {
      inherit system;
      config.allowUnfree = true;
    };
  };

  pkgs = import nixpkgs {
    inherit system;
    config = {
      allowUnfree = true;
    };
    overlays = [
      overlay-unstable
    ];
  };

```

Then you can do `pkgs.firefox` or `pkgs.unstable.firefox`.

---

<div class="post-metadata">

### Author: ![waffle8946](https://discourse.nixos.org/user_avatar/discourse.nixos.org/waffle8946/32/27221_2.png) [@waffle8946](https://discourse.nixos.org/u/waffle8946)
#### Post date: [August 9, 2024, 12:16pm UTC](https://discourse.nixos.org/t/mixing-stable-and-unstable-packages-on-flake-based-nixos-system/50351/4 "2024-08-09T12:16:18Z")

</div>

_EDIT: Huge caveat - I strongly recommend not mixing stable with unstable on the same system. It’s unsupported and can lead to confusing errors when going to run programs, due to glibc and graphics driver mismatches._

**Never set `pkgs` directly in the NixOS module system,** as the other answers are indicating.

Here’s a couple of concepts you need to know:

1. If you want to access some inputs, or some other value across your config without creating an explicit option for it, use `specialArgs` or `_module.args`. (For things that you `import`, you must pass them in `specialArgs` specifically to avoid infrec.)
2. Changing `pkgs` requires an overlay; however, for this application, you may not necessarily need one if you are willing to get away from the `pkgs.unstable` syntax specifically.

Which means the following:

1. Add an entry to your `inputs`, and pass them to your config via `specialArgs`, in your `flake.nix`:

2. Since you need an unfree package specifically, allow the unfree package somewhere in your NixOS config:

3. Then, use that config when importing the unstable nixpkgs, and then use the appropriate module arg in your package list.  
a. EITHER create a new module arg:

I’m personally against 3b, because an overlay for this is completely unnecessary and will likely slow down eval.

PS this has got to be one of the most-asked questions, it’s silly that we are still having to rewrite the answers from scratch in 2024…

---

<div class="post-metadata">

### Author: ![Nebucatnetzer](https://discourse.nixos.org/user_avatar/discourse.nixos.org/nebucatnetzer/32/5770_2.png) [@Nebucatnetzer](https://discourse.nixos.org/u/Nebucatnetzer)
#### Post date: [August 9, 2024, 5:50pm UTC](https://discourse.nixos.org/t/mixing-stable-and-unstable-packages-on-flake-based-nixos-system/50351/5 "2024-08-09T17:50:49Z")

</div>

> [@waffle8946](#):
>
> **Never set `pkgs` directly in the NixOS module system,** as the other answers are indicating.

Is that what is happening here?

> <https://github.com/Nebucatnetzer/nixos/blob/master/lib/mk_computer.nix>

> [@waffle8946](#):
>
> PS this has got to be one of the most-asked questions, it’s silly that we are still having to rewrite the answers from scratch in 2024…

You could add an article to nix.dev or the wiki.

---

<div class="post-metadata">

### Author: ![blit](https://discourse.nixos.org/user_avatar/discourse.nixos.org/blit/32/17052_2.png) [@blit](https://discourse.nixos.org/u/blit)
#### Post date: [August 10, 2024, 6:50am UTC](https://discourse.nixos.org/t/mixing-stable-and-unstable-packages-on-flake-based-nixos-system/50351/6 "2024-08-10T06:50:28Z")

</div>

Perfect! Used option 3a, this should definitely be written somewhere in the docs, at least not official.

---

<div class="post-metadata">

### Author: ![osbm](https://discourse.nixos.org/user_avatar/discourse.nixos.org/osbm/32/29975_2.png) [@osbm](https://discourse.nixos.org/u/osbm)
#### Post date: [October 13, 2024, 7:30pm UTC](https://discourse.nixos.org/t/mixing-stable-and-unstable-packages-on-flake-based-nixos-system/50351/7 "2024-10-13T19:30:27Z")

</div>

Hello, I am a bit new to flakes and the nix syntax. The tutorial i followed led me to a different outputs syntax so i am not sure how i can follow your step 1. Can you help? I am figuring this stuff out as i go so there are some holes in my understanding.

```nix
{
  description = "My system configuration";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
    unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
  };

  outputs = { self, nixpkgs, ... }:
    let
      lib = nixpkgs.lib;
    in {
      nixosConfigurations = {
        tartarus = lib.nixosSystem {
          system = "x86_64-linux";
          modules = [./configuration.nix];
          # revision = self.shortRev or self.dirtyShortRev or self.lastModified or "unknown";
        };
      };
    };
}

```

---

<div class="post-metadata">

### Author: ![sevos](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/s/f05b48/32.png) [@sevos](https://discourse.nixos.org/u/sevos)
#### Post date: [October 18, 2024, 3:54pm UTC](https://discourse.nixos.org/t/mixing-stable-and-unstable-packages-on-flake-based-nixos-system/50351/8 "2024-10-18T15:54:49Z")

</div>

Hey! Since you are new, I’ll throw in some syntax explanation. If you open your `configuration.nix`, you’ll see something like this:

```nix
{ config, pkgs, ... }:
{
  imports = [./hardware-configuration.nix];
  # ...
}

```

This is a nix function. On the first line you can see the attribute set that would be used as an argument, and the big attribute set after `:` is the return of the function.

So when you rebuild your system with a flake that you provided, here

```nix
tartarus = lib.nixosSystem {
  system = "x86_64-linux";
  modules = [./configuration.nix];
  # revision = self.shortRev or self.dirtyShortRev or self.lastModified or "unknown";
};

```

you call a function `lib.nixosSystem` that creates a configuration `tartarus` for you. Somewhere inside that `lib.nixosSystem` function the following happens:

- `config` is extracted from `nixpkgs`
- `pkgs` is extracted from `nixpkgs`. It looks something like `pkgs = nixpkgs.legacyPackages.${system};` (`system` is provided by you in argument to `nixosSystem`)
- `./configuration.nix` is read and called with these (and other) arguments

What you need to do is to extract the unstable version of `pkgs` and provide it in inputs to function in `./configuration.nix`.

To do this `nixosSystem` allows you adding attributes that would be used in calls to functions from `modules`. You can add attribute `specialArgs = { /* your args */ };` and your args would be used in a call to function in `./configuration.nix`. And you would also need to modify `./configuration.nix` by adding unstable version of `pkgs` as input.

So you’ll get something like this:

```nix
# In your flake declaration
inputs = {
  nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
  unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs, ... }:
let
  system = "x86_64-linux"
  lib = nixpkgs.lib;
  pkgs-unstable = unstable.legacyPackages.${system};
in {
  nixosConfigurations = {
    tartarus = lib.nixosSystem {
      inherit system; # inherited it from 'let' block
      modules = [./configuration.nix];
      specialArgs = { inherit pkgs-unstable; };
    };
  };
};

# In your configuration.nix:
{ config, pkgs, pkgs-unstable, ... }:
{
  # ...
  environment.systemPackages = with pkgs; [
    neovim # package from pkgs
    pkgs-unstable.ripgrep # package from pkgs-unstable
  ];
  # ...
}

```

---

<div class="post-metadata">

### Author: ![osbm](https://discourse.nixos.org/user_avatar/discourse.nixos.org/osbm/32/29975_2.png) [@osbm](https://discourse.nixos.org/u/osbm)
#### Post date: [October 18, 2024, 7:20pm UTC](https://discourse.nixos.org/t/mixing-stable-and-unstable-packages-on-flake-based-nixos-system/50351/9 "2024-10-18T19:20:32Z")

</div>

Wow, thank you so much for the detailed explanation. This is literally a game changer. One can write a very dynamic configuration logic with this. It is awesome.

---

<div class="post-metadata">

### Author: ![dixtel](https://discourse.nixos.org/user_avatar/discourse.nixos.org/dixtel/32/12155_2.png) [@dixtel](https://discourse.nixos.org/u/dixtel)
#### Post date: [January 2, 2025, 10:46pm UTC](https://discourse.nixos.org/t/mixing-stable-and-unstable-packages-on-flake-based-nixos-system/50351/10 "2025-01-02T22:46:51Z")

</div>

Hey,

```auto
pkgs-unstable = unstable.legacyPackages.${system};

```

should be

```auto
pkgs-unstable = inputs.unstable.legacyPackages.${system};

```

?

---

<div class="post-metadata">

### Author: ![drupol](https://discourse.nixos.org/user_avatar/discourse.nixos.org/drupol/32/9471_2.png) [@drupol](https://discourse.nixos.org/u/drupol)
#### Post date: [January 2, 2025, 11:10pm UTC](https://discourse.nixos.org/t/mixing-stable-and-unstable-packages-on-flake-based-nixos-system/50351/11 "2025-01-02T23:10:05Z")

</div>

Yes. Feel free to try and report feedback.

---

<div class="post-metadata">

### Author: ![dixtel](https://discourse.nixos.org/user_avatar/discourse.nixos.org/dixtel/32/12155_2.png) [@dixtel](https://discourse.nixos.org/u/dixtel)
#### Post date: [January 3, 2025, 11:52pm UTC](https://discourse.nixos.org/t/mixing-stable-and-unstable-packages-on-flake-based-nixos-system/50351/12 "2025-01-03T23:52:59Z")

</div>

I tested it and the following error will show:

```auto
error: undefined variable 'unstable'

```

So the fixed code will look like this:

```auto
# In your flake declaration
inputs = {
  nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
  unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs, ... }@inputs:
let
  system = "x86_64-linux"
  lib = nixpkgs.lib;
  pkgs-unstable = inputs.unstable.legacyPackages.${system};
in {
  nixosConfigurations = {
    tartarus = lib.nixosSystem {
      inherit system; # inherited it from 'let' block
      modules = [./configuration.nix];
      specialArgs = { inherit pkgs-unstable; };
    };
  };
};

# In your configuration.nix:
{ config, pkgs, unstable, ... }:
{
  # ...
  environment.systemPackages = with pkgs; [
    neovim # package from pkgs
    unstable.ripgrep # package from pkgs-unstable
  ];
  # ...
}

```

Also I don’t know if the following line is the correct way of adding additional arguments to nixos modules:

```auto
specialArgs = { inherit pkgs-unstable; };

```

I have multiple inputs in my flake.nix so I have declared this as:

```auto
nixosConfigurations.pc = nixpkgs.lib.nixosSystem rec {
...
   specialArgs = inputs // { unstable = inputs.unstable.legacyPackages.${system}; };
...
}

```

---

<div class="post-metadata">

### Author: ![drupol](https://discourse.nixos.org/user_avatar/discourse.nixos.org/drupol/32/9471_2.png) [@drupol](https://discourse.nixos.org/u/drupol)
#### Post date: [January 4, 2025, 5:21am UTC](https://discourse.nixos.org/t/mixing-stable-and-unstable-packages-on-flake-based-nixos-system/50351/13 "2025-01-04T05:21:09Z")

</div>

Run nix flake update !

---

<div class="post-metadata">

### Author: ![noofel.rouge](https://discourse.nixos.org/user_avatar/discourse.nixos.org/noofel.rouge/32/30017_2.png) [@noofel.rouge](https://discourse.nixos.org/u/noofel.rouge)
#### Post date: [February 16, 2025, 12:18pm UTC](https://discourse.nixos.org/t/mixing-stable-and-unstable-packages-on-flake-based-nixos-system/50351/14 "2025-02-16T12:18:45Z")

</div>

hello, having the same issue, but want to use unstable inside home-manager.

my flake.nix:

```auto
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
    nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
    home-manager = {
      url = "github:nix-community/home-manager/release-24.11";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = {self, nixpkgs, nixpkgs-unstable, home-manager, ...}@inputs: {
    nixosConfiguration.cesium = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      specialArgs = { inherit inputs; };
      modules = [
        ./configuration.nix
        home-manager.nixosModules.home-manager {
          ./home.nix
        }
      ];
    };
  };
}

```

my home.nix:

```auto
{inputs, config, pkgsUnstable, pkgs, ...}: {
  _module.args.pkgsUnstable = import inputs.nixpkgs-unstable {
    inherit (pkgs.stdenv.hostPlatform) system;
    inherit (config.nixpkgs) config;
  };
  programs.wezterm = {
    enable = true;
    package = pkgsUnstable.wezterm;
  };
}

```

but i am getting this error message:

```auto
error:
       … while calling the 'head' builtin
         at /nix/store/h3g3hcnwm00lhr41fj9d9ahy002d6h7k-source/lib/attrsets.nix:1574:11:
         1573| || pred here (elemAt values 1) (head values) then
         1574| head values
             | ^
         1575| else

       … while evaluating the attribute 'value'
         at /nix/store/h3g3hcnwm00lhr41fj9d9ahy002d6h7k-source/lib/modules.nix:816:9:
          815| in warnDeprecation opt //
          816| { value = addErrorContext "while evaluating the option `${showOption loc}':" value;
             | ^
          817| inherit (res.defsFinal') highestPrio;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'inputs' missing
       at /nix/store/h3g3hcnwm00lhr41fj9d9ahy002d6h7k-source/lib/modules.nix:515:48:
          514| addErrorContext (context name)
          515| (args.${name} or config._module.args.${name})
             | ^
          516| ) (functionArgs f);

```

---

<div class="post-metadata">

### Author: ![waffle8946](https://discourse.nixos.org/user_avatar/discourse.nixos.org/waffle8946/32/27221_2.png) [@waffle8946](https://discourse.nixos.org/u/waffle8946)
#### Post date: [February 16, 2025, 2:24pm UTC](https://discourse.nixos.org/t/mixing-stable-and-unstable-packages-on-flake-based-nixos-system/50351/15 "2025-02-16T14:24:33Z")

</div>

> [@noofel.rouge](#):
>
> ` specialArgs = { inherit inputs; };`

you also need the counterpart for HM: `home-manager.extraSpecialArgs` (in `modules` or so on).

---

<div class="post-metadata">

### Author: ![noofel.rouge](https://discourse.nixos.org/user_avatar/discourse.nixos.org/noofel.rouge/32/30017_2.png) [@noofel.rouge](https://discourse.nixos.org/u/noofel.rouge)
#### Post date: [February 16, 2025, 2:34pm UTC](https://discourse.nixos.org/t/mixing-stable-and-unstable-packages-on-flake-based-nixos-system/50351/16 "2025-02-16T14:34:32Z")

</div>

solved it, many thanks.

---

<div class="post-metadata">

### Author: ![jheidbrink](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/j/f1d935/32.png) [@jheidbrink](https://discourse.nixos.org/u/jheidbrink)
#### Post date: [March 20, 2025, 12:37pm UTC](https://discourse.nixos.org/t/mixing-stable-and-unstable-packages-on-flake-based-nixos-system/50351/17 "2025-03-20T12:37:21Z")

</div>

I’m getting

```auto
[...]
       error: attribute 'pkgsUnstable' missing
       at /nix/store/s3bhg6p26cqi1hm2lamjjdwaiq49g2hn-source/lib/modules.nix:515:28:
          514| addErrorContext (context name)
          515| (args.${name} or config._module.args.${name})
             | ^
          516| ) (functionArgs f);

```

I also don’t understand how we get a variable `pkgsUnstable` just by adding an input `nixpkgs-unstable` in our flake. Similarly, I don’t understand how we get an input `pkgs` for our modules by adding a `nixpkgs` input to our flake.

---

<div class="post-metadata">

### Author: ![phanirithvij](https://discourse.nixos.org/user_avatar/discourse.nixos.org/phanirithvij/32/28729_2.png) [@phanirithvij](https://discourse.nixos.org/u/phanirithvij)
#### Post date: [March 20, 2025, 12:55pm UTC](https://discourse.nixos.org/t/mixing-stable-and-unstable-packages-on-flake-based-nixos-system/50351/18 "2025-03-20T12:55:27Z")

</div>

> [@aos](#):
>
> ```auto
> let
> system = "x86_64-linux";
> pkgs = import nixpkgs { inherit system; };
> pkgsUnstable = import nixpkgs-unstable { inherit system; };
> in
> 
> ```

you might be missing these.

---

<div class="post-metadata">

### Author: ![waffle8946](https://discourse.nixos.org/user_avatar/discourse.nixos.org/waffle8946/32/27221_2.png) [@waffle8946](https://discourse.nixos.org/u/waffle8946)
#### Post date: [March 24, 2025, 2:04pm UTC](https://discourse.nixos.org/t/mixing-stable-and-unstable-packages-on-flake-based-nixos-system/50351/19 "2025-03-24T14:04:44Z")

</div>

Do not do what @aos suggested because your nixpkgs config (e.g. setting unfree) will not carry over.

Please reread my post in full and perform every step. I explained _exactly_ how to pass in nixpkgs-unstable flake input into the module system (step 1) and add a module arg `pkgsUnstable` (step 3a).

> [@jheidbrink](#):
>
> Similarly, I don’t understand how we get an input `pkgs` for our modules by adding a `nixpkgs` input to our flake.

`pkgs` specifically is a bit of behind-the-scenes-magic. It comes from whichever nixpkgs input you use to call `lib.nixosSystem`.  
But `pkgsUnstable` you have to create manually, which was _the entire point of my reply_.

---

<div class="post-metadata">

### Author: ![riza](https://discourse.nixos.org/user_avatar/discourse.nixos.org/riza/32/32610_2.png) [@riza](https://discourse.nixos.org/u/riza)
#### Post date: [April 2, 2025, 2:29pm UTC](https://discourse.nixos.org/t/mixing-stable-and-unstable-packages-on-flake-based-nixos-system/50351/20 "2025-04-02T14:29:20Z")

</div>

I have now settled with the following config, mixing stable and unstable packages and a testing host going fully unstable:

```nix
#flake.nix
{
  description = "Nixos config flake";

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

#...
  };

  outputs = { self, nixpkgs, nixpkgs-unstable, ... }@inputs:
    let
      lib = nixpkgs.lib;
      system = "x86_64-linux";
      variables = nixpkgs.lib.importJSON ./secrets/variables.json;
      pkgs = nixpkgs.legacyPackages.${system};

      pkgsUnstable = import nixpkgs-unstable {
        inherit system;
        config.allowUnfree = true;
      };

      specialArgs = {
        inherit inputs;
        pkgs-unstable = pkgsUnstable;
      };

      nixosConfig = { configPath, useUnstable ? false }:
        let
          nixpkgsSrc = if useUnstable then nixpkgs-unstable else nixpkgs;
        in
        nixpkgsSrc.lib.nixosSystem {
          modules = [configPath];
        };

    in
    {
      nixosConfigurations = {
        prodhost= nixosConfig { configPath = ./hosts/prodhost/configuration.nix; };
        testhost = nixosConfig { configPath = ./hosts/testhost/configuration.nix; useUnstable = true; };
      };
    };
}

```

Declaring packages

```nix
  environment.systemPackages = (with pkgs; [
    stable-package
  ]) ++
  (with pkgs-unstable; [
     unstable-package
  ]);

```
