Unstable for one host definition only

Hi everyone.

I am using the following flake to mix stable and some rare unstable packages (some packages are simply to old on stable):

{
  description = "Nixos config flake";

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

    lanzaboote = {
      url = "github:nix-community/lanzaboote/v0.4.2";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    nixos-wsl = {
      url = "github:nix-community/NixOS-WSL";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    nix-comfyui.url = "github:dyscorv/nix-comfyui";

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

    # nix for android
    nix-on-droid = {
      url = "github:nix-community/nix-on-droid/release-24.05";
      inputs.nixpkgs.follows = "nixpkgs";
      inputs.home-manager.follows = "home-manager";
    };
  };

  outputs = { self, nixpkgs, nixpkgs-unstable, lanzaboote, nix-comfyui, nix-on-droid, nixos-wsl, ... }@inputs:
    let
      lib = nixpkgs.lib;
      variables = pkgs.lib.importJSON ./secrets/variables.json;
      system = "x86_64-linux";
      pkgs = nixpkgs.legacyPackages.${system};
      pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
    in
    {
      nixosConfigurations = {
        puffy = lib.nixosSystem {
          inherit system;
          modules = [ ./hosts/puffy/configuration.nix ];
          specialArgs = {
            inherit inputs;
            vars = variables.home;
            pkgs-unstable = import nixpkgs-unstable {
              inherit system;
              config.allowUnfree = true;
            };
          };
        };
        puff = lib.nixosSystem {
          inherit system;
          modules = [ ./hosts/puff/configuration.nix ];
          specialArgs = {
            inherit inputs;
            vars = variables.home;
            pkgs-unstable = import nixpkgs-unstable {
              inherit system;
              config.allowUnfree = true;
            };
          };
        };
        vm = lib.nixosSystem {
          inherit system;
          modules = [ ./hosts/vm/configuration.nix ];
          specialArgs = {
            inherit inputs;
            vars = variables.home;
            pkgs-unstable = import nixpkgs-unstable {
              inherit system;
              config.allowUnfree = true;
            };
          };
        };
        DEN02263 = lib.nixosSystem {
          inherit system;
          modules = [ ./hosts/wsl/configuration.nix ];
          specialArgs = {
            inherit inputs;
            vars = variables.work;
            pkgs-unstable = import nixpkgs-unstable {
              inherit system;
              config.allowUnfree = true;
            };
          };
        };
        nixos = lib.nixosSystem {
          inherit system;
          modules = [ ./hosts/wsl/configuration.nix ];
          specialArgs = {
            inherit inputs;
            vars = variables.home;
            pkgs-unstable = import nixpkgs-unstable {
              inherit system;
              config.allowUnfree = true;
            };
          };
        };
      };
      nixOnDroidConfigurations.default = nix-on-droid.lib.nixOnDroidConfiguration {
        pkgs = import nixpkgs {
          system = "aarch64-linux";
        };
        modules = [ ./hosts/mikrobi/configuration.nix ];
        extraSpecialArgs = {
          vars = variables.home;
        };
      };
    };
}

Whole config file on Gitlab
This setup is working very well but I have just one problem: I would like to have one nixConfiguration (vm) to only use unstable packages for testing. I can achieve this by setting nixpkgs and nixpkgs-unstable both to unstable - which needs manual editing of the flake.nix and is not the prefered way.

Does anyone have an idea to modify the nixConfiguration for “vm” to point pkgs and pkg-unstable to nixpkgs-unstable? And if that is not possible, a better structure that would allow this?

Thanks and have a nice day
Thomas

1 Like

Use vm = nixpkgs-unstable.lib.nixosSystem { ... }. By default, whichever nixpkgs’ lib.nixosSystem you use to create your nixosConfigurations entry, these packages will be used for the system.

3 Likes

I dismissed this idea because it seemed a too easy fix - but this is the actual solution. Thanks for the help.