Skip to content

Instantly share code, notes, and snippets.

@bartman
Last active November 25, 2024 13:06
Show Gist options
  • Save bartman/7ffc5fe7b38e9e736ce6ef58e2571f31 to your computer and use it in GitHub Desktop.
Save bartman/7ffc5fe7b38e9e736ce6ef58e2571f31 to your computer and use it in GitHub Desktop.
switching Debian 12 bookworm to Nix and home-manager

intro

I have a Raspberry PI 5 with a freshly installed Debian 12 (using Raspberry PI Imager). I chose the version without a Desktop environment.

NOTE: this is a brand new environment, and I had nothing to retain (like dotfiles, etc).

Ultimately, I pushed this to here: https://github.com/bartman/nix

switching Debian to use Nix

system configuration

(optional) install etckeeper before we start

sduo apt install etckeeper

install the Nix packages

sudo apt install nix-setup-systemd

only users in nix-users can get access to /nix store

sudo /sbin/adduser $USER nix-users

allow Nix to use flakes and nix-command in /etc/nix/nix.conf...

experimental-features = nix-command flakes

enable Nix environment loading when shell starts

sudo cp /usr/share/doc/nix-bin/examples/nix-profile-daemon.sh /etc/profile.d/

restart the Pi

sudo reboot

user home-manager configuration

Create a new Nix home config file

mkdir ~/nix
cd ~/nix
nix run home-manager -- init --switch .

Make sure it works

home-manager --version

installing new packages through home-manager

Edit the generated ~/nix/home.nix adding neovim and changing some options

{ config, pkgs, ... }:
{
    home.username = "bart";                # you will see your $USER name here
    home.homeDirectory = "/home/bart";     # you will see your $HOME path here
    home.stateVersion = "24.05";
    home.packages = [
        pkgs.neovim                        # this is how we add packages
    ];
    home.file = { };
    home.sessionVariables = {
        EDITOR = "nvim";                   # this is how to set ENV variables
    };

    # see https://mynixos.com/home-manager/options/
    # or `man home-configuration.nix` about available variables
    programs.man.generateCaches = true;
    programs.git.userName = "bart";        # you may want to set this to your name

    programs.home-manager.enable = true;
}    

Execute the changes

home-manager switch --flake ~/nix#bart

NOTE: "~/nix#bart" is composed of path to where to find the flake file (~/nix) and the name of the config in the file (bart). There could be multiple concurrent configurations that you can switch between.

letting Nix manage bashrc/profile

Edit the ~/nix/home.nix adding something like:

  programs.bash = {
    enable = true;
    historySize = 10000;
    historyFileSize = 100000;
  }
  programs.starship.enable = true;
  programs.fzf.enable = true;

Execute the changes

home-manager switch --flake ~/nix#bart

references

documentation

resoures

random videos I watched

examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment