nixconfig/README.md

2.5 KiB

folliehiyuki's Nix configuration

This Nix flake is used to manage:

  • my work laptop (an Apple M2 Macbook Air)
  • my NixOS desktop

For the configuration of my other desktop hosts running either AlpineLinux or ChimeraLinux, see dotfiles-ansible repository.

Table of Content

Setup

Darwin

nix and homebrew need to be installed separately:

  • nix: sh <(curl -L https://nixos.org/nix/install)
  • homebrew: bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Currently, there is only 1 Darwin host, to configure it:

nix build .#darwinConfigurations.hoangnguyenhuy.system
./result/sw/bin/darwin-rebuild switch --flake .#hoangnguyenhuy

NixOS

The NixOS host is set up with tmpfs root, so a few prerequisite steps are needed before nixos-install can be executed:

# Destroy, partition, format the targeted disk and mount them to /mnt
# Method 1: via a custom-built disko script
nix build .#nixosConfigurations.aragorn.config.system.build.diskoScript && ./result
# Method 2: use the original `disko` toplevel script via nix run
nix run .#disko -- --mode disko --flake .#aragorn

# Generate SSH key pairs
mkdir -m 0755 -p /mnt/persist/etc/ssh
ssh-keygen -t rsa -b 4096 -C root@aragorn -f /mnt/persist/etc/ssh/ssh_host_rsa_key
ssh-keygen -t ed25519 -C root@aragorn -f /mnt/persist/etc/ssh/ssh_host_ed25519_key

# Update .sops.yaml file with this new key, and run `sops updatekeys` for the host secrets

# Generate a random machine-id file (should be confidential :v)
systemd-machine-id-setup --root /mnt/persist/

# Install the NixOS system
nixos-install --no-root-passwd --root /mnt --flake .#aragorn

# Unmount and reboot
umount -R /mnt
reboot

# Reconfigure the installed system in the future
nixos-rebuild switch --flake .#aragorn

Credits

Guides for NixOS root on tmpfs: