Home Manager: Difference between revisions

Euxane (talk | contribs)
m Fix syntax highlight for some nix code snippets
NobbZ (talk | contribs)
Removed options that are not only not needed for HM as system module, but might be harmful when used (wrong)
 
(6 intermediate revisions by 4 users not shown)
Line 53: Line 53:


=== Usage as a NixOS module in a Flake ===
=== 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:
Here is the skeleton of how to add Home Manager as a module to your system(s) via your [[Flakes|flake]]:
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
{
{
   inputs = {
   inputs = {
     nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
     nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
     home-manager = {
     home-manager = {
       url = "github:nix-community/home-manager/release-24.05";
       url = "github:nix-community/home-manager/release-24.11";
       inputs.nixpkgs.follows = "nixpkgs"
       inputs.nixpkgs.follows = "nixpkgs";
     };
     };
   };
   };
   outputs = { self, nixpkgs, home-manager }@inputs:
   outputs = { self, nixpkgs, home-manager, ... }@inputs:
     nixosConfigurations.ExampleMachine = nixosConfiguration "ExmapleMachine"
     nixosConfigurations.exampleMachine = nixosConfiguration "exampleMachine"
       system = "x86_64-linux";
       system = "x86_64-linux";
       modules = [
       modules = [
         home-manager.nixosmodules.home-manager {
        ./configuration.nix
          nix.registry.nixos.flake = inputs.self;
         home-manager.nixosModules.home-manager
        {
           home-manager.useGlobalPkgs = true;
           home-manager.useGlobalPkgs = true;
           home-manager.useUserPackages = true;
           home-manager.useUserPackages = true;
        };
          home-manager.users.your-username = import ./home.nix;
        # Anything else you need to import, for example
        }
        ./Devices/ExampleMachine.nix
       ];
       ];
     };
     };
Line 80: Line 80:
</syntaxhighlight>
</syntaxhighlight>
        
        
From there, in your configuration simply needs to make use of Home Manager.  
Here's an example of home manager configuration in ./home.nix
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
{ config, pkgs, ... }:
{
{
   home-manager.users.exampleuser = {
   # This value determines the Home Manager release that your
    home.stateVersion = "24.04";
  # 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>
</syntaxhighlight>