← 返回命令列表

Linux command

home-manager 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Apply home configuration

home-manager switch

Apply a specific flake

home-manager switch --flake [.#username]

Initialize

home-manager init

Initialize and immediately activate

home-manager init --switch

Build without activating

home-manager build

List generations

home-manager generations

Rollback to previous generation

home-manager rollback

Remove old generations

home-manager expire-generations "[30 days ago]"

Edit configuration file

home-manager edit

List installed packages

home-manager packages

说明

home-manager is a Nix-based tool for managing user environment configuration declaratively. It handles dotfiles, user packages, and environment settings through Nix expressions, enabling reproducible and versionable home directory setups. Configuration is written in Nix language, typically in ~/.config/home-manager/home.nix or as part of a Nix flake. The configuration declares packages to install, programs to configure, files to manage, and services to run. Many programs have dedicated Home Manager modules that generate configuration files automatically. For example, configuring programs.git generates ~/.gitconfig with proper syntax. This is more maintainable than managing dotfiles manually. Generations provide configuration history. Each switch creates a new generation, and you can roll back to any previous state. This makes experimentation safe - broken configurations can be reverted instantly. Home Manager can run standalone or integrate with NixOS. In standalone mode, it manages the user environment independently. With NixOS, it can be imported as a module for tighter integration.

参数

switch
Build and activate new configuration.
build
Build configuration without activating.
init _--switch_ _dir_
Generate an initial Home Manager configuration. Use --switch to also activate it.
generations
List all configuration generations.
rollback
Revert to previous generation.
expire-generations _period_
Remove generations older than period.
remove-generations _IDs_
Remove specific generations by ID.
edit
Open configuration in $EDITOR.
news
Show news entries about configuration.
packages
List installed packages.
uninstall
Remove Home Manager from the user environment.
option _name_
Show value of configuration option.
--flake _flake-uri_
Use flake-based configuration.
-f, --file _file_
Configuration file path.
-A _attribute_
Attribute to build from configuration.
-b _ext_
Backup file extension for existing files that would be overwritten.
-n, --dry-run
Show what would be done without doing it.
-v, --verbose
Increase verbosity.
--show-trace
Show detailed location information for errors.

FAQ

What is the home-manager command used for?

home-manager is a Nix-based tool for managing user environment configuration declaratively. It handles dotfiles, user packages, and environment settings through Nix expressions, enabling reproducible and versionable home directory setups. Configuration is written in Nix language, typically in ~/.config/home-manager/home.nix or as part of a Nix flake. The configuration declares packages to install, programs to configure, files to manage, and services to run. Many programs have dedicated Home Manager modules that generate configuration files automatically. For example, configuring programs.git generates ~/.gitconfig with proper syntax. This is more maintainable than managing dotfiles manually. Generations provide configuration history. Each switch creates a new generation, and you can roll back to any previous state. This makes experimentation safe - broken configurations can be reverted instantly. Home Manager can run standalone or integrate with NixOS. In standalone mode, it manages the user environment independently. With NixOS, it can be imported as a module for tighter integration.

How do I run a basic home-manager example?

Run `home-manager switch` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does switch do in home-manager?

Build and activate new configuration.