Inspired by Leon Breedt's repo.
-
Install Nix using the Determinate Systems Nix installer.
-
Install Homebrew (it's only used to install Casks and Mac App Store apps, its not in the
$PATH
). -
Ensure that the current user is able to clone the private secrets repo before proceeding to the next step, by putting the SSH private key needed to clone the repo into
$HOME/.ssh/id_rsa
. -
Run
env FLAKE=<NAME> ./bootstrap
. After a successful bootstrap, the hostname will be updated to match the flake. -
Whenever you make configuration changes, run
./rebuild
. If any files are reported as being in the way, move them out of the way and re-run.
TODO: Below instructions are outdated and not adapted for complete flake rewrite.
-
Download the latest NixOS stable distribution, these instructions were tested with 22.11. Download the minimal distribution, not graphical.
-
Create a bootable USB.
-
Boot from the USB device.
-
Create root and boot partitions and format them with the file system of your choice, use the nixos and swap labels, as our configuration depends on these labels, and mount the file systems in
/mnt
and/mnt/boot
, respectively. -
Run
nixos-generate-config --root /mnt
-
Clone this repository to
/mnt/etc/nixos/nixos-config
:nix-shell -p git echo https://<USER>:<GITHUB-TOKEN>@github.com > $HOME/.git-credentials git clone https://github.com/leonbreedt/nixos-config.git /mnt/etc/nixos/nixos-config
-
Ensure the
root
user has the SSH public key for cloning the secret repository referenced by theflake.nix
, it should be put in/root/.ssh
with appropriate permissions. Runssh [email protected]
at least once, and save the GitHub SSH key (needed to avoid thenixos-install
command hanging waiting for user input when cloning the secrets repo). -
Run the installer, where
<SYSTEM>
is the name of the system inflake.nix
:nixos-install --flake "/mnt/etc/nixos/nixos-config#<SYSTEM>" -v
You will be prompted for a root password, which you can use after reboot to give the normal user a password to log in if you want to use X11. Only the normal user will be able to SSH in.
-
Whenever you make changes to the configuration, you can Run
env FLAKE=<SYSTEM> ./rebuild
in/etc/nixos/nixos-config
, where<SYSTEM>
is the name of the system inflake.nix
. This will runnixos-rebuild
in flake mode, and switch to the built configuration afterwards.
TODO: Below instructions are outdated and not adapted for complete flake rewrite.
-
Clone this repository on an existing NixOS system, and ensure
nativeSystemd
is set tofalse
inwsl/default.nix
. -
Build the latest
main
branch on an existing NixOS system:nix build .#nixosConfigurations.<WSL-CONFIG-NAME>.config.system.build.installer
-
This will produce a tarball in
./result/tarball/nixos-wsl-installer.tar.gz
, copy it somewhere (e.g USB). -
Import the NixOS distribution tarball into the appropriate location (where you want
.\NixOS\
to be located, e.g. on a data drive:wsl --import NixOS .\NixOS\ nixos-wsl-installer.tar.gz --version 2
-
Launch the distribution, after it is finished it should launch the shell for the user in your configuration:
wsl -d NixOS
-
Clone this repository to
/etc/nixos/nixos-config
:sudo mkdir /etc/nixos sudo git clone https://github.com/leonbreedt/nixos-config.git /etc/nixos/nixos-config
-
Change to
/etc/nixos/nixos-config
and run./rebuild
to do the initial build.
Whenever you make changes to the configuration, just run ./rebuild
in the cloned
flake directory to apply it to your system. Since the value of FLAKE
defaults
to the current hostname, you don't have to pass a hostname for subsequent builds,
once it has been built once.
There are still some rough edges with this configuration. Mainly around first-time setup/retrieval of credentials from my private repo, you won't get access to it :)
If you remove the private repo input in flake.nix
and the secrets references
you can likely get it going.
If you run a command that is not installed, and you get an error like this:
DBI connect('dbname=/nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite','',...) failed:
unable to open database file at /run/current-system/sw/bin/command-not-found line 13.
Then you can likely resolve it by updating your Nix channels for the root user.
sudo nix-channel --update
Since are using rustup
instead of global native Nix Rust packages, make
sure rust-analyzer
is installed:
rustup component add rust-analyzer