First nixos installation
1 Why NixOS
AFTER you reinstall your machine - to install the DEV environment, all you
have to take with you is /etc/nixos/configuration.nix
file, everything is
described in it. Amazing!
When previously you would have to check your notes for step by step instruction(similar like linux ubuntu install), to configure your new environment same as it was before, then run different scripts from different places, make sure you got them all.. with nix you will never have that pain again.
2 Why NixOS by others
3 Documentation
- nixos github repo - https://github.com/nix-community/NixOS-WSL
- nixos manual - https://nixos.org/manual/nix/stable/
4 Installation on WSL
Steps described here:
4.1 Check if NixOS is not already installed
Run the commands in windows cmd or powershell.
wsl --status wsl --version wsl --help wsl --list --verbose
4.2 Install
If it does not exist(wsl --list --verbose
does not yield result with nixos ),
then basically download nixos-wsl.tar.gz
into your windows /Downloads
folder from the latest release.
Then in CMD run(while in /Downloads folder):
wsl --import NixOS .\NixOS\ nixos-wsl.tar.gz --version 2
check if it was really installed:
wsl -l -v
You should see NixOS listed. Now we can run nixos:
wsl -d NixOS
After the initial installation, you need to update your channels once(while in
nixos), to be able to use nixos-rebuild
:
sudo nix-channel --add https://nixos.org/channels/nixos-23.11 nixos sudo nix-channel --update
5 Configure NixOS installation over Emacs
Enter nix-shell
to use Emacs(it does not get installed on the system, just
TEMPORARILY FROM NIXOS CACHE?). So I can then modify the configuration
/etc/nixos/configuration.nix
file.
nix-shell -p emacs29
Then let's run emacs in nix-shell(run with sudo)
sudo emacs
Ok now you are in Emacs, but in nix-shell
. If we turn off nixos now, when we
launch it again, emacs will not be available. Only after you run nix-shell -p
emacs
. Let's install emacs permanetely. First open the default NixOS
configuration file:
sudo emacs /etc/nixos/configuration.nix
Add the following 4 files lines, it will install Emacs globally and permanetely inside of NixOS as well as git(we will need it to clone our config repos). We Install emacs29 because of seq error message that I have faced before:
environment.systemPackages = with pkgs; [ emacs29 git ];
After adding these 4 lines to the config file, C-d
to go back to
nixos@nixos(out of nix-shell) and BUILD the nixos with the new changes(emacs
and git installation).
sudo nixos-rebuild switch
After this finishes running, you should be able to use Emacs and git!
emacs git status
6 Authenticate to git
Some of our config repos are private, so for that we need to authenticate to git first.
First you must do this.
Then one of these:
- authenticate with personal access token
- authenticate with ssh(usually using this at home)
- On work machine, set up ssh method to work repo.
- On work machine for personal repos - use token method.
7 Clone the dotfiles repo
It consists both emacs and nixos config, we will need both in the next steps.
mkdir ~/GIT
cd ~/GIT
git clone https://github.com/arvydasg/dotfiles
8 Using your own custom nixos configuration file
# delete current nixos directory sudo rm -rf /etc/nixos # put our config folder instead of the default one sudo ln -s ~/GIT/dotfiles/nixos/ /etc/nixos
Check if the symlink worked:
ls -la /etc | grep nixos
You should see nixos -> /home/nixos/GIT/dotfiles/nixos/
.
If so, then you are done.
We can rebuild NixOS with the settings from our personal configuration in mind.
sudo nixos-rebuild switch
After this is done running, our NixOS installation will be current, as the one described in the configuration file.
Note on Installing other packages
If you want to install a package called "make" for example and nixos says it can not find it when you attempt to install it, then you can do
command-not-found make
, this command will show each package which exposes that command. Quite useful to know all the versions/types of the package you want to install.
9 Using your own custom Emacs config
After we have all the "OS" dependencies installed, we can install Emacs dependencies.
# remove .emacs.d dir from ~/ first cd ~/GIT ln -s GIT/dotfiles/.emacs.d/ ~/.emacs.d
Check if symlink got created with(while in ~/ dir):
ls -la | grep .emacs.d
Should see something like .emacs.d -> GIT/dotfiles/.emacs.d/
.
Do the following step that is described in the emacs config, tangling part - here.
cd ~/.emacs.d
git update-index --assume-unchanged init.el
Try to launch emacs for all the packages to be installed.
10 GUI glitch
Reported it here - https://github.com/microsoft/wslg/issues/1148
Possible fix(questionable) .wslgconfig(as explained in the comments of the issue)