- Introduction
- Setup NixOS with Flakes
- Configure Home Manager
- Issues Encountered
- Using Home Manager
- Conclusion
This document outlines the steps I followed to install Home Manager on NixOS using flakes, detailing the configuration process, issues encountered, and how to use Home Manager.
- Ensure that you have NixOS installed and that flakes are enabled. Add the following to your
/etc/nixos/configuration.nix:nix = { package = pkgs.nixFlakes; extraOptions = '' experimental-features = nix-command flakes ''; };
- Apply the configuration:
sudo nixos-rebuild switch
- Create a
flake.nixfile to configure NixOS with Home Manager:{ description = "NixOS configuration for Rob's system"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; home-manager.url = "github:nix-community/home-manager"; home-manager.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = { self, nixpkgs, home-manager }: { nixosConfigurations = { rob-nixos = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = [ ./configuration.nix home-manager.nixosModules.home-manager { home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; home-manager.backupFileExtension = "backup"; # Set backup file extension home-manager.users.rob = import ./home.nix { pkgs = import nixpkgs { system = "x86_64-linux"; }; lib = nixpkgs.lib; config = {}; }; } ]; }; }; }; }
- Create a
home.nixfile for Home Manager configuration:{ config, pkgs, lib, ... }: { home.username = "rob"; home.homeDirectory = "/home/rob"; programs.home-manager.enable = true; home.stateVersion = "23.05"; # Specify the version of Home Manager programs.bash = { enable = true; initExtra = '' # Add any custom initialization for bash here export EDITOR="nano" ''; }; home.packages = with pkgs; [ pkgs.nano pkgs.vim pkgs.git pkgs.wget ]; home.sessionVariables = { EDITOR = "nano"; }; }
- Apply the configuration with flakes:
sudo nixos-rebuild switch --flake .#
Initially, I encountered an error related to the undefined variable 'system':
error: undefined variable ‘system’
This was resolved by explicitly defining 'system' when importing nixpkgs within flake.nix.
Another issue was the missing 'stateVersion', which is required for Home Manager:
error: The option `home-manager.users.rob.home.stateVersion’ is used but not defined.
This was fixed by adding the 'stateVersion' option in home.nix.
There were conflicts with existing files, which required setting a backup file extension:
error: The option `home-manager.users.rob.home-manager’ does not exist.
This was resolved by correctly placing the 'backupFileExtension' option in flake.nix under the home-manager module.
Once Home Manager is installed and configured, you can start using it to manage your home environment.
To manage packages, add them to the home.packages attribute in your home.nix file. For example:
home.packages = with pkgs; [
pkgs.nano
pkks.vim
pkgs.git
pkgs.wget
];You can set various configuration options for your user environment in the home.nix file. For example, to set the default editor to nano:
home.sessionVariables = {
EDITOR = "nano";
};After making changes to your home.nix file, apply the new configuration using the following command:
home-manager switchTo manage your Home Manager configuration with GitHub, follow these steps:
- Initialize a Git repository in your configuration directory:
git init - Add your configuration files to the repository:
git add flake.nix home.nix configuration.nix - Commit the changes:
git commit -m "Initial commit of Home Manager configuration" - Create a repository on GitHub, and then add it as a remote in your local repository:
git remote add origin https://github.com/yourusername/yourrepository.git - Push the changes to GitHub:
git push -u origin master
Now your Home Manager configuration is version-controlled and hosted on GitHub. You can pull changes from GitHub on other machines and apply the configuration using the following commands:
git pull origin master
sudo nixos-rebuild switch --flake .#
home-manager switchBy following these steps and resolving the issues encountered, I successfully installed and configured Home Manager on NixOS using flakes. This setup allows for efficient management of the home environment and seamless updates using the flake-based approach. Additionally, managing the configuration with GitHub ensures that changes are version-controlled and easily deployable across multiple machines.
