Install NixOS from existing Linux

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.
      ./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?

}

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;
  services.gnome3.chrome-gnome-shell.enable = true;

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

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

 boot.loader.grub.extraEntries = ''
   menuentry "Fedora" {
     search --set=fedora --fs-uid dm-name-VolumeGroup-root
     configfile "($fedora)/boot/grub/grub.cfg"
   }
 '';

How should I proceed?
Thank you very much

@akiross I have (almost) the exact same setup (on lvm). This is the pertinent component of my configuration.nix:

{ config, pkgs, ... }:
{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
    ];

  # Use the systemd-boot EFI boot loader.
  boot.loader.systemd-boot.enable = false;
  boot.loader.efi.canTouchEfiVariables = true;
  boot.loader.efi.efiSysMountPoint = "/boot/efi"; #This is the most important line
  boot.loader.grub.enable = true;
  boot.loader.grub.version = 2;
  boot.loader.grub.device = "nodev";
  boot.loader.grub.efiSupport = true;
  boot.loader.grub.useOSProber = false;
  boot.supportedFilesystems = [ "ntfs" ];
  boot.loader.grub.extraEntries = ''
	menuentry "Windows Boot Manager (on /dev/nvme0n1p2)" --class windows --class os {
		insmod part_gpt
		insmod fat
		search --no-floppy --fs-uuid --set=root 40E2-A3BF
		chainloader /EFI/Microsoft/Boot/bootmgfw.efi
	}

	menuentry "Fedora" --class fedora --class os {
		insmod part_gpt
		insmod ext2
		insmod fat
		search --no-floppy --fs-uuid --set=root 40E2-A3BF
		chainloader /EFI/fedora/grubx64.efi
	}
'';

}

And my hardware-configuration.nix:

# Do not modify this file!  It was generated by ‘nixos-generate-config’
# and may be overwritten by future invocations.  Please make changes
# to /etc/nixos/configuration.nix instead.
{ config, lib, pkgs, ... }:

{
  imports =
    [ <nixpkgs/nixos/modules/installer/scan/not-detected.nix>
    ];

  boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "nvme" "usb_storage" "usbhid" "sd_mod" "sr_mod" ];
  boot.initrd.kernelModules = [ "dm-snapshot" ];
  boot.kernelModules = [ "kvm-intel" ];
  boot.extraModulePackages = [ ];

  fileSystems."/" =
    { device = "/dev/disk/by-uuid/3244183c-5adf-47c9-8b20-6be2d3f45502";
      fsType = "ext4";
    };

  fileSystems."/home" =
    { device = "/dev/disk/by-uuid/b792912b-943e-48d4-a2ff-c716ef4123fc";
      fsType = "ext4";
    };

  fileSystems."/boot" =
    { device = "/dev/disk/by-uuid/d391084d-b279-4b51-a8ab-7ee9883d6b7d";
      fsType = "ext4";
    };

  fileSystems."/boot/efi" =
    { device = "/dev/disk/by-uuid/40E2-A3BF";
      fsType = "vfat";
    };

  swapDevices =
    [ { device = "/dev/disk/by-uuid/daddec15-1691-4efc-b783-9d683b44a05c"; }
    ];

  nix.maxJobs = lib.mkDefault 8;
  powerManagement.cpuFreqGovernor = lib.mkDefault "performance";
}

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.

See also: NixOS managed grub not detecting another distribution (Fedora)

1 Like

Hello @mjlbach and thanks for your help!

Your configuration has been useful, but I did something wrong because I am unable to use GRUB to start the Fedora system.

The current status is:

  1. power on
  2. grub showing
  3. fedora entries won’t work
  4. nixos entry work

NixOS is the default UEFI boot entry, so it will start, leading to grub, but I can still start Fedora via the UEFI boot menu - not grub.

I tried these configurations:

{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
    ];

  boot.loader.systemd-boot.enable = false;
  boot.loader.efi.canTouchEfiVariables = true; 
  boot.loader.efi.efiSysMountPoint = "/boot/efi";
  boot.loader.grub.device = "nodev";  # do not install grub, just add entries
  boot.loader.grub.efiSupport = true;  # build grub with efi support, default false
  boot.loader.grub.useOSProber = false;
  boot.loader.grub.extraEntries = ''
    menuentry "Fedora ONE" {
        search --set=boot --fs-uid 8FBB-25E7
        configfile "($boot)/EFI/fedora/grub.cfg"
    }

    menuentry "Fedora TWO" --class fedora --class os {
        insmod part_gpt
        insmod ext2
        insmod fat
        search --no-floppy --fs-uuid --set=root 65176797-2614-4b29-be42-a529e26013b0
        search --no-floppy --fs-uuid --set=boot 8FBB-25E7
        chainloader ($boot)/EFI/fedora/grubx64.efi
    }
  '';
{ config, lib, pkgs, ... }:
 
{
  imports =
    [ <nixpkgs/nixos/modules/installer/scan/not-detected.nix>
    ];
 
  boot.initrd.availableKernelModules = [ "ahci" "nvme" "rtsx_pci_sdmmc" ];
  boot.initrd.kernelModules = [ "dm-snapshot" ];
  boot.kernelModules = [ "kvm-intel" ];
  boot.extraModulePackages = [ ];
 
  fileSystems."/" =
    { device = "/dev/disk/by-uuid/517592fb-a3a5-4338-9bd3-e1fcbc005c1e";
      fsType = "ext4";
    };
 
  fileSystems."/boot" =
    { device = "/dev/disk/by-uuid/65176797-2614-4b29-be42-a529e26013b0";
      fsType = "ext4";
    };
 
  fileSystems."/boot/efi" =
    { device = "/dev/disk/by-uuid/8FBB-25E7";
      fsType = "vfat";
    };
 
  swapDevices =
    [ { device = "/dev/disk/by-uuid/3db6a809-03c2-4d96-b870-51d6924581aa"; }
    ];
 
  powerManagement.cpuFreqGovernor = lib.mkDefault "powersave";
  # High-DPI console
  console.font = lib.mkDefault "${pkgs.terminus_font}/share/consolefonts/ter-u28n.psf.gz";
}

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.

Did you try in your first config this:

	menuentry "Fedora" --class fedora --class os {
		insmod part_gpt
		insmod ext2
		insmod fat
		search --no-floppy --fs-uuid --set=root 8FBB-25E7
		chainloader /EFI/fedora/grubx64.efi
	}

Also can you confirm that grubx64.efi is located at /EFI/fedora/grubx64.efi when 8FBB-25E7 is mounted?

You may need to not set boot.loader.grub.device = “nodev”;

Before I got it working, I also had the issue where selecting fedora would trigger a restart.

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 :slight_smile:
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.

Our approach is currently to just use kexec to boot into a proper nixos using this tool

2 Likes

Sorry for missing this! If the ISO doesn’t work that’s definitely an issue that should be tracked. In any case, the kexec approach works well. It’s reasonably straightforward, you first pass it the command line arguments and then you tell it to switch, at which point it instantly loads the kernel and it’s as if you booted regularly.