[HELP] How can I manually install NixOS from a bootable USB drive and use a remote Flake repository to set up my system with a custom configuration?

I’m planning to wipe the slate clean and install a fresh OS using a bootable USB drive. But here’s the cool part: I want to grab a custom system configuration from a remote Flake repository during the install. That way, the new system will be all set up with my preferred settings right from the start.

nixos-install has --flake argument:

       --flake flake-uri#name
               Build the NixOS system from the specified flake. The flake must contain an output named ‘nixosConfigurations.name’.

So you should be able to specify when it’s time to actually install the system any flake there like this: nixos-install --flake github:my/repo#machinename. Note that it will use all hardware specs from that flake, so you should keep them as abstract as you can.

You could also create a new flake.nix in /mnt/etc/nixos before running nixos-install with contents like this (assuming you provide nixosModule output with your config):

{
  inputs.nixpkgs = "github:nixos/nixpkgs/nixos-24.05";
  inputs.my-repo = "github:my/repo";
  outputs = {self, nixpkgs, my-repo}: {
    nixosConfigurations.machinename = nixpkgs.lib.nixosSystem {
      modules = [
        ./hardware-configuration.nix
        my-repo.nixosModules.mymachine
      ];
    };
  };
}

Then results of nixos-generate-config will be used in your config.

3 Likes

I appreciate your assistance in answering my question. I am pleased to confirm that the installation process functioned as intended.

1 Like

After you placed the flake in /mnt/etc/nixos,

What was the nix install command you used?

And if my existing flake/repo references a hardware-configuration.nix, and then I’m referencing the new one in this flake? Does it use this one? Then I could replace in repo after the initial install?

Then I want to figure out how to add disko to the equation.

Hey, I think the following reference might give you more detail on your questions.
Installing NixOS with Flakes and LVM on LUKS

Sorry for the inconvenience of my answer to give you a straight answer to your questions. I also followed the above reference to install my NixOS. Hope it’ll give you the solutions.