Home Manager: Difference between revisions

m dotfile => dotfiles | plural
Show how to install Home Manager into your system in a flake.
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>.


To use it inside nixosConfigurations in a Flake, put home-manager in your inputs and in your configuration modules import <code>home-manager.nixosModules.home-manager</code>, then you can use it as above.
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.


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 flake:
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
    home-manager = {
      url = "github:nix-community/home-manager/release-24.05";
      inputs.nixpkgs.follows = "nixpkgs"
    };
  };
  outputs = { self, nixpkgs, home-manager }@inputs:
    nixosConfigurations.ExampleMachine = nixosConfiguration "ExmapleMachine"
      system = "x86_64-linux";
      modules = [
        home-manager.nixosmodules.home-manager {
          nix.registry.nixos.flake = inputs.self;
          home-manager.useGlobalPkgs = true;
          home-manager.useUserPackages = true;
        };
        # Anything else you need to import, for example
        ./Devices/ExampleMachine.nix
      ];
    };
  };
}
     
From there, in your configuration simply needs to make use of Home Manager.
{
  home-manager.users.exampleuser = {
    home.stateVersion = "24.04";
  };
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.11


== Usage ==
== Usage ==