- Nix 39.3%
- TypeScript 37.7%
- HTML 16.6%
- Shell 5.4%
- CSS 0.6%
- Other 0.4%
| home | ||
| hosts | ||
| modules/nixos | ||
| .gitignore | ||
| flake.lock | ||
| flake.nix | ||
| README.md | ||
NixOS Configuration Flake
This is the NixOS configuration for my personal devices. It is structured as a flake and also contains some "for personal use only" applications and scripts. Maybe some bits are useful for you as well 🤷
Deployment
Deploying the configuration to the device is done via nixos-rebuild and the --build-host and --target-host options.
nixos-rebuild switch --flake .#claw --build-host stesie@claw.local --target-host stesie@claw.local --sudo
It is important to note that the --build-host and --target-host options must be used together, otherwise
(if you only specify --build-host) the configuration will be built on the remote machine, and then rolled
out locally.
Device Bootstrapping
Raspberry Pi
This is the description for a network install that does not require the Raspberry Pi to be connected to a display.
Instead it's sufficient to connet it to the network via ethernet cable and ssh into the machine.
The SD card image will setup the root account and a user called nixos without password.
However the SSH service is configred to not accept empty passwords.
So in order to login via SSH, you need to pre-load your SSH key into the authorized_keys file of either the root user or the nixos user.
The first step is to download the bootable SD card image from the Hydra build system, see this nixos.wiki entry.
Pre-load an SSH key into the image
- Use
nix run nixpkgs#parted <img>to find out what exactly to mount. See this stackoverflow answer for details. - Mount the image file into a local directory by running
mkdir img
sudo mount -o loop,offset=<result from parted> <image file name> img
- Generate an SSH key if you haven't already using the
ssh-keygentool. - The SD card image will setup a user called
nixoson first boot. For that reason/home/nixosdoes not exist in the image you just mounted. Create the user home, and pre-load your SSH key as an authorized key:
sudo mkdir -p img/home/nixos/.ssh
sudo cp ~/.ssh/id_rsa.pub img/home/nixos/.ssh/authorized_keys
sudo chown -R 1000:100 img/home/nixos
sudo chmod -R 700 img/home/nixos
sudo chmod 600 img/home/nixos/.ssh/authorized_keys
- Unmount the image via
sudo umount img - Use
nix run nixpkgs#rpi-imagerto run the Raspberry Pi imager and write the image to the SD card.
After first boot
- Once the key is on the device, ssh into it as the
nixosuser. - Run
sudo nixos-generate-configto generate the initial configuration. - IMPORTANT: You need to make two modifications to
/etc/nixos/configuration.nix. If you forget to add this to the config, when younixos-rebuild switchyou won't be able to login anymore!
- Configure the
nixosuser:
users.users.nixos = {
isNormalUser = true;
extraGroups = ["wheel"];
};
- Enable the SSH services:
services.openssh = {
enable = true;
# require public key authentication for better security
settings.PasswordAuthentication = false;
settings.KbdInteractiveAuthentication = false;
#settings.PermitRootLogin = "yes";
};