Collection of my NixOS configs
Use development shell templates:
nix flake init -t github:Mimovnik/mimonixos#<devshell>
where <devshell>
is one of the devshell templates from template/devshells/<devshell>
directory
nix --extra-experimental-features "nix-command flakes" shell nixpkgs#git
git clone https://github.com/Mimovnik/mimonixos ~/.mimonixos
# Backup default config
sudo mv /etc/nixos /etc/nixos.bak
# Link
sudo ln -s ~/.mimonixos /etc/nixos
sudo nixos-rebuild switch --flake ~/.mimonixos#myhost
Once the system is rebuilt you can use aliases for rebuliding, testing, editing, updating and deploying this config:
List them with:
alias | grep mim
Download iso image from here.
Determine usb drive name /dev/sdX with:
sudo blkid
Flash an usb drive:
cp /path/to/iso/file /dev/sdX
sync
Note
This may take a while and no output is printed during the copying.
Before rebooting you may need to reorder the boot records so the live iso is the first record to boot.
You can do it in your BIOS/UEFI or:
On UEFI you can use 'efibootmgr' utility:
See the current boot order:
efibootmgror on nix:
nix run nixpkgs#efibootmgrLook for the name of your usb drive
Change the order so nixos
sudo efibootmgr -o 0007,0002,0003
Boot into the live iso
Proceed with the installation
You can install nixos remotely via ssh using nixos-anywhere I have followed this guide.
- Target host
- Source host with nix
- Network connectivity between the two
Edit target host config on source machine
- Add authorized keys to new host config: Somewhere in the nixos module add
users.users.${username}.openssh.authorizedKeys.keys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKdW1UbkbF0p1yTBh2CKv//RsDvot07/t7AtdNGeAsx/ mimo@glados"
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPb0nrIl2mNjcXMmYWIMalZUGb9Kv/1htsLtqA8hYC/F mimovnik@walle"
];
or import modules/system/common/authorized-keys.nix
Note
It is already imported in modules/system/base/default.nix
- Configure storage using disko
Create
disko-config.nix
Import it in host's system config
Specify the main device:
disko.devices.disk.main.device = "/dev/sda";
- Start target host Boot into some linux with openssh
If you don't have os enter some live iso
- Test ssh connectivity for root on target host nixos-anywhere requires either ssh to root or passwordless sudo
On nixos iso you can change the root password with sudo passwd
because sudo doesn't need authentication
Test with:
TARGET=192.168.0.5
ssh root@$TARGET
- Run nixos-anywhere
CONFIG="samurai-tv"
TARGET=192.168.0.5
nix run github:nix-community/nixos-anywhere -- --generate-hardware-config nixos-generate-config ./hosts/$CONFIG/hardware-configuration.nix --flake ~/.mimonixos#$CONFIG --target-host root@$TARGET
Note
git add any new files regarding the new host configuration nix won't see the files unless they are staged
Example of such configuration is in hosts/samurai-tv
Note
I didn't have hardware-configuration.nix before running nixos-anywhere Although I imported it in system.nix