This repo contains my personal system configuration that consists of:
- My config for NixOS
- My config for Home Manager
- My dconf (written in Nix) for the Gnome Desktop Environment
- My ZFS partitioning and formatting script
- My dotfiles for Git, Fish, NeoVim, EditorConfig, Prettier
- My config for Nix-on-Droid (WIP)
- Old install scripts (tested on: {see CI matrix above})
It includes a Nix Flake file which acts as an entrypoint for Nix and defines the following outputs:
nixosConfigurations.*
- NixOS system configurationshomeConfigurations.*
- Nix Home Manager configurationnixOnDroidConfigurations.*
- Nix-on-Droid configuration for Nix-powered Android shell environment
This is how I apply my Nix configuration on my machines. If you fork this repo (to modify it as per your needs), you should be able to use the same commands as they're written in a generic way.
sudo nixos-rebuild switch --flake "$CFG#$(hostname)"
home-manager switch --flake $CFG#$USER
nix flake update $CFG
The versions of most software installed on the system are determined by the
Nixpkgs commit hash stored in the flake.lock
file. Running the command above
will update it (and the other flake inputs) to latest version.
Clone the repo, e.g. to $HOME/code/repos
:
git clone https://github.com/PetarKirov/dotfiles
Copy a machine configuration and modify it as needed:
cd dotfiles
cp -r nixos/machines/zlx-nixos-desktop2 nixos/machines/my-machine
# Edit nixos/machines/my-machine/*
- Find Nix packages: https://search.nixos.org/packages
- Browse NixOS configuration options:
- Full list (on a single page): https://nixos.org/manual/nixos/stable/options.html
- Search: https://search.nixos.org/options
- Home Manager docs: https://nix-community.github.io/home-manager/
- Home Manager options: https://nix-community.github.io/home-manager/options.html
- Nix Language
- Overview: https://nixery.dev/nix-1p.html
- Nix cheatsheet: https://learnxinyminutes.com/docs/nix
- Interactive tour of Nix: https://nixcloud.io/tour/?id=1
- Official docs: https://nixos.org/manual/nix/stable/expressions/writing-nix-expressions.html
- Nix Flakes
- An introduction: https://christine.website/blog/nix-flakes-1-2022-02-21
- Official docs: https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html
- Cachix: https://www.cachix.org
- Nix Direnv: https://github.com/nix-community/nix-direnv
- Direnv: https://direnv.net/
-
Boot into a live NixOS environment (either a live CD containing the NixOS installer or an existing NixOS installation on another drive)
- If you're using a live CD environment, be sure to update
/etc/nixos/configuration.nix
like so:
# Open the file and change it to the snippet below: sudo nvim /etc/nixos/configuration.nix # Once the file has been updated and saved, apply the settings: sudo nixos-rebuild switch
{ config, pkgs, ... }: { imports = [ <nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-graphical-gnome.nix> ]; nix = { trustedUsers = [ "root" "nixos" ]; extraOptions = '' experimental-features = nix-command flakes ''; }; }
These settings will ensure that you're using a recent enough version of Nix with the necessary features enabled.
- If you're using a live CD environment, be sure to update
-
Clone this repo and
cd
into it:git clone https://github.com/PetarKirov/dotfiles && cd dotfiles
-
Assuming that you're installing NixOS on a clean drive, run the automated ZFS partitioning tool:
- Run it in "dry-run" mode to get information about your system:
./utils/make_zfs.bash
- If you need to partition your drive run:
env DRY_RUN=0 KEEP_PARTITIONS=0 ./utils/make_zfs.bash
- If your drive is already partitioned, run:
env DRY_RUN=0 ./utils/make_zfs.bash
- Run it in "dry-run" mode to get information about your system:
-
Now there should be a root ZFS partition mounted at
/mnt
. To install NixOS there, run:
- Bash $
-
mkdir ./nixos/machines/my-machine sudo nixos-generate-config --root /mnt --dir /..$(git rev-parse --show-toplevel)/nixos/machines/my-machine
- Fish â‹Š>
-
mkdir ./nixos/machines/my-machine sudo nixos-generate-config --root /mnt --dir /..(git rev-parse --show-toplevel)/nixos/machines/my-machine
- Bash $
-
sudo nixos-install --impure --flake '.#my-machine' --root /mnt
- Fish â‹Š>
-
sudo nixos-install --impure --flake '.#my-machine' --root /mnt
Your files were automatically generated. Now they could be manually changed!
note: Do not forget to set random
hostId
. You can use the following command for generation:tr -dc 0-9a-f < /dev/urandom | head -c 8
With everything configured we can continue with:
(Replace my-machine
in the command above with the name of the
machine config you want to apply.)
-
Now that NixOS is installed, chroot into (using
nixos-enter
) and change the password of the default user:sudo nixos-enter --root /mnt passwd zlx exit
(Replace
zlx
in the command above with the your username.) -
Copy the
dotfiles
repo inside the user's home dir:mkdir -p /mnt/home/$USER/code/repos cp -a ../dotfiles /mnt/home/$USER/code/repos
-
Build the home-manager config and copy it to the new Nix Store:
nix build ".#homeConfigurations.$USER.activationPackage" sudo nix copy --to /mnt ./result/ --no-check-sigs
-
Reboot into the new Nix install, open a terminal, cd into the dotfiles dir and activate the home-manager config:
cd /home/$USER/code/repos/dotfiles nix path-info ".#homeConfigurations.$USER.activationPackage" | xargs -I@@ sh -c '@@/activate'
-
You're done!