u/DVT01

▲ 7 r/NixOS

Setting up disko after installation

Hello!

I'm new to Nix and NixOS, as I switched to NixOS 2 weeks ago. I found out about disko shortly after my switch. My understanding is that with disko you can install NixOS with your config from the start, so the first generation would be from your config.

I switched to NixOS because it's easy to install my exact system on all my devices (e.g. desktop, laptop, etc). I'm not sure if there is a better way by default, but to install NixOS on a new device I follow these steps:

  1. Install NixOS on the device from the USB ISO
  2. Boot into the device, add git, vim and enable experimental flakes, and switch to this generation
  3. Clone my NixOS configuration
  4. Copy over the automatically generated disk configurations to my NixOS system config
  5. Create boot generation from my custom config

I don't know if the following is correct, but with disko I understand that to install NixOS with your config, you can install NixOS from the iso using your NixOS flake config directly onto the device as the first generation.

My question is: already having NixOS installed on my system, can I setup disko on my existing config?

In case it is relevant, this is my NixOS config: diego-velez/nixos

EDIT: It seems that the answer is no.

Since the steps to re-install the OS are tedious imo, I looked into disko, and played with it in a vm. To my nixos repo, I duplicated my desktop host but with disko. These are the steps I did from the NixOS minimal ISO live image inside the VM to install my nixos config with disko:

  1. Set root password: sudo passwd root
  2. Start ssh: sudo systemctl start sshd
  3. Find out ip: ip addr
  4. From host, SSH into live image: ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@<ip>
  5. Git clone nixos repo: git clone https://github.com/diego-velez/nixos
  6. Format the disk: sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko/latest -- --mode destroy,format,mount ./nixos/hosts/desktop-disko/disko-config.nix
  7. Generate initial config: nixos-generate-config --no-filesystems --root /mnt
  8. Install the OS with my config: sudo nixos-install --root /mnt --flake ./nixos#desktop-disko
  9. If no initial password, after booting, set user password

I've seen that nixos-anywhere might automate all these steps. I will look into it.

EDIT: Just tried nixos-anywhere, and I'm hooked lmao. Literally, after you have a working disko config, all you need to do is be able to connect to the remote machine via SSH. Then you just run one command: nix run github:nix-community/nixos-anywhere -- --flake <path_to_flake>#<host> --target-host root@<remote_ip>, and you're done.

reddit.com
u/DVT01 — 8 days ago