Use unstable version for some packages

I am using stable (23.05) for my system but since I have some problems with a Gnome Extension, I want to use the unstable version for this specific package. I already looked into overwrites and overlays, even looked at configs from other people that seem do the same thing. But still I am absolutely helpless and have no idea how to adapt it to my Flake config…

I have already added nixpkgs-unstable to the inputs/outputs of the flake, but I don’t know how to pass it to home-manager and there install a package from unstable instead of stable.

May anyone be so kind to help me out? :frowning:
Idk… I find flakes so utterly complicated… I just dont unserstand it…
If you have any good learning resources, feel free to share.

# flake.nix
  description = "My NixOS workstation configuration";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
    nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    home-manager.url = "github:nix-community/home-manager/release-23.05";
    home-manager.inputs.nixpkgs.follows = "nixpkgs";
    vscode-server.url = "github:nix-community/nixos-vscode-server";

  outputs = { self, nixpkgs, nixpkgs-unstable, home-manager, vscode-server, ... }@inputs: {
    nixosConfigurations = {
      # NixOS is the hostname this config is applied to
      NixOS = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [ 
          home-manager.nixosModules.home-manager {
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
            home-manager.users.stfnx.imports = [
            # Optionally pass arguments to home.nix
            #home-manager.extraSpecialArgs = {};
# home/_main.nix

{ config, pkgs, lib, ... }:
  # Install Gnome Extensions
  home.packages = with pkgs.gnomeExtensions; [
    # gsconnect
    # night-theme-switcher

1 Like

I have had success with using nix-starter-configs by Misterio77.

Here’s how I use packages from unstable:
1. Import nixpkgs-unstable in flake.nix
2. Define an overlay that makes the unstable packages available under “unstable”
3. Import the overlay
4. Take a package from the unstable set

Note that I use home-manager separately from NixOS configuration.
You have home-manager as a NixOS module, but it should be easy to
adapt to that approach.

btw, I don’t have a deep understanding of how this all works, either :wink:
The starter config works almost too well - there’s not much opportunity to learn when everything works.


Hi! nixpkgs.lib.nixosSystem does not know anything about the
nixpkgs-unstable flake, which you are also loading. Similar to @ttrei, I also
suggest providing the unstable packages as an overlay like so:

  add-unstable-packages = final: _prev: {
    unstable = import nixpkgs-unstable {
      system = "x86_64-linux;

Then, you can use this overlay in one of your NixOs modules (e.g., the mentioned
./system/main.nix module):

    nixpkgs.overlays = [add-unstable-packages];

And finally, you can install unstable packages with

environment.systemPackages = [ unstable.hello ];

EDIT: And yea, the initial setup is complicated. But when it’s done; yeah, you can install and run different package versions (and their software stacks) next to each other. Awesome.

1 Like

Where in my flake.nix would I define the overlay / include the following snippet?

unstable-packages = final: _prev: {
    unstable = import inputs.nixpkgs-unstable {
      system = final.system;
      config.allowUnfree = true;

In the outputs? Or in the inputs? Or as a separate block?

@ttrei you defined it in a separate file, which currently isn’t necessary for me because this will be my only overlay for now.

btw. I already came across the templates from Misterio77, but the default one is too complicated for now. Since I don’t understand all that’s going on there, I avoided using it for now. Should I just use it and go from there?

1 Like

I guess you can define an “overlays” attrset in your outputs:

overlays = {
  unstable-packages = ...

Then reference it in the _main.nix module:

{ config, pkgs, lib, outputs, ... }:
  nixpkgs.overlays = [outputs.unstable-packages];

I highly recommend going with the template.
Yes, it might be inscrutable in the beginning, but so is nix and NixOS :slight_smile:
I find it much easier to learn by modifying/breaking existing config than by creating from scratch.

1 Like

Thanks! I will now start to migrate everything I’ve done so far into the Misterio77 normal template. I guess it makes sense to start with a pre-organized config, instead of cooking my own soup.

The separate config.allowUnfree = true; while importing nixpkgs-unstable is unintuitive. I thought it would use the global configuration I defined for the normal packages.