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).
Install NixOS on another partition, from your existing Linux distribution (without the use of a USB or optical device!)
Install NixOS on the same partition (in place!), from your existing non-NixOS Linux distribution using NIXOS_LUSTRATE .
Install NixOS on your hard drive from the Live CD of any Linux distribution.
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)
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)
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.
Remember to give the VM partitions a label. In hardware-configuration.nix refer to these labels. THIS IS IMPORTANT.
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
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.
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
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.
./hardware-configuration.nix
];
# 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 = "127.0.0.1,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; [
networkmanagerapplet
wget vim
];
# Some programs need SUID wrappers, can be configured further or are
# started in user sessions.
programs.mtr.enable = 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 https://nixos.org/nixos/options.html).
system.stateVersion = "20.03"; # Did you read the comment?
}
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”.
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.
Hi,
thanks for the tips, but I still have some doubts.
I tried installing NixOS from liveusb but failed, so I’m trying to install it to another partition side-to-side with my current installation (Fedora 31).
My major problem is that I’m not sure how to mount the boot partitions (EFI system, GPT). In the current Fedora installation, the situation is this:
/dev/sda1 mounted in /boot/efi
/dev/sda2 mounted in /boot
/dev/sda3 is a LVM physical volume with 3 logical volumes:
/dev/VolumeGroup/swap
/dev/VolumeGroup/root mounted to / in fedora
/dev/VolumeGroup/nixos that should be mounted as / in nixos
The objective is to have nixos and fedora side-to-side, selectable in GRUB.
I prepared the /dev/VolumeGroup/nixos partition, but I’m not sure if I should mount the boot partitions as fedora is doing or not. Before installing, should I run
# mount /dev/VolumeGroup/nixos /mnt
# mount /dev/sda2 /mnt/boot
# mount /dev/sda1 /mnt/boot/efi
or should I run
# mount /dev/VolumeGroup/nixos /mnt
# mount /dev/sda1 /mnt/boot
Which one? I don’t know what the installer would do, so I can’t chose and I would like to get it right and not break the current system.
Also, I am not sure about the GRUB configuration. My current setup is:
boot.loader.grub.useOSProber = true;
but I’m unsure if this is enough or I should have explicitly
The confusing part is Fedora on UEFI has two partitions mounted under boot, one for the EFI images that should be mounted at /boot/efi (where Fedora’ grub is contained in /boot/efi/EFI/fedora/grubx64.cfg) and one partition for /boot which contains the kernel. T
The above should allow the system to boot. Change your uuid’s of course (include --root in the grub override). Note, this chainload’s Fedora’s grub, so you’ll be forwarded from the nix grub into fedora grub. I find this is more robust (although if anyone’s gotten auto-updating fedora kernels in nix grub please let me know.
I added 2 entries just to see the various results.
In the first case, “Fedora ONE” (configfile), the system just reboots,
while in the second case “Fedora TWO” (chainloader), I get a grub> prompt, but I couldn’t manage to use it.
Not sure how to fix this, even if I can boot, so it’s not really a problem.
Yes, I also tried that, but without prefixing ($root) to the chainload path I get a not found error.
Regarding the nodev: what’s the point of it? I get that nodev will change grub config, without installing grub. From my understanding, grub is already there due to fedora installation, so nix is updating the config but the grub I see is the one from fedora, so I don’t really need to unset nodev.
This being said, unsetting it will probably reinstall it over the existing one, which is not really a problem.
Is that correct?
Now, I thought I might try with no grub altogether, so I’ll just use the UEFI boot menu instead
Not really a fix, but still good for me.
@wmertens May I ask if you could help me? I’d like to try your technique but I’ve not worked out how to get the install scripts…
Background is that the NixOS .iso’s using dd will not boot on my Thinkpad X1 Tablet 2nd gen. Ubuntu ones and others do… and I’ve done it 100s of times before so that’s odd.