Using both stable/unstable in Flake+Config+HomeManager

I followed officially provided instructions to use Home-Manager with Flake while keeping configuration.nix intact. Here is the simplified result of that:

###################### flake.nix ######################

{
  description = "Laptop Workstation";

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

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

  outputs = inputs@{ nixpkgs, nixpkgs-unstable, home-manager, ... }: {
    nixosConfigurations = {
      xyz = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          ./configuration.nix
          home-manager.nixosModules.home-manager
          {
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
            home-manager.users.arti = import ./home.nix;
          }
        ];
      };
    };
  };
}

###################### configuration.nix ##############

{ config, pkgs, lib, options, ... }:

{
  nix = {
    package = pkgs.nixFlakes;
    extraOptions = ''
      experimental-features = nix-command flakes
    '';
  };

  imports = [
    ./hardware-configuration.nix
  ];

  system = {
    stateVersion = "24.05"; # DO NOT CHANGE
  };

  # Virtualization
  virtualisation.libvirtd.enable = true;

  # Boot
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;
  boot.initrd.luks.devices."luks-00000000-f2fe-0000-0000-000000000000".device = "/dev/disk/by-uuid/00000000-0000-0000-0000-000000000000";

  # Network
  networking = {
    networkmanager.enable = true;
    hostName = "xyz";
  };

  # Time
  time.timeZone = "Europe/Amsterdam";

  # Localization
  i18n = {
    defaultLocale = "en_US.UTF-8";
    extraLocaleSettings = {
      LC_ADDRESS = "nl_NL.UTF-8";
      LC_IDENTIFICATION = "nl_NL.UTF-8";
      LC_MEASUREMENT = "nl_NL.UTF-8";
      LC_MONETARY = "nl_NL.UTF-8";
      LC_NAME = "nl_NL.UTF-8";
      LC_NUMERIC = "nl_NL.UTF-8";
      LC_PAPER = "nl_NL.UTF-8";
      LC_TELEPHONE = "nl_NL.UTF-8";
      LC_TIME = "nl_NL.UTF-8";
    };
  };

  # Window System
  services.xserver = {
    enable = true;
    displayManager.gdm.enable = true;
    desktopManager.gnome.enable = true;

    # Keymap
    xkb = {
      layout = "us";
      variant = "";
    };
  };

  # User
  users.users.arti = {
    isNormalUser = true;
    description = "Artifex";
    extraGroups = [ "networkmanager" "wheel" ];
  };

  # System Packages/Programs
  nixpkgs.config.allowUnfree = true;
  environment.systemPackages = with pkgs; [
    cloudflare-warp
  ];
  environment.gnome.excludePackages = with pkgs; [
    baobab # Disk Usage Analyzer
    epiphany # Web
    gnome.geary
    gnome.gnome-characters
    gnome-connections
    gnome-console
    gnome.gnome-contacts
    gnome.gnome-font-viewer
    gnome.gnome-maps
    gnome.gnome-music
    gnome.gnome-system-monitor
    gnome-tour
    yelp # Help
  ];

  # Services
#  services.cloudflare-warp.enable = true;
}

###################### home.nix #######################

{ config, pkgs, lib, ... }:

{
  home = {
    stateVersion = "24.05"; # DO NOT CHANGE

    # User
    username = "arti";
    homeDirectory = "/home/arti";
  };

  # User Packages/Programs
  home.packages = with pkgs; [
    jetbrains.idea-ultimate
  ] ++ (with pkgs.gnomeExtensions; [
    tophat
  ]);

  programs.home-manager.enable = true;

  imports = [
    ./dconf.nix
  ];
}

Now I’m wondering how I can selectively set some packages to be installed from the unstable channel in both my configuration.nix and home.nix files, but I cannot find a working example of that, specifically in the sort of setup I have. Is there anyone here who could guide me through this? Thanks!

You need to pass arguments to your modules by using specialArgs = inputs; in your flake.nix so that you can use both nixpkgs and nixpkgs-unstable arguments in your configuration.nix file (for example).

1 Like

Thanks, I’ve added the specialArgs = inputs; line to my flake.nix, but how can I utilize that in home.nix (Home-Manager)?

I believe you need to use extraSpecialArgs = inputs; to pass arguments to home-manager (not entirely sure why they’re different between a regular NixOS module and a HomeManager module).

Then, in your home.nix, you can do

+ { config, pkgs, lib, nixpkgs, nixpkgs-unstable, ... }:

{
  home = {
    stateVersion = "24.05"; # DO NOT CHANGE
...

and use these new arguments when declaring your packages, for example

  # User Packages/Programs
  home.packages = with pkgs; [
    jetbrains.idea-ultimate
+    nixpkgs.packageFromStable
+    nixpkgs-unstable.packageFromUnstable
  ] ++ (with pkgs.gnomeExtensions; [
    tophat
  ]);

It failed:

error:
       … from call site

         at /nix/store/...-source/flake.nix:24:11:

           23|         nixosSystem = args:
           24|           import ./nixos/lib/eval-config.nix (
             |           ^
           25|             {

       error: function 'anonymous lambda' called with unexpected argument 'extraSpecialArgs'

       at /nix/store/...-source/nixos/lib/eval-config.nix:11:1:

           10| # types.submodule instead of using eval-config.nix
           11| evalConfigArgs@
             | ^
           12| { # !!! system can be set modularly, would be nice to remove,

That’s the problem, whatever instructions I follow, it leads to ambiguous errors! :smile:


P.S. Even in configuration.nix the nixpkgs-unstable is said to not be found… I’ve tried different ways and calls.

No idea :grimacing:

Here’s how I do it in my flake.nix

Then I can use those parameters in my config.nix