I wrote a long article about my journey to Nix, NixOS, Home Manager and flakes where you may find more background information about this repository and its goals.
My setup is using the flake.nix
as a central point.
flake.nix
is calling most of the other files depending on the set hostname:
hosts/$HOSTNAME/default.nix
configuration.nix
- all files related to
home-manager
:homemanager.nix
andhomemanager/*
The directory assets
contain various configuration and binary files
I wanted to keep close to my NixOS configuration files.
I wrote several shell scripts so that I don’t have to remember the commands for updating and so forth.
you can update the setup using nixos-rebuild_switch_flake.sh
which
basically invokes the command:
sudo nixos-rebuild switch --flake /home/vk/nixos
In practice, I’m using nh-os-switch.sh
to update my setup to meet
the stored configuration. This is a visually appealing wrapper that is
using nh to run:
nh os switch --ask "/home/vk/nixos"
You may need to adapt the paths to meet your path, of course.
You should start with the nixos-rebuild
command and then optionally
switch to nh
when everything is working so far.
update-flake.sh
is updating the flake definitions to the most
current ones and commit them to the git repository. Therefore, as long
as you don’t invoke this command, no package updates will be
downloaded from the remote repositories.
From time to time, you may want to invoke garbage-collecting.sh
to
get rid of older data which is not required any more.
configuration.nix
also contains a weekly garbage collection but I’m
not sure when and how this is invoked. If you need more space at a
certain point in time, you’re save to invoke garbage-collecting.sh
any time.
As of 2023-12-25, I do have four different hosts running this NixOS configuration:
jackson is my business notebook (Lenovo T490) which I’m using during a business week. This is the most intensly used NixOS system at the moment by far.
floyd is my personal notebook (Lenovo X260) which I was using to test NixOS without affecting my main systems that are running Xubuntu LTS or Debian stable. I don’t work on it much. It’s mostly used for FOSS conferences I attend.
nixosvmr and nixosvms are two qemu virtual machines in order to test multi-host setup or to play with my NixOS configuration without having floyd around. Notice that as of 2023-08-09, 20GB (virtual) disk space is too small. NixOS really adds up lots of space in comparison to Debian-based distributions. I’m using the VMs rarely since I started with floyd and jackson.
- Download installer ISO :focus:
- https://nixos.org/download.html#nixos-iso
- Don’t use the “Minimal ISO” since it might not come with some GUI stuff we need.
- I was using “GNOME 64 Bit”
- [2023-07-29 Sat] I used: https://channels.nixos.org/nixos-23.05/latest-nixos-gnome-x86_64-linux.iso
- https://nixos.org/download.html#nixos-iso
- Install NixOS using that ISO
- Learn how to set up a USB thumb drive and boot from it for installing the basic OS
- Modify default configuration.nix:
- Start an editor:
sudo nano /etc/nixos/configuration.nix
- Change hostname on new host from default if necessary:
- https://borretti.me/article/nixos-for-the-impatient#postinstall
- by setting
networking.hostName
from “nixos” to a new hostname
- by setting
- https://borretti.me/article/nixos-for-the-impatient#postinstall
- Activate flakes: https://nixos.wiki/wiki/Flakes
“On NixOS set the following options in
configuration.nix
and runnixos-rebuild
”{ pkgs, ... }: { # usual, this line is already there nix.settings.experimental-features = [ "nix-command" "flakes" ]; } # usual, this line is already there
- Add the
git
and package. Also add your favourite editor as well for fixing miscellaneous things. I’m usingvim
for that.- Just write the corresponding package name where
firefox
is installed in theconfiguration.nix
.
- Just write the corresponding package name where
- OPTIONALLY: Install packages like vim, sshd, flakes in case you need to play around more
- Just write the corresponding package name where
firefox
is installed in theconfiguration.nix
.
- Just write the corresponding package name where
- Update and activate your setup
sudo nixos-rebuild switch
- Start an editor:
- Get this NixOS configuration git repository via (
scp
orgit clone https://github.com/novoid/nixos-config.git ~/nixos
)- target directory:
~/nixos/nixos-configuration
- I’m using following command at my LAN:
scp -r vk@192.168.2.42:src/nixos-configuration ~/ && mv ~/nixos-configuration ~/nixos
- I’m using following command at my LAN:
- target directory:
- Create a configuration for the
$HOSTNAME
in the nixos-configuration git repo- Adapt
flakes.nix
- Create
~/nixos/hosts/$HOSTNAME
(from an existing host as template) - Get the
hardware-configuration.nix
into your new setupcd ~/nixos cp /etc/nixos/hardware-configuration.nix ~/nixos/hosts/$HOSTNAME/ cp /etc/nixos/configuration.nix ~/nixos/hosts/$HOSTNAME/default.nix git add
- Adapt
- Check for things that won’t work or need attention when you’re not Karl Voit:
- Check out all spots marked with “SPECIFICTOKARL” for things that are different on your side:
git grep -B 1 -A 2 SPECIFICTOKARL
flake.nix
:description
,system.stateVersion
, username “vk”, …
- Check out all spots marked with “FIXXME” for things that may need attention to fix:
git grep -B 1 -A 2 FIXXME
- Check out all spots marked with “DEPENDENCY” for things that are referring to stuff which is not available in this NixOS repository:
git grep -B 1 -A 2 DEPENDENCY
- Usually, you might want to get rid of those things because the would result in errors in your situation.
- Check out all spots marked with “SPECIFICTOKARL” for things that are different on your side:
- Run flakes with the new setup:
- Switch to nixos-config dir
- Double-check: make sure that hostname matches a config
- Run flakes with current nixos-config dir:
sudo nixos-rebuild switch --flake .
- Fix any error that may arise at this point.
- Yes, this can be frustrating. I wish you good luck here.
- Usually, you just have to remove stuff from
~/nixos/hosts/$HOSTNAME/default.nix
when it is also defined inflakes.nix
or other existing files. - Futhermore, you might have to create (and
git add
) configuration files that are assumed to exist such asassets/.tmuxp/$HOSTNAME.yaml
.
- I do recommend a reboot here to cleanly boot the updated OS with all of its settings.
- Execute store optimization (replacing copies with hardlinks):
nix-store --optimise
- OPTIONALLY: Symlink
/etc/nixos
to~/nixos
if you want to usenixos-rebuild
without the optional parameter for the path.
This is quite handy to be included here because this is what I typically do right after setting up NixOS if I don’t take over the old keys via my previous dotfiles.
Please do replace $HOST
(your hostname), $USER
(your local
username) and $GITHUBUSER
(username at GitHub) accordingly:
- execute
ssh-keygen -t ed25519 -C "git.$HOST@karl-voit.at"
- This creates a new SSH key, using the provided email as a label.
- At the prompt, type a secure passphrase.
- Choose a file name:
/home/$USER/.ssh/id_ed25519_Git_$HOST
- adding to ssh-agend:
ssh-add ~/.ssh/id_ed25519_Git_$HOST
- visit https://github.com/settings/keys
- click on “New SSH key”
- insert a name and paste the content of the following file:
~/.ssh/id_ed25519_Git_$HOST.pub
- add the following lines to your
~/.ssh/config
file (create if it doesn’t exist):host github.com IdentityFile ~/.ssh/id_ed25519_Git_$HOST User $GITHUBUSER
If not specified otherwise, this configuration is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License