Home Manager: Difference between revisions

Rrdpad (talk | contribs)
fix home manager module and add home manager config
m remove "note that" - this wiki is all notes and it is redundant
 
(6 intermediate revisions by 5 users not shown)
Line 16: Line 16:
Your configuration is stored in <code>~/.config/home-manager/home.nix</code>. Each time you modify it, rerun <code>home-manager switch</code> for changes to have effect.
Your configuration is stored in <code>~/.config/home-manager/home.nix</code>. Each time you modify it, rerun <code>home-manager switch</code> for changes to have effect.


Note that to work correctly, home-manager needs your shell to source <code>~/.nix-profile/etc/profile.d/hm-session-vars.sh</code>. The most convenient way to do so is to have home-manager manage your whole shell configuration, eg <code>programs.bash.enable = true;</code> or <code>programs.zsh.enable = true;</code>. But in this case your whole bashrc is managed with Home Manager: the years of customization you accumulated in your former .bashrc must be migrated to Home Manager options, which may take some time. The quick and dirty way to do the migration is to move your bashrc to some other location and source it from Home Manager:
To work correctly, home-manager needs your shell to source <code>~/.nix-profile/etc/profile.d/hm-session-vars.sh</code>. The most convenient way to do so is to have home-manager manage your whole shell configuration, eg <code>programs.bash.enable = true;</code> or <code>programs.zsh.enable = true;</code>. But in this case your whole bashrc is managed with Home Manager: the years of customization you accumulated in your former .bashrc must be migrated to Home Manager options, which may take some time. The quick and dirty way to do the migration is to move your bashrc to some other location and source it from Home Manager:
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
{ pkgs, ...}: {
{ pkgs, ...}: {
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 = [
          ./configuration.nix
        ./configuration.nix
          home-manager.nixosModules.home-manager
        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;
          home-manager.users.your-username = import ./home.nix;
         };
         }
       ];
       ];
     };
     };
Line 85: Line 85:


{
{
  # Home Manager needs a bit of information about you and the
  # paths it should manage.
  home.username = "your-username";
  home.homeDirectory = "/home/your-username";
   # This value determines the Home Manager release that your
   # This value determines the Home Manager release that your
   # configuration is compatible with. This helps avoid breakage
   # configuration is compatible with. This helps avoid breakage
Line 98: Line 93:
   # the Home Manager release notes for a list of state version
   # the Home Manager release notes for a list of state version
   # changes in each release.
   # changes in each release.
   home.stateVersion = "24.05";
   home.stateVersion = "24.11";
 
  # Let Home Manager install and manage itself.
  programs.home-manager.enable = true;
}
}
</syntaxhighlight>
</syntaxhighlight>