### Example User Configuration Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/installation/nixos.md Example snippet for configuring a user's environment within NixOS configuration.nix, including packages and program settings. ```nix users.users.eve.isNormalUser = true; home-manager.users.eve = { pkgs, ... }: { home.packages = [ pkgs.atool pkgs.httpie ]; programs.bash.enable = true; # 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 should not change this value, even if you update Home Manager. If you do # want to update the value, then make sure to first check the Home Manager # release notes. home.stateVersion = "26.05"; # Please read the comment before changing. }; ``` -------------------------------- ### Program Configuration Import Example Source: https://github.com/nix-community/home-manager/wiki/FAQ Example of how a program's configuration file can import a generated file. This is a common pattern when using Home Manager to manage complex application settings. ```json { "imports": [ "generated.json", ], ... } ``` -------------------------------- ### Configure Git Program Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/dotfiles.md Example of enabling the Git program configuration in Home Manager. ```nix { # … programs.git = { enable = true; userName = "Jane Doe"; userEmail = "jane.doe@example.org"; }; # … } ``` -------------------------------- ### Install Home Manager Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/installation/standalone.md Run the Home Manager installation command to create the first Home Manager generation. This command activates Home Manager in your user environment. ```shell $ nix-shell '' -A install ``` -------------------------------- ### Declarative Home Manager Installation Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/installation/nixos.md Declaratively installs Home Manager by fetching the release tarball and importing the NixOS module within configuration.nix. Configures user 'eve' with specific packages and bash. ```nix { config, pkgs, lib, ... }: let home-manager = builtins.fetchTarball https://github.com/nix-community/home-manager/archive/release-26.05.tar.gz; in { imports = [ (import "${home-manager}/nixos") ]; users.users.eve.isNormalUser = true; home-manager.users.eve = { pkgs, ... }: { home.packages = [ pkgs.atool pkgs.httpie ]; programs.bash.enable = true; # The state version is required and should stay at the version you # originally installed. home.stateVersion = "26.05"; }; } ``` -------------------------------- ### Home Manager Configuration for NixGL Integration Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/gpu-non-nixos.md Configure NixGL packages, default wrapper, offload wrapper, and install scripts. This setup enables GPU acceleration for programs managed by Home Manager. ```nix { config, lib, pkgs, nixgl, ... }: { targets.genericLinux.nixGL = { packages = nixgl.packages; defaultWrapper = "mesa"; offloadWrapper = "nvidiaPrime"; installScripts = [ "mesa" "nvidiaPrime" ]; }; programs.mpv = { enable = true; package = config.lib.nixGL.wrap pkgs.mpv; }; home.packages = [ (config.lib.nixGL.wrapOffload pkgs.freecad) (config.lib.nixGL.wrappers.nvidiaPrime pkgs.xonotic) ]; } ``` -------------------------------- ### Switch Home Manager Configuration Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/nix-flakes/standalone.md After initial setup, use this command to build and activate your Home Manager configuration. Assumes you are in the flake directory. ```shell $ home-manager switch ``` -------------------------------- ### Home Manager Flake Configuration with Extra Arguments Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/nix-flakes/standalone.md Example of a `flake.nix` file demonstrating how to pass flake inputs as extra arguments to `homeManagerConfiguration`. This allows modules to access flake inputs directly. ```nix { inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; home-manager.url = "github:nix-community/home-manager"; }; outputs = inputs@{ nixpkgs, home-manager, ... }: { homeConfigurations.jdoe = home-manager.lib.homeManagerConfiguration { pkgs = nixpkgs.legacyPackages.x86_64-linux; extraSpecialArgs = { inherit inputs; }; modules = [ ./home.nix ]; }; }; } ``` -------------------------------- ### Install Yazi Flavor on Windows Source: https://github.com/nix-community/home-manager/blob/master/tests/modules/programs/yazi/flavor/README.md Clone the flavor repository to the Yazi configuration directory for Windows systems. ```bash git clone https://github.com/username/example.yazi.git %AppData%\yazi\config\flavors\example.yazi ``` -------------------------------- ### Run mpd as a User Service Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/modular-services.md A minimal example to run mpd as a user service. This generates `~/.config/systemd/user/mpd.service` with `ExecStart` set to the mpd binary and `WantedBy=default.target`. ```nix { pkgs, ... }: { home.services.mpd = { process.argv = [ "${pkgs.mpd}/bin/mpd" "--no-daemon" ]; }; } ``` -------------------------------- ### Update Home Manager Channel for Standalone Installation Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/upgrading.md Add the desired Home Manager channel, update all channels, and then switch to the new configuration for a standalone setup. ```shell $ nix-channel --add https://github.com/nix-community/home-manager/archive/release-25.11.tar.gz home-manager $ nix-channel --update $ home-manager switch ``` -------------------------------- ### Minimal Home Manager Configuration Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/configuration.md This is a basic `home.nix` file generated on a fresh install. It sets essential user information and enables Home Manager itself. ```nix { config, pkgs, ... }: { # Home Manager needs a bit of information about you and the # paths it should manage. home.username = "jdoe"; home.homeDirectory = "/home/jdoe"; # 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 = "26.05"; # Let Home Manager install and manage itself. programs.home-manager.enable = true; } ``` -------------------------------- ### Module Auto-importing Structure Example Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/contributing/guidelines.md Illustrates the directory structure for modules in Home Manager, showing which files and directories are automatically imported and which are excluded. ```plaintext modules/programs/ ├── git.nix # Single-file module (imported) ├── firefox/ # Multi-file module (imported) │ ├── default.nix │ └── addons.nix ├── _experimental.nix # Excluded (starts with _) └── _wip/ # Excluded directory (starts with _) └── newfeature.nix ``` -------------------------------- ### Configure User Environment with Home Manager Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/installation/nix-darwin.md Example of configuring a user's environment using the Home Manager module in nix-darwin. This sets up packages and program configurations for a specific user. ```nix users.users.eve = { name = "eve"; home = "/Users/eve"; }; home-manager.users.eve = { pkgs, ... }: { home.packages = [ pkgs.atool pkgs.httpie ]; programs.bash.enable = true; # The state version is required and should stay at the version you # originally installed. home.stateVersion = "26.05"; }; ``` -------------------------------- ### Nested Structures and Duplicate Children in Nix Source: https://github.com/nix-community/home-manager/blob/master/tests/lib/generators/tokdl-result.txt Shows how to define nested attribute sets and how Home Manager handles duplicate child attribute names within a block. ```nix duplicateChildren { child 2 child 1 } extraAttrs 2 true arg1=1 arg2=false { nested { a 1 b null } } nested { - 1 2 - true false - - null } ``` -------------------------------- ### NixGL Integration with Channels Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/gpu-non-nixos.md Alternative NixGL integration method for users not using flakes. This example shows how to import NixGL packages using channels. ```nix { config, lib, pkgs, ... }: { targets.genericLinux.nixGL.packages = import { inherit pkgs; }; # The rest is the same as above ... } ``` -------------------------------- ### Enable User Packages in nix-darwin Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/installation/nix-darwin.md Enable user packages to be installed to `/etc/profiles/per-user/$USERNAME` by setting `home-manager.useUserPackages` to true in your nix-darwin configuration. ```nix home-manager.useUserPackages = true; ``` -------------------------------- ### Querying Manually Installed Packages with nix-env Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/faq/collision.md This command queries your user environment to list packages that have been manually installed using `nix-env --install`. It helps identify potential conflicts before applying Home Manager configurations. ```shell $ nix-env --query hello-2.10 ``` -------------------------------- ### Check Current Home Manager Channel Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/upgrading.md Verify the Home Manager channel currently in use for a standalone installation. ```shell $ nix-channel --list ``` -------------------------------- ### Install Yazi Flavor on Linux/macOS Source: https://github.com/nix-community/home-manager/blob/master/tests/modules/programs/yazi/flavor/README.md Clone the flavor repository to the Yazi configuration directory for Linux and macOS systems. ```bash git clone https://github.com/username/example.yazi.git ~/.config/yazi/flavors/example.yazi ``` -------------------------------- ### Configure Yazi Flavor Source: https://github.com/nix-community/home-manager/blob/master/tests/modules/programs/yazi/flavor/README.md Add these lines to your theme.toml configuration file to enable the custom flavor. Replace 'example' with your flavor's name. ```toml [flavor] use = "example" ``` -------------------------------- ### Basic Attribute Assignment in Nix Source: https://github.com/nix-community/home-manager/blob/master/tests/lib/generators/tokdl-result.txt Demonstrates setting basic attributes with different data types like integers, strings, booleans, and null values in Nix configuration. ```nix rootLevelChild 2 rootLevelChild 1 a 1 argsAndProps 1 2 a=3 b "string" flatItems 1 2 "asdf" true null unsafeString " \" \n " ``` -------------------------------- ### Verify Home Manager Version Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/upgrading.md Run this command after upgrading to check the installed Home Manager version. This helps ensure the upgrade was successful and the correct release branch is being used. ```shell home-manager --version ``` -------------------------------- ### Add Home Manager Channel (Release) Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/installation/nixos.md Adds a specific release branch of the Home Manager channel for NixOS installation. Replace 'release-26.05' with your desired version. ```shell $ sudo nix-channel --add https://github.com/nix-community/home-manager/archive/release-26.05.tar.gz home-manager $ sudo nix-channel --update ``` -------------------------------- ### Update User Channels and Switch Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/updating.md For standalone Home Manager installations using channels, update the user's channels first, then switch to the new configuration. ```shell $ nix-channel --update … unpacking channels... $ home-manager switch ``` -------------------------------- ### Example Commit Message Format Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/contributing/guidelines.md This commit message follows the recommended format, including a component, a brief description, and an optional long description. It is suitable for inclusion in Home Manager pull requests. ```git starship: allow running in Emacs if vterm is used The vterm buffer is backed by libvterm and can handle Starship prompts without issues. ``` -------------------------------- ### Configure Nvidia drivers in Home Manager Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/gpu-non-nixos.md Enable and configure proprietary Nvidia drivers by specifying the version and SHA256 hash obtained from Nvidia's website. The driver version must match the host system's installed version. ```nix targets.genericLinux.gpu.nvidia = { enable = true; version = "550.163.01"; sha256 = "sha256-74FJ9bNFlUYBRen7+C08ku5Gc1uFYGeqlIh7l1yrmi4="; }; ``` -------------------------------- ### Home Manager Build Error Example Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage.md This console output demonstrates a typical error message when an option is assigned a value of the wrong type, such as a string instead of a boolean for `programs.emacs.enable`. ```console $ home-manager build error: A definition for option `programs.emacs.enable' is not of type `boolean'. Definition values: - In `/home/jdoe/.config/home-manager/home.nix': "yes" (use '--show-trace' to show detailed location information) ``` -------------------------------- ### Multiline Strings and Special Characters in Nix Source: https://github.com/nix-community/home-manager/blob/master/tests/lib/generators/tokdl-result.txt Illustrates how to define multiline strings and strings containing special characters, including newlines, tabs, backslashes, and quotes, within Nix configuration. ```nix bigFlatItems 23847590283751 1.239000 "multiline \" \" \" string " null c "multiline string with special characters: \\" \" " ``` -------------------------------- ### Lists and Nested Lists in Nix Attributes Source: https://github.com/nix-community/home-manager/blob/master/tests/lib/generators/tokdl-result.txt Demonstrates the definition of lists within attribute sets, including deeply nested lists and lists containing attribute sets, in Nix configuration. ```nix listInAttrsInList { list1 { - { a 1 } - { b true } - { c null d { - { e "asdfadfasdfasdf" } } } } list2 { - { a 8 } } } ``` -------------------------------- ### Fetch Nvidia driver hash Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/gpu-non-nixos.md Use `nix store prefetch-file` to get the hash for a specific Nvidia driver version. Ensure the version and architecture (e.g., `x86_64` or `aarch64`) in the URL are correct for your system. ```sh nix store prefetch-file \ https://download.nvidia.com/XFree86/Linux-x86_64/550.163.01/NVIDIA-Linux-x86_64-550.163.01.run ``` -------------------------------- ### Enable X Session and Window Manager in Home Manager Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/graphical.md Enables the X session and specifies the command to launch a window manager within your Home Manager configuration. This allows Home Manager to start graphical services. It requires a command string for the window manager. ```nix { # … xsession.enable = true; xsession.windowManager.command = "…"; # … } ``` -------------------------------- ### Create NixOS Configuration from Template Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/nix-flakes/nixos.md Command to initialize a new NixOS configuration in /etc/nixos using the NixOS template from the home-manager flake repository. ```shell $ nix flake new /etc/nixos -t github:nix-community/home-manager#nixos ``` -------------------------------- ### Build and Open HTML Documentation Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/contributing/guidelines.md Builds the HTML version of the Home Manager manual and opens it. This is useful for reviewing documentation changes. ```shell $ nix-build -A docs.html $ xdg-open ./result/share/doc/home-manager/index.html ``` -------------------------------- ### Make Package Option Nullable Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/contributing/guidelines.md When a module installs a package, consider making the package option nullable. This allows users to manage the package installation outside of Home Manager if needed. ```nix package = lib.mkPackageOption pkgs "xdg-terminal-exec" { nullable = true; }; ``` -------------------------------- ### Initialize Nix-Darwin Configuration Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/nix-flakes/nix-darwin.md Command to create a new nix-darwin configuration in `~/.config/darwin` using the Home Manager nix-darwin flake template. ```shell $ nix flake new ~/.config/darwin -t github:nix-community/home-manager#nix-darwin ``` -------------------------------- ### Start Home Manager Graphical Session Source: https://github.com/nix-community/home-manager/blob/master/tests/modules/misc/xsession/basic-xsession-expected.txt Starts the 'hm-graphical-session.target' systemd user service. This is typically used to initiate the graphical environment managed by Home Manager. It relies on systemd's user instance. ```bash systemctl --user start hm-graphical-session.target ``` -------------------------------- ### Basic Test File Structure Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/contributing/tests.md A fundamental test file structure demonstrating Home Manager configuration and NMT assertions. ```nix { # Home Manager configuration programs.myprogram = { enable = true; settings = { option = "value"; }; }; # NMT test script with assertions nmt.script = '' assertFileExists "home-files/.config/myprogram/config.toml" assertFileContent "home-files/.config/myprogram/config.toml" ${./expected-config.toml} ''; } ``` -------------------------------- ### View Home Manager Configuration Manual Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage.md To view the complete documentation for Home Manager options directly in your terminal, use the `man` command with the configuration file name. ```shell man home-configuration.nix ``` -------------------------------- ### Extract Text from PDF Source: https://github.com/nix-community/home-manager/blob/master/tests/modules/programs/antigravity-cli/skills/pdf-processing/SKILL.md Use pdfplumber to extract text from the first page of a PDF document. Ensure the pdfplumber library is installed. ```python import pdfplumber with pdfplumber.open("document.pdf") as pdf: text = pdf.pages[0].extract_text() ``` -------------------------------- ### Initialize Home Manager with Custom Directory Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/nix-flakes/standalone.md Use this command to initialize Home Manager configuration in a specified directory (e.g., `~/hmconf`) instead of the default `~/.config/home-manager`. ```shell $ nix run home-manager/$branch -- init --switch ~/hmconf ``` -------------------------------- ### Configure Git with Home Manager Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/introduction.md This Nix configuration snippet enables the Git program and sets the user's email and name. It demonstrates how Home Manager generates the corresponding Git configuration file automatically. ```nix programs.git = { enable = true; userEmail = "joe@example.org"; userName = "joe"; }; ``` ```ini [user] email = "joe@example.org" name = "joe" ``` -------------------------------- ### Platform-Specific News Entry Condition Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/contributing/news.md Example of a condition for a news entry that should only be displayed on Linux platforms. This is useful for platform-specific module announcements. ```nix condition = hostPlatform.isLinux; ``` -------------------------------- ### Uninstall GPU drivers on non-NixOS Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/gpu-non-nixos.md To remove the GPU drivers installed by Home Manager, delete the symlink in `/run/opengl-driver` and the configuration file in `/etc/tmpfiles.d/`. ```sh sudo rm /run/opengl-driver sudo rm /etc/tmpfiles.d/non-nixos-gpu.conf ``` -------------------------------- ### Home Manager Module Arguments Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/installation/nixos.md Illustrates the extra module arguments passed to each 'home-manager.users.' module during configuration. ```nix { lib, pkgs, osConfig, nixosConfig, osClass, modulesPath, ... }: ``` -------------------------------- ### Initialize and Switch Home Manager Configuration (Specific Version) Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/nix-flakes/standalone.md Use this command to generate and activate a Home Manager configuration pinned to a specific release branch, such as 26.05. ```shell $ nix run home-manager/release-26.05 -- init --switch ``` -------------------------------- ### Use Global Nixpkgs in Home Manager Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/installation/nix-darwin.md Configure Home Manager to use the global Nixpkgs instance instead of a private one by setting `home-manager.useGlobalPkgs` to true. This can save an evaluation and improve consistency. ```nix home-manager.useGlobalPkgs = true; ``` -------------------------------- ### Expanded Home Manager Configuration Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/configuration.md This expanded configuration adds packages like htop and fortune, enables Emacs with extra packages, and configures the gpg-agent service. ```nix { config, pkgs, ... }: { # Home Manager needs a bit of information about you and the # paths it should manage. home.username = "jdoe"; home.homeDirectory = "/home/jdoe"; # Packages that should be installed to the user profile. home.packages = [ pkgs.htop pkgs.fortune ]; # 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 = "26.05"; # Let Home Manager install and manage itself. programs.home-manager.enable = true; programs.emacs = { enable = true; extraPackages = epkgs: [ epkgs.nix-mode epkgs.magit ]; }; services.gpg-agent = { enable = true; defaultCacheTtl = 1800; enableSshSupport = true; }; } ``` -------------------------------- ### Use Unstable Package with Flakes Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/faq/change-package-module.md In a flake-based setup, pass the unstable package set as an extra module argument to override a module's package. ```nix { pkgsUnstable, ... }: { programs.beets.package = pkgsUnstable.beets; # … } ``` -------------------------------- ### Initialize and Switch Home Manager Configuration (Unstable) Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/nix-flakes/standalone.md Use this command to generate and immediately activate a basic Home Manager configuration using the unstable branch of Home Manager. ```shell $ nix run home-manager/master -- init --switch ``` -------------------------------- ### Add Overlay in System Configuration Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/faq/change-package-module.md If `home-manager.useGlobalPkgs = true` is enabled, Home Manager uses the system package set. Place overlays in the system configuration instead of the Home Manager configuration. ```nix { pkgsUnstable, ... }: { nixpkgs.overlays = [ (_final: _prev: { skim = pkgsUnstable.skim; }) ]; } ``` -------------------------------- ### Switching with Custom Backup Command Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/dotfiles.md Use the 'home-manager switch -B ' to execute a custom command for handling colliding files. ```shell home-manager switch -B trash-put ``` -------------------------------- ### Basic flake-parts Configuration with Home Manager Module Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/nix-flakes/flake-parts.md This snippet demonstrates a typical flake-parts configuration that imports and utilizes the Home Manager flake module to define reusable home modules and specific user configurations. ```nix { description = "flake-parts configuration"; inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; home-manager.url = "github:nix-community/home-manager"; flake-parts.url = "github:hercules-ci/flake-parts"; }; outputs = inputs@{ ... }: flake-parts.lib.mkFlake { inherit inputs; } { imports = [ # Import home-manager's flake module inputs.home-manager.flakeModules.home-manager ]; flake = { # Reusable Home Manager module. homeModules.bash= { pkgs, ... }: { programs.bash = { enable = true; shellAliases = { ll = "ls -l"; }; }; home.packages = [ pkgs.hello ]; }; # Concrete Home Manager configuration. homeConfigurations.alice = home-manager.lib.homeManagerConfiguration { pkgs = import nixpkgs { system = "x86_64-linux"; }; modules = [ inputs.self.homeModules.bash { home.username = "alice"; home.homeDirectory = "/home/alice"; home.stateVersion = "25.11"; } ]; }; }; # See flake.parts for more features, such as `perSystem` }; } ``` -------------------------------- ### Prevent Package Propagation in Home-manager Source: https://github.com/nix-community/home-manager/wiki/Home This snippet demonstrates how to prevent packages from being propagated in home-manager's configuration. It uses `mkForce` to ensure that only explicitly listed packages are installed. ```nix home.packages = mkForce []; ``` -------------------------------- ### Update Lock File and Rebuild (nix-darwin Module) Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/upgrading.md For nix-darwin installations, update the flake lock file using 'nix flake update', and then rebuild the system with 'darwin-rebuild switch --flake .'. ```shell $ nix flake update $ darwin-rebuild switch --flake . ``` -------------------------------- ### Configure Service Data Files Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/modular-services.md Declare configuration files for a service using `configData`. These files are materialized in `$XDG_CONFIG_HOME/home-services//` and their paths are injected back for the service to use. ```nix { config, ... }: { home.services.demo = { process.argv = [ "/bin/myapp" "--config" config.home.services.demo.configData."app.toml".path ]; configData."app.toml".text = '' port = 1234 ''; }; } ``` -------------------------------- ### Configure Home Manager State Version Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/upgrading.md Set the `home.stateVersion` in your configuration to the Home Manager release version you first used for this configuration. This ensures backward compatibility. ```nix { # Example: if this home configuration was first created on 24.11. home.stateVersion = "24.11"; } ``` -------------------------------- ### Create a News Entry using Nix Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/contributing/news.md Use this command to generate a new news entry file within the Home Manager project. This is the recommended method for creating news entries. ```shell $ nix run .#create-news-entry ``` -------------------------------- ### Switching with Backup Extension Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/dotfiles.md Use the 'home-manager switch -b backup' command to automatically move colliding files to a '.backup' extension. ```shell home-manager switch -b backup ``` -------------------------------- ### Enable Emacs in Home Manager Configuration Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage.md This snippet shows how to enable Emacs within your Home Manager configuration. Ensure you provide a boolean value for the `programs.emacs.enable` option. ```nix programs.emacs.enable = "yes"; ``` -------------------------------- ### Follow Nixpkgs Input in Flakes Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/nix-flakes.md Configure Home Manager to use the same Nixpkgs input as the rest of your flake. Use with caution, especially with unstable branches, as it bypasses compatibility checks. ```nix home-manager.inputs.nixpkgs.follows = "nixpkgs"; ``` -------------------------------- ### Enable Nix Flakes Experimental Features Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/nix-flakes/prerequisites.md Configures Nix to enable experimental features 'nix-command' and 'flakes'. This is required for flake-based Home Manager installations across different system types. ```nix nix.settings.experimental-features = "nix-command flakes"; ``` ```bash experimental-features = nix-command flakes ``` -------------------------------- ### Run Nix Commands with Flakes Enabled Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/nix-flakes/prerequisites.md Demonstrates how to enable flakes on a per-command basis using the --extra-experimental-features flag for both nix and home-manager CLI tools. ```shell $ nix --extra-experimental-features "nix-command flakes" $ home-manager --extra-experimental-features "nix-command flakes" ``` -------------------------------- ### Override Home Manager Input with Flakes (Shell) Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/contributing/getting-started.md When using flakes, override the `home-manager` input to point to a local development clone. This allows `home-manager` commands to use your modified version. ```shell home-manager --override-input home-manager ~/devel/home-manager ``` -------------------------------- ### Update Lock File and Rebuild (Standalone) Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/upgrading.md After updating flake inputs, run 'nix flake update' to refresh the lock file, followed by 'home-manager switch --flake .' to apply the changes for a standalone Home Manager installation. ```shell $ nix flake update $ home-manager switch --flake . ``` -------------------------------- ### Configure Backup Command Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/dotfiles.md Set the 'home-manager.backupCommand' option to specify a custom command for handling backup files. ```nix { home-manager.backupCommand = "${pkgs.trash-cli}/bin/trash-put"; } ``` -------------------------------- ### Overwrite Existing Backups Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/dotfiles.md Enable 'home-manager.overwriteBackup = true' to allow overwriting existing backup files. Use with caution. ```nix { home-manager.backupFileExtension = "backup"; home-manager.overwriteBackup = true; } ``` -------------------------------- ### Home Manager Package Declaration Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/faq/collision.md This snippet shows how a package, in this case 'hello', is declared within a Home Manager configuration file. This declaration can lead to a collision if the package is already installed manually. ```nix home.packages = [ pkgs.hello ]; ``` -------------------------------- ### Initialize Home Manager Configuration Without Switching Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/nix-flakes/standalone.md Run this command to generate the Home Manager configuration files without activating them. This allows for manual inspection and editing before the first activation. ```shell $ nix run home-manager/$branch -- init ``` -------------------------------- ### Home Manager Module Arguments Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/installation/nix-darwin.md Illustrates the extra module arguments passed to each `home-manager.users.` module, including `lib`, `pkgs`, `osConfig`, `darwinConfig`, `osClass`, and `modulesPath`. ```nix { lib, pkgs, osConfig, darwinConfig, osClass, modulesPath, ... }: ``` -------------------------------- ### Configure Home Manager Path (Nix) Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/contributing/getting-started.md Permanently set the path for Home Manager in your configuration to use a local development clone. This ensures that `home-manager switch` and `home-manager build` commands utilize your local repository. ```nix programs.home-manager.enable = true; programs.home-manager.path = "$HOME/devel/home-manager"; ``` -------------------------------- ### Override Home Manager Path (Shell) Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/contributing/getting-started.md Temporarily use a local clone of Home Manager by overriding the default input path using the `-I` command-line option. This is useful for quick testing of local changes. ```shell home-manager -I home-manager=$HOME/devel/home-manager ``` -------------------------------- ### Home Manager Switch Error Output Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/faq/collision.md This is an example of the error output encountered when attempting to switch to a Home Manager configuration that has a package collision. It highlights the conflicting paths and suggests using `nix-env --set-flag` to manage priorities. ```shell $ home-manager switch these derivations will be built: /nix/store/xg69wsnd1rp8xgs9qfsjal017nf0ldhm-home-manager-path.drv [...] Activating installPackages replacing old ‘home-manager-path’ installing ‘home-manager-path’ building path(s) ‘/nix/store/b5c0asjz9f06l52l9812w6k39ifr49jj-user-environment’ Wide character in die at /nix/store/64jc9gd2rkbgdb4yjx3nrgc91bpjj5ky-buildenv.pl line 79. collision between ‘/nix/store/fmwa4axzghz11cnln5absh31nbhs9lq1-home-manager-path/bin/hello’ and ‘/nix/store/c2wyl8b9p4afivpcz8jplc9kis8rj36d-hello-2.10/bin/hello’; use ‘nix-env --set-flag priority NUMBER PKGNAME’ to change the priority of one of the conflicting packages builder for ‘/nix/store/b37x3s7pzxbasfqhaca5dqbf3pjjw0ip-user-environment.drv’ failed with exit code 2 error: build of ‘/nix/store/b37x3s7pzxbasfqhaca5dqbf3pjjw0ip-user-environment.drv’ failed ``` -------------------------------- ### Import nix-darwin Module Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/installation/nix-darwin.md Import the Home Manager nix-darwin module into your nix-darwin configuration. This makes the `home-manager.users` option available. ```nix imports = [ ]; ``` -------------------------------- ### Source Home Manager Session Variables (System Packages) Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/installation/nix-darwin.md Source the Home Manager session variables script. This is necessary if Home Manager does not manage your shell configuration and `home-manager.useUserPackages` is enabled. ```bash . "/etc/profiles/per-user/$USER/etc/profile.d/hm-session-vars.sh" ``` -------------------------------- ### Build and View Man Pages Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/contributing/guidelines.md Builds the man page version of module options and displays a specific man page. Useful for checking the formatting of module option documentation. ```shell $ nix-build -A docs.manPages $ man ./result/share/man/man5/home-configuration.nix.5 ``` -------------------------------- ### Configure Backup File Extension Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/dotfiles.md Set the 'home-manager.backupFileExtension' option in your NixOS or nix-darwin configuration to specify a backup extension. ```nix { home-manager.backupFileExtension = "backup"; } ``` -------------------------------- ### Activate Home Manager Configuration Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/usage/configuration.md Commands to apply the Home Manager configuration. `home-manager switch` applies changes directly, while `home-manager build` creates a result link for inspection. ```shell home-manager switch ``` ```shell home-manager build ``` -------------------------------- ### Run All Home Manager Tests Manually Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/contributing/tests.md Execute the entire Home Manager test suite using `nix-build`. This method may impurely source the system's Nixpkgs. ```shell # The full Home Manager test suite can be run by executing $ nix-build --pure --option allow-import-from-derivation false tests -A build.all ``` -------------------------------- ### Importing Unstable Nixpkgs with Channels Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/faq/unstable.md Import Nixpkgs from the unstable channel to access its packages. Ensure the 'nixpkgs-unstable' channel is added and updated. ```nix { pkgs, config, ... }: let pkgsUnstable = import {}; in { home.packages = [ pkgsUnstable.foo ]; # … } ``` -------------------------------- ### Run a Specific Home Manager Test Manually Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/contributing/tests.md Execute an individual test case using `nix-build`. This approach may also impurely source the system's Nixpkgs. ```shell # and run an individual test, for example `alacritty-empty-settings`, through $ nix-build --pure tests --option allow-import-from-derivation false -A build.alacritty-empty-settings ``` -------------------------------- ### List All Home Manager Tests Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/contributing/tests.md Use this command to list all available tests discoverable by the Home Manager `tests` command. ```shell # List all available tests $ nix run .#tests -- -l ``` -------------------------------- ### Create a News Entry using Nix Shell Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/contributing/news.md An alternative method to create a news entry file using a specific development shell and script. This achieves the same result as the `nix run` command. ```shell $ nix-shell -A dev --run modules/misc/news/create-news-entry.sh ``` -------------------------------- ### List Home Manager Integration Tests Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/contributing/tests.md Discover and list only the integration tests. Note that these are primarily available on Linux. ```shell # List integration tests $ nix run .#tests -- -t -l ``` -------------------------------- ### Run Home Manager Tests Against Flake Nixpkgs Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/contributing/tests.md Execute tests using the Nixpkgs version specified in the `flake.lock` file. This ensures consistency and avoids impure sourcing. ```shell # To run against the Nixpkgs from the `flake.lock` file, use instead e.g. $ nix build .#test-all ``` ```shell # or $ nix build .#test-alacritty-empty-settings ``` -------------------------------- ### Add Home Manager Release Channel Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/installation/standalone.md Add a specific Home Manager release channel and update it. Use this if you are following a Nixpkgs version 26.05 channel. ```shell $ nix-channel --add https://github.com/nix-community/home-manager/archive/release-26.05.tar.gz home-manager $ nix-channel --update ``` -------------------------------- ### Run Home Manager Integration Tests Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/contributing/tests.md Execute all integration tests. This command is most effective on Linux systems. ```shell # Run all integration tests $ nix run .#tests -- -t integration-test- ``` -------------------------------- ### Source Session Variables (Alternative Path) Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/installation/standalone.md Source the Home Manager session variables script from an alternative path. This is used when managing home configuration with system configuration. ```bash /etc/profiles/per-user/$USER/etc/profile.d/hm-session-vars.sh ``` -------------------------------- ### Add Overlay for Module Package Source: https://github.com/nix-community/home-manager/blob/master/docs/manual/faq/change-package-module.md When a module lacks a `package` option, use Nixpkgs overlays to substitute the package with one from a different channel, like unstable. ```nix { pkgs, config, ... }: let pkgsUnstable = import {}; in { programs.skim.enable = true; nixpkgs.overlays = [ (_final: _prev: { skim = pkgsUnstable.skim; }) ]; # … } ```