NixOS is a Linux distribution that is built around the Nix package manager. More information is in my previous post(s). This post is about the way I added home-manager to my (modular) Nixos configuration.
Including home-manager Link to heading
First home-manager needs to be added to the normal Nixos configuration. This can be done by adding just a few lines of code. See how to do this in the example below:
{ config, pkgs, ... }:
let
home-manager = builtins.fetchTarball "https://github.com/nix-community/home-manager/archive/release-22.11.tar.gz";
in
{
imports =
[ # Include the results of the hardware scan.
./t14s-hardware-configuration.nix
./parts/generic-boot-systemd.nix
./parts/generic-desktop.nix
./parts/generic.nix
./parts/virtualisation.nix
./parts/printing.nix
./parts/users.nix
./parts/apps-default.nix
./parts/apps-extra-cli.nix
./parts/apps-extra-desktop.nix
./parts/apps-extra-music.nix
./parts/fonts.nix
"${home-manager}/nixos"
];
# Home-manager profiles
home-manager.users.patrick = import ./home/patrick-base-t14s.nix;
...
Notice:
- the lines between
let
andin
at the top of the file, - the import line (
"${home-manager}/nixos"
), and - the added profile line (
home-manager.users.patrick = ...
).
Also notice that the home-manager profile actually imports a nix configuration. This nix configuration is specific per person (since it is the users personal home-manager setup) so each user can have this import line.
Home manager configuration Link to heading
The basic home-manager configuration file is personal per user. However, multiple users can share imports from within that personal configuration file.
For example, my personal home-manager configuration file looks as follows:
{ config, pkgs, lib, ... }:
{
# Home Manager settings
#
# https://mipmip.github.io/home-manager-option-search/
imports =
[
./patrick-zshell.nix
./patrick-sway.nix
./patrick-git.nix
./generic-tealdeer.nix
./generic-tmux.nix
./generic-gammastep.nix
];
# home-manager.useGlobalPkgs = true; # Use the global pkgs that is configured via the system level nixpkgs options
programs.home-manager.enable = true; # Let Home Manager install and manage itself.
home.username = "patrick";
home.homeDirectory = "/home/patrick";
# 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.
home.stateVersion = "22.11";
}
The home manager configuration is modularized in a similar fashion as my normal Nixos configuration. Therefore it shows files which are and are not prepaned with my username (patrick). Those with a username are for that user specifically.
Applying and updating the configuration Link to heading
This works in the same fashion as in my modular setup (see the previous blog post).