Nix refers to the holy trinity: An operating system, a programming language, and a package manager.
- NixOS is a Linux distribution that's configured directly from these dotfiles, and can be rolled back upon a system breaking config change. This allows fearless tinkering!
- NixOS isn't FHS compliant, and cannot execute random binaries. However, there are workarounds for these two issues.
- NixLang is a functional programming language which means it's pure and immutable. There is no state in a functional programming language.
- By far the best of the three is Nix the package manager. It allows declarative, rather than imperative, package management. This provides repoducibility among many systems, including even MacOS!
- An interesting (although not very useful for many) result that comes from this declarative structure is the fact that a system configured in this declarative way can survive bit rot.
- Nix shells allow you to temporarily download packages for one time uses. The package manager will then garbage collect (at your discretion) and remove these packages. No longer do you have to worry about bloat accumulating from packages you forgot to remove!
- nix flake update
- sudo nixos-rebuild switch --flake .#default
- home-manager switch --flake .#axelcool1234
- sudo nixos-rebuild switch --flake .#default --rollback
Firstly... DON'T PANIC! This will be an easy transition - even if we only have the terminal (I'm assuming we start in the base home directory).
- Execute
sudo nix-channel --add https://nixos.org/channels/nixos-unstable nixos
- Execute
sudo nix-channel --list
and ensure you only have the unstable branch as a channel. Callsudo nix-channel --remove [name]
if that's not the case. - Execute
sudo nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
- Execute
sudo nix-channel --update
- This website has more information about installing home-manager (you shouldn't need this, but just in case!): https://nix-community.github.io/home-manager/index.xhtml#sec-install-standalone
- To ensure it has been installed correctly, try "man home-configuration.nix" - this might only work after step 5.
- Execute
nix-shell -p home-manager git
- Clone this repository -
git clone https://github.com/axelcool1234/.dotfiles.git
- Execute
cp /etc/nixos/hardware-configuration.nix .dotfiles/hosts/Legion-Laptop/hardware-configuration.nix
- Execute
cd .dotfiles
- Execute
nix flake update
(you may need to temporarily enable experimental features for the command) - Execute
sudo nixos-rebuild switch --flake .#default
- Execute
home-manager switch --flake .#axelcool1234
If home-manager fails to install due to a mismatch in a hash, that means we need to update that hash. If you don't know where the mismatched hash is, I recommend:
- Execute
nix-shell -p ripgrep
- Execute
rg
and then part of the name of the derivation with the mismatched hash. You should be able to find where it's located. - Change the
sha256
of the derivation with thesha256
the home-manager error outputted. - Try to execute
home-manager switch --flake .#axelcool1234
again.
Once this is all done, we can execute reboot
and get into our system. It should be just as how you remembered it! Remember to commit and push these .dotfiles,
since you called nix flake update
! You may need to do the post-setup steps to be able to properly commit and push these changes.
We need to make sure our github is configured with an SSH key so we can actually develop! Arguably, this step should be set up using something like sops Nix. At some point I'll have to learn how to use that - or some other secret management system for Nix.
- Execute
ssh-keygen
- Execute
cat
and wherever the result of thessh-keygen
was stored. We want the.pub
file to be outputted, so we can copy it. - Paste the copied SSH key on github by going to Settings -> "SSH and GPG Keys" -> "New SSH Key" and then save the new SSH key
- Execute
cd .dotfiles
- Execute
git remote set-url origin [email protected]:axelcool1234/.dotfiles.git
- Execute
git fetch
You can now commit and push changes to the .dotfiles to GitHub!
Has your bootloader been wiped? Try this:
- Boot up a live installation USB (as long as it's Linux this solution should work)
- Execute
lsblk -o +LABEL
and identify your Linux root partition (the one with the most space) and the boot partition (should be something like 512 MB) - Execute
sudo mount /dev/[linux root partition] /mnt
- Execute
sudo mount /dev/[linux boot partition] /mnt/boot
cd
to/mnt
- Execute
cd /home/axelcool1234/.dotfiles
- Execute
sudo nixos-install --flake .#default
Your bootloader should've been reinstalled. Now, when you reboot, GRUB (or whatever bootloader being used at the time) should start up.
Make sure to execute nixos-switch
once you've booted into NixOS so that GRUB can be reconfigured.
For more information, I learned how to do this from this discussion.
- https://mynixos.com/
- Great for browsing options from NixOS and Home-manager
- https://search.nixos.org/packages
- Great for searching for available packages
- https://noogle.dev/
- Great for searching the NixLang library