Home Manager Setup
Manage user environments with Home Manager
Manage personal configuration files and profiles with Home Manager, similar to the way that system configuration is performed, but don't require users to have root access.
This is a work in progress.
TODO
- Optimize path when first installing via
nix-shell
Make sure NixOS can handle Nix Flakes and nix-command
# ~/.config/nix/nix.conf
nix = {
package = pkgs.nixFlakes;
extraOptions = ''
experimental-features = nix-command flakes
'';
};
As the user add home manager channel
nix-channel --add https://github.com/nix-community/home-manager/archive/release-23.05.tar.gz home-manager
nix-channel --update
Logout and log back in to install
nix-shell '<home-manager>' -A install
This will create a default configuration flie at ~/.config/home-manager/home.nix
. Clone a repository into the folder like so.
rm -rf ~/.config/home-manager
git clone https://github.com/tiredofit/home.git ~/.config/home-manager
If no repo, there should be at the very least the following:
# ~.config/home-manager/flake.nix
{
description = "Tired of I.T! Home Manager configuration";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
home-manager = {
url = "github:nix-community/home-manager/release-23.05";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { nixpkgs, home-manager, ... }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
in {
homeConfigurations.dave = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
./home.nix
];
};
};
}
# ~/.config/home-manager/home.nix
{ config, pkgs, ... }:
{
imports = [
];
home = {
username = "dave";
homeDirectory = "/home/dave";
stateVersion = "23.05";
language = {
base = "en_US.UTF-8";
address = "en_US.UTF-8";
collate = "en_US.UTF-8";
ctype = "en_US.UTF-8";
measurement ="en_US.UTF-8";
messages ="en_US.UTF-8";
monetary ="en_US.UTF-8";
name = "en_US.UTF-8";
numeric ="en_US.UTF-8";
paper = "en_US.UTF-8";
time = "en_US.UTF-8";
};
};
nixpkgs = {
config = {
allowUnfree = true;
allowUnfreePredicate = (_: true);
};
};
programs = {
home-manager.enable = true;
direnv = {
enable = true;
nix-direnv = {
enable = true;
};
};
};
}
Activate Home Manager
home-manager switch --flake ~/.config/home-manager/#dave -v
Keeping things up to date
Update Repository changes
nix flake update ~/.config/home-manager
Use this script
# update.sh
#!/bin/sh
case "${1}" in
home )
_old=$(pwd)
echo "** Updating Home"
cd ~/.config/home-manager
nix flake update ~/.config/home-manager --extra-experimental-features "nix-command flakes"
echo "** Switching Configuration"
cd "${_old}"
home-manager switch --flake ~/.config/home-manager/#${USER} -v
;;
system )
echo "** Updating Flake"
sudo nix flake update /etc/nixos/
echo "Switching Profile"
sudo nixos-rebuild switch --flake /etc/nixos/#${HOSTNAME}
;;
esac
Optimized Install w/Flakes
If not installed - make sure Nix is installed
sh <(curl -L https://nixos.org/nix/install) --daemon
nix run home-manager/master --extra-experimental-features "flakes nix-command" -- init --switch
mkdir -p $HOME/src/home
git clone https://git.tiredofit.ca/tiredofit/home-manager $HOME/src/home
home-manager switch --flake /home/$USER/src/home#$HOSTNAME.$USER --extra-experimental-features "flakes nix-command"