Files
home-manager/docs/manual/nix-flakes/nixos.md
Austin Horstman 0a8d50edf2 docs/nix-flakes: clarify extraSpecialArgs usage
Explain when to use extraSpecialArgs versus _module.args in the flake setup guides, and keep the generated standalone fixture aligned with the updated template output.
2026-04-20 09:36:51 -05:00

1.8 KiB

NixOS module

To use Home Manager as a NixOS module, a bare-minimum flake.nix would be as follows:

{
  description = "NixOS configuration";

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

  outputs = inputs@{ nixpkgs, home-manager, ... }: {
    nixosConfigurations = {
      hostname = 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.extraSpecialArgs = { inherit inputs; };
            home-manager.users.jdoe = ./home.nix;
          }
        ];
      };
    };
  };
}

Use home-manager.extraSpecialArgs to pass arguments from your flake to home.nix and any imported Home Manager modules. For example, the configuration above makes the complete inputs attrset available to modules, so they can declare arguments such as { inputs, ... }:.

The lower-level mechanism behind this is _module.args. Set _module.args.<name> from inside a module only when you need to provide a module argument from within the module graph itself. For values that originate outside the module graph, such as flake inputs, prefer home-manager.extraSpecialArgs.

The Home Manager configuration is then part of the NixOS configuration and is automatically rebuilt with the system when using the appropriate command for the system, such as nixos-rebuild switch --flake <flake-uri>.

You can use the above flake.nix as a template in /etc/nixos by

$ nix flake new /etc/nixos -t github:nix-community/home-manager#nixos