/dotfiles

My dotfiles for GNU/Linux, FreeBSD and macOS. Managed using chezmoi. Fish, Mutt/Neomutt, neovim, tmux, ...

Primary LanguageVim Script

gwarf's dotfiles

My messy dotfiles for GNU/Linux and macOS. WIP :)

Chezmoi

Some files or configuration parts are for GNU/Linux (Archlinux and NixOS) and some others are for macOS.

WIP++ I'm converting this repository from using nix and home-manager to chezmoi.

Why moving to chezmoi?

Using NixOS and Homemanager on macOS was fun and quite efficient, but remained too complex on some aspects, thus I decided to move to something simpler. In addition to this, there were recently some issues in the nix community and various points from those people made sense to me:

Initialising

chezmoi init gwarf
chezmoi diff
chezmoi apply

Pulling changes

# Pull changes and review them
chezmoi git pull -- --autostash --rebase && chezmoi diff
# Apply them
chezmoi apply
# Pull and apply all at once
chezmoi update

Pushing changes

chezmoi cd
git status
git commit -a
git push

Nix (Legacy)

The nix setup got converted from yadm to using nix and home-manager.

Searching for a Nix package, an option, …

# Using new "experimental" nix search command
nix search nixpkgs firefox
# If experimental features are not enabled
nix --extra-experimental-features "nix-command flakes" search nixpkgs firefox
# Using legacy slow nix-env
nix-env -qaP firefox

It is also possible to use different online services to search in the browser:

Updating nix flakes inputs

To refresh the information about all flakes inputs, it's possible to use two commands:

Beware as if you are using some nighlyt or unstable inputs it could break, and commit the change, making reverting a bit less easier (but still doable).

  • nix flake lock allows to specify one more multiple inputs to update and then you will have to manually commit the changes to the lock file.
# Checking satus of inputs
nix flake info
# Update all flake inputs and commit lock file
nix flake update --commit-lock-file
# Update main inputs
nix flake lock --update-input nixpkgs \
  --update-input nixpkgs-unstable \
  --update-input nixpkgs-darwin-stable \
  --update-input home-manager
# Update neovim inputs
nix flake lock --update-input neovim-nightly-overlay --update-input nix2lua
# Update nix user repository input
nix flake lock --update-input nur
# Update home-manager input
nix flake lock --update-input home-manager

Nix upgrade

  • Read release notes for nix, nixos and home-manager
  • Update channels definition (replace existing ones, with most recent ones)
  • Update channels
  • Rebuild the system

NixOS setup

NixOS version: using the stable NixOS release, and allowing to explicitly select packages from unstable.

Managing NixOS using flakes and Mome Manager

Manage NixOS configuration in ~/repo/dotfiles.

home-manager examples are available in the test modules.

# Download flake locally
gh repo clone gwarf/dotfiles
cd ~/repos/dotfiles/
# Rebuild all system conf
# Used to make test, not changing conf available at boot
nix build ".#nixosConfigurations.brutal.config.system.build.toplevel"
sudo result/bin/switch-to-configuration switch
# Build and siwtch to the new conf, updating boot menu
sudo nixos-rebuild switch --flake .
# On macOS
nix flake update --commit-lock-file
darwin-rebuild switch --flake .
# In case the hostname changed (like on a VPN), it can be specified like this
./result/sw/bin/darwin-rebuild switch --flake . -p 'darwinConfigurations.Baptistes-MBP.system'
Updating

The first thing is to update the nix flake inputs, then rebuilding the system using those inputs.

# Rebuilding system
sudo nixos-rebuild switch --flake .
# upgrade nixpkgs **only** and rebuild flake-managed system
sudo nixos-rebuild switch --upgrade --update-input nixpkgs \
  --commit-lock-file --flake ~/repos/dotfiles
# On macOS
nix flake update --commit-lock-file
darwin-rebuild switch --flake .
Cleaning old generations
# List generations
nix-env -p /nix/var/nix/profiles/system --list-generations
# Delete all generations
nix-env --delete-generations old
# Delete generations older than 14d
nix-env --delete-generations 14d
# Delete specific generations
nix-env --delete-generations 10 11 14
# Collect garbage
sudo nix-collect-garbage -d

macOS AKA Darwin using flakes and Home Manager

Using nix-darwin, initially based on the video and gist from @jmatsushita:

The flake can be updated as for other nix anf flake-based systems.

# Rebuild all system conf
nix build ".#darwinConfigurations.Baptistes-MBP.system"
# Switch to the new conf
./result/sw/bin/darwin-rebuild switch --flake .

Managing project-specific env with nix flakes and direnv

For python

See:

Using a Nix flake templates for easy dev envs:

nix flake init --template github:the-nix-way/dev-templates#python
direnv allow
# Edit flake.nix as needed, adding packages or python packages.

Interesting approach to look into: reddit post allowing to use requirements.txt

References

Videos

Flakes

Nix Darwin

Home manager

Real world flakes from other users