Home Manager: Difference between revisions
m dotfile => dotfiles | plural |
Removed options that are not only not needed for HM as system module, but might be harmful when used (wrong) |
||
(9 intermediate revisions by 6 users not shown) | |||
Line 50: | Line 50: | ||
It can either be incorporated in <code>/etc/nixos/configuration.nix</code> or be placed in a standalone file and imported in configuration.nix: <code>imports = [ ./thefile.nix ]</code>. | It can either be incorporated in <code>/etc/nixos/configuration.nix</code> or be placed in a standalone file and imported in configuration.nix: <code>imports = [ ./thefile.nix ]</code>. | ||
Whenever you change you home-manager configuration, you must rerun <code>nixos-rebuild switch</code>. With this method, changing the configuration of an unprivileged user requires to run a command as root. | |||
=== Usage as a NixOS module in a Flake === | |||
Here is the skeleton of how to add Home Manager as a module to your system(s) via your [[Flakes|flake]]: | |||
<syntaxhighlight lang="nix"> | |||
{ | |||
inputs = { | |||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11"; | |||
home-manager = { | |||
url = "github:nix-community/home-manager/release-24.11"; | |||
inputs.nixpkgs.follows = "nixpkgs"; | |||
}; | |||
}; | |||
outputs = { self, nixpkgs, home-manager, ... }@inputs: | |||
nixosConfigurations.exampleMachine = nixosConfiguration "exampleMachine" | |||
system = "x86_64-linux"; | |||
modules = [ | |||
./configuration.nix | |||
home-manager.nixosModules.home-manager | |||
{ | |||
home-manager.useGlobalPkgs = true; | |||
home-manager.useUserPackages = true; | |||
home-manager.users.your-username = import ./home.nix; | |||
} | |||
]; | |||
}; | |||
}; | |||
} | |||
</syntaxhighlight> | |||
Here's an example of home manager configuration in ./home.nix | |||
<syntaxhighlight lang="nix"> | |||
{ config, pkgs, ... }: | |||
{ | |||
# This value determines the Home Manager release that your | |||
# configuration is compatible with. This helps avoid breakage | |||
# when a new Home Manager release introduces backwards | |||
# incompatible changes. | |||
# | |||
# You can update Home Manager without changing this value. See | |||
# the Home Manager release notes for a list of state version | |||
# changes in each release. | |||
home.stateVersion = "24.11"; | |||
} | |||
</syntaxhighlight> | |||
Of course you'll probably want to keep more stuff in there than just a state version, but the state version is required. | |||
The downside to doing it this way over the User config is that you have to do a full system rebuild; the home manager config is part of the full system, and so must be built as root or at least a trusted user. | |||
== Usage == | == Usage == |