Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ajhalili2006/0ec6a39eca2f455406eed94f2047db84 to your computer and use it in GitHub Desktop.

Select an option

Save ajhalili2006/0ec6a39eca2f455406eed94f2047db84 to your computer and use it in GitHub Desktop.

Copilot Chat Conversation Export: Reinstalling NixOS with flake configuration

User: @ajhalili2006 Thread URL: https://github.com/copilot/c/a3f0710d-7d1c-4f43-960f-c9ffa49e4753

@ajhalili2006

How do I re-install NixOS using my existing flake-based config via nixos-install on a live CD session?

Copilot

To re-install NixOS using your existing flake-based configuration from a live CD session, you can use the nixos-install command with the --flake flag.

Based on your repository structure in andreijiroh-dev/nixops-config, follow these steps:

1. Prepare your partitions

Ensure your target drive is partitioned and formatted. Mount your root partition to /mnt and your boot/EFI partition to /mnt/boot (or whichever path is defined in your hardware-configuration.nix).

# Example (adjust device names to your actual setup)
mount /dev/disk/by-label/nixos /mnt
mkdir -p /mnt/boot
mount /dev/disk/by-label/boot /mnt/boot
# If using swapon
swapon /dev/disk/by-label/swap

2. Run the installation

Run nixos-install pointing to your remote flake. You will need to specify the attribute name of the host you are installing (e.g., stellapent-cier, portable, or lairland).

# Replace {hostname} with your target host, e.g., stellapent-cier
sudo nixos-install --flake github:andreijiroh-dev/nixops-config#{hostname}

3. Finalize

Once the installation finishes, set a root password if prompted, and then reboot:

reboot

Notes from your repository:

  • Hostnames: The available host configurations in your hosts/ directory are:
    • stellapent-cier
    • lairland
    • portable
    • raspi-base
    • recoverykit
  • Remote URL: Using github:andreijiroh-dev/nixops-config ensures you are pulling the latest pushed configuration. If you have local changes on a USB drive, you can use the path to that directory instead (e.g., --flake /path/to/repo#{hostname}).
  • Hardware Configuration: Ensure the hardware-configuration.nix inside hosts/{hostname}/ matches the hardware of the machine you are currently installing on. If the hardware has changed, you may need to generate a new one using nixos-generate-config --root /mnt --show-config and update your repository accordingly.

@ajhalili2006

What's the difference between partition UUIDs and regular UUIDs, as shown from my reformatted root partition in KDE Partition Manager, especially for editing hardware-configuration.nix?

Attachments: A screenshot of the reformatted root partition's details popout in KDE Partition Manager

Copilot

In your NixOS setup, understanding the difference between these two is crucial for ensuring your system boots correctly after reformatting. Based on the image, here is the breakdown:

1. UUID (Filesystem UUID)

  • What it is: A unique identifier for the filesystem (ext4, in your case) stored inside the partition.
  • Behavior: It is generated when you format the partition. If you reformat the partition, this UUID will change, even if you use the same filesystem type.
  • Value in Image: 3991c709-e64d-4166-9369-c3cbe39beaae
  • Linux Path: /dev/disk/by-uuid/3991c709-e64d-4166-9369-c3cbe39beaae

2. Partition UUID (PARTUUID)

  • What it is: A unique identifier for the partition entry itself in the GPT (GUID Partition Table).
  • Behavior: It is tied to the "slot" on the disk. It does not change if you reformat the filesystem inside. It only changes if you delete the partition and recreate it.
  • Value in Image: 8E01EDCC-4C43-4A97-9CE3-039AA0A200C2
  • Linux Path: /dev/disk/by-partuuid/8e01edcc-4c43-4a97-9ce3-039aa0a200c2

Which one should you use in hardware-configuration.nix?

By default, NixOS (nixos-generate-config) uses the Filesystem UUID. This is generally preferred because it ensures that Linux is mounting the correct data and filesystem type, rather than just a specific block on the disk.

Since you just reformatted your partition, you must update your hardware-configuration.nix with the new UUID (the highlighted one in your image).

Example update for your configuration:

fileSystems."/" =
  { device = "/dev/disk/by-uuid/3991c709-e64d-4166-9369-c3cbe39beaae";
    fsType = "ext4";
  };

Summary Comparison

Feature UUID (Filesystem) PARTUUID (Partition)
Scope Filesystem level (ext4, btrfs, etc.) Partition Table level (GPT)
When it changes Every time you format/reformat Only if you delete/recreate partition
NixOS Default Yes (Recommended) No (Usually for Bootloaders)
Use Case Mounting drives in /etc/fstab Identifying hardware slots/partitions

Pro-tip: If you use the PARTUUID, your system might still try to mount the drive even if the filesystem is corrupted or empty. Using the UUID acts as a safety check that the expected filesystem actually exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment