Install NixOS from existing Linux

Just a note: I installed NixOS without needing the installer ISO. Instead I first installed Nix in the “host Linux”, and then I managed to get the install scripts with

nix-build '<nixpkgs/nixos>' -A -A -I nixos-config=/nix/store/75yffgx3600s8cwdmmzz9803k88ppxmv-nixpkgs-20.09pre221814.10100a97c89/nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix

Then, I first used the nixos-in-place approach of bind-mounting a subdirectory as root and swapping the roots in stage1, but then I realized that with btrfs subvolumes or LVM volumes, this is not needed.

I also decided to share the nix and home volumes between the installs.

So what is needed is:

  • install Nix, preferably multi-user
  • get the install scripts as above
  • mount the desired root filesystem
  • bind-mount the efi boot (if using efi), home, nix and any other volumes you wish to share inside that root
  • run nixos-generate-config, edit the config, nixos-install

I think this would be easier if

  • the install scripts are a nixpkgs package
  • there is a script to convert a single-user install to multi-user

I think that you would be interested in this script : it is used to bootstrap NixOS on server that don’t “natively” support NixOS.

Right, I saw that, but it doesn’t work with EFI and it wipes the old root, whereas I want to be able to go back to Mint while I figure out how to set up my desktop…

Thanks for the insight!

I think having installers in nixos is reasonable separation of concerns, and while converting single to multi user installs would sure be handy now and then, I imagine it would be very tricky to implement.

But it’s very hard to get the install scripts from non-nixos, where you want them in the first place. How is that a good separation?
Or maybe there should be a nix-installer package that just references the scripts in the nixos tree


Do you think we should add something to this section of the NixOS manual?

I am new to NixOS and have been trying to install the OS several times already and all have failed. Once the computer even reached a reboot, but in the middle everything got stuck (frozen) and … I had to cancel everything.
Why not make an intuitive graphical installer like others do?
I was very interested in the NixOS concept itself and wanted to test (for my own interest) and figure it out for future possible use. But installing on a computer is so complicated (usb or lustration) that we have to give up a rather interesting experience.
The instructions are written more for professionals than for ordinary users. It’s a pity.
We have to wait until it reaches the normal installer, as we have come to the graphical DE on the ISO.

Welcome Sergio! There are three ways of installing NixOS from an existing Linux installation. It sounds like you’ve tried both option 1 and option 2. Personally, I used option 2 (using NIXOS_LUSTRATE).

  1. Install NixOS on another partition, from your existing Linux distribution (without the use of a USB or optical device!)
  2. Install NixOS on the same partition (in place!), from your existing non-NixOS Linux distribution using NIXOS_LUSTRATE .
  3. Install NixOS on your hard drive from the Live CD of any Linux distribution.

I assume you’re following the instructions in section 2.5.4 of the manual. Which step are you stuck on?

It would probably help if you include your configuration.nix and hardware-configuration.nix so we can see if there’s anything unusual.

There is also another way which I used to install transfering from a VM. This also allows you to multi-boot alongside existing linux.

I’ll briefly talk here and if somebody wants more explanation I would explain.

DO NOT GO DOWN THIS WAY unless you have some basic understanding of partitioning and booatloaders.
There would be some minor hiccups but this is still pretty simple really. (I’m talking only about concepts, exact steps would need me to reinstall)

  1. Make a VM (It doesn’t matter if you use a fixed size HDD or not but HDD size should be similar to your NixOS partition size)

  2. Make three partitions, in your hardware computer. Note their exact byte sizes. CAREFUL- gparted on your existing linux and gparted on NixOS live cd may use different units by default. Now make the same partitions in the VM.
    a) /boot (yes, separate despite MBR, not a necessity but still). recommended size 300 MB
    b) /
    c) Swap (You’ll have an existing swap in your hardware, just make sure to label vm and hw swaps same). In hardware, swapoff, relabel, swapon.

  3. Remember to give the VM partitions a label. In hardware-configuration.nix refer to these labels. THIS IS IMPORTANT.

  4. Install. See that everything is how you’d like. If you don’t have a wired connection in your hardware computer then add a wifi program in your VM installation. I prefer iwd

  5. Reboot into the iso. dd from VM’s /boot to a file. Use scp to copy this to a hardware computer (as a file). Now dd to the hardware’s /boot.

  6. Reboot hardware. When you’re at grub, type in e. There, delete everything and type this:
    configfile (hd_,msdos_)/boot/grub/grub.cfg where you have to replace hd_ and msdos_ with appropriate numbers. Sidenote- arch’s grub allows completion with options at the bottom inside this editing interface, try hitting tab for options. You can also just jump directly to the grub command line and enter this configfile command there. There you also get tab completion.

If you are able to see NixOS grub then step 1 is done. Boot to your regular linux instead. Now copy the / partition from VM to hardware, similar to how you did for /boot. Now reboot hardware and use that configfile way.

Y0u’re inside NixOS. If you’d like you can do a nixos rebuild-switch --install-bootloader after changing boot.loader.grub.device.

I think this can be extended to BIOS + GPT and UEFI + GPT too but you’ll have to know your concepts there.

With BIOS + GPT, I believe the only difference is that in step 3, you’ll have to label your hardware partitions too. (with BIOS+MBR, labels are stored in the partition itself so dd takes care).

I’ve never used UEFI but on the arch wiki UEFI sounds even simpler than Legacy BIOS so maybe worth a try.

If anyone tries this, I’d love to hear your experience.

Thinking about it, you can actually install from Windows too, you’ll only need a live CD with grub. Or if you can boot to a VBR somehow then just install grub stage 1 in your /boot.

Hi mhwombat,
I tried to install from a flash drive, followed the instructions from the official site, and got stuck after the reboot command, when after loading the first graphic screen with NixOS versions appeared, after confirmation there should be a graphic DE, but I only had a black screen with a terminal.
After that, no matter what passwords (combinations) I entered - everything was rejected and I could not move one step further.
After unsuccessful attempts, I decided to abandon this idea and wait for the time when (if) an acceptable graphical installer for this OS appears, as almost all other distros now have it.
I am grateful to everyone for the desire to help me with advice, but I decided so far to refrain from this idea.
Thanks again.

when installing, there should be a step to do a sudo nixos-install --root /mnt, that will ask you for root’s password, you will need to sign in as root and the password which you just entered. Then you can set the password for your user

jonringer thanks for your advice.
Next time I’ll try to take this into account.

Today, I was finally able to install the OS on part of the disk.
And now I have problems:

  • the system does not connect to Wi-Fi - there is no connection, nor the usual icon for connecting
  • it is not clear how to set a password for the user. The password that I set is suitable only for the root. I did not find a clear instruction in the instructions (I am not English - there may be a problem with the translation)
  • without Wi-Fi I can neither update the system nor switch to nixos-unstable
    Well, the most incomprehensible thing for me - after the reboot everything worked as it should, but in the GRUB (which is on the “sda” disk) there is no other system (not marked), but I have Kubuntu and Fedora there. Moreover, after booting from sdb, from Fedora GRUB, NixOS is missing.
    • I would still like to complete the installation, but apparently I did something wrong.
    • I will be glad of any help.
    • In configuration.nix, I have this:

t# Edit this configuration file to define what should be installed on
# your system.  Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).

{ config, pkgs, ... }:

  imports =
    [ # Include the results of the hardware scan.

  # Use the GRUB 2 boot loader.
  boot.loader.grub.enable = true;
  boot.loader.grub.version = 2;
  # boot.loader.grub.efiSupport = true;
  # boot.loader.grub.efiInstallAsRemovable = true;
  # boot.loader.efi.efiSysMountPoint = "/boot/efi";
  # Define on which hard drive you want to install Grub.
   boot.loader.grub.device = "/dev/sda"; # or "nodev" for efi only

   networking.hostName = "ToshibaP300"; # Define your hostname.
   networking.wireless.enable = true;  # Enables wireless support via wpa_supplicant.

  # The global useDHCP flag is deprecated, therefore explicitly set to false here.
  # Per-interface useDHCP will be mandatory in the future, so this generated config
  # replicates the default behaviour.
  # networking.useDHCP = false;
  # networking.interfaces.enp3s0.useDHCP = true;
    networking.interfaces.wlp2s0.useDHCP = true;

  # Configure network proxy if necessary
  # networking.proxy.default = "http://user:password@proxy:port/";
  # networking.proxy.noProxy = ",localhost,internal.domain";

  # Select internationalisation properties.
   i18n.defaultLocale = "en_US.UTF-8";
   console = {
     font = "Lat2-Terminus16";
     keyMap = "us";

  # Set your time zone.
   time.timeZone = "Europe/Kiev";

  # List packages installed in system profile. To search, run:
  # $ nix search wget
     environment.systemPackages = with pkgs; [
     wget vim

  # Some programs need SUID wrappers, can be configured further or are
  # started in user sessions. = true;
    programs.gnupg.agent = {
     enable = true;
     enableSSHSupport = true;
     pinentryFlavor = "gnome3";

  # List services that you want to enable:

  # Enable the OpenSSH daemon.
    services.openssh.enable = true;

  # Open ports in the firewall.
  # networking.firewall.allowedTCPPorts = [ ... ];
  # networking.firewall.allowedUDPPorts = [ ... ];
  # Or disable the firewall altogether.
  # networking.firewall.enable = false;

  # Enable CUPS to print documents.
   services.printing.enable = true;

  # Enable sound.
   sound.enable = true;
   hardware.pulseaudio.enable = true;

  # Enable the X11 windowing system.
   services.xserver.enable = true;
   services.xserver.layout = "us";
   services.xserver.xkbOptions = "eurosign:e";

  # Enable touchpad support.
   services.xserver.libinput.enable = true;

  # Enable the KDE Desktop Environment.
   services.xserver.displayManager.sddm.enable = true;
   services.xserver.desktopManager.plasma5.enable = true;

  # Define a user account. Don't forget to set a password with ‘passwd’.
   users.users.sergio = {
     createHome = true;
     isNormalUser = true;
     extraGroups = [ "wheel" "video" "audio" "disk" "networkmanager" ];
     group = "users";
     uid = 1000; 
   # Enable ‘sudo’ for the user.

  # This value determines the NixOS release from which the default
  # settings for stateful data, like file locations and database versions
  # on your system were taken. It‘s perfectly fine and recommended to leave
  # this value at the release version of the first install of this system.
  # Before changing this value read the documentation for this option
  # (e.g. man configuration.nix or on
  system.stateVersion = "20.03"; # Did you read the comment?


not sure what the KDE version is, but you can do networking.networkmanager.enable = true; to use the NetworkManager utility

# as root
passwd sergio
# asks to put in password twice

You also need boot.loader.grub.useOSProber = true; for grub to look for other bootable partitions

@SergioTar I had to manually add fedora to grub to get it to be recognized via chainloading

see: NixOS managed grub not detecting another distribution (Fedora)

Thanks for the tips.
“configuration.nix” I have already adjusted.
Now I wonder if I can somehow start NixOS or should I do everything from scratch?
In the existing GRUB (Fedora) there is no NixOS but it exists on the disk and I can even edit “configuration.nix”.

Thanks for the tips.
I will try to somehow boot first NixOS

You should be able to chainload either grub depending on which grub you set precedence, just change the path to grub.cfg in configfile to point at nix.

I already solved the problem with the GRUB as you both suggested to me. It worked.
But with Wi-Fi, I still have a problem. The fact that I was advised did not work and caused a conflict.
I’ll look for more options.

You can’t have both wireless and networkmanager be enabled. You have to disable wireless and configure your wifi with NetworkManager.

Also take a look at the nixos-hardware repo.

I really like what Gnome3 is doing, my configuration for that is

  # Some programs need SUID wrappers, can be configured further or are
  # started in user sessions.
  programs.gnupg.agent = {
    enable = true;
    enableSSHSupport = true;
    pinentryFlavor = "gnome3";

  # Enable sound.
  sound.enable = true;
  hardware.pulseaudio.enable = true;
  hardware.pulseaudio.support32Bit = true;

  # Enable the X11 windowing system.
  services.xserver.enable = true;
  services.xserver.layout = "us";

  # Enable touchpad support.
  services.xserver.libinput.enable = true;
  # Use Gnome3
  services.xserver.displayManager.gdm.enable = true;
  services.xserver.desktopManager.gnome3.enable = true; = true;

  # for the Gnome Software app
  services.flatpak.enable = true;
1 Like