Hello, I found about nixOS yesterday and I’m trying to install it from archlinux which is my current system. I have an MBR system and I want to keep archlinux and the current grub bootloader which is installed on disk. NixOS will be on the same disk as archlinux and /home will be on another disk partition which I already use for archlinux. I followed the “Installing from another Linux distribution” guide and I’m on step in which I need to edit the configuration file and create the “nixbld” user.
I stopped there mainly because of the warning about the "Once you complete this step, you might no longer be able to boot on existing systems without the help of a rescue USB drive or similar. "
I don’t want nixOS to replace my current grub. I’m planning after install of nixOS to update grub on archlinux, so to detect nixOS and add a menu entry for it.
So, with these in configuration file for grub section:
# Use the GRUB 2 boot loader.
boot.loader.grub.enable = true;
boot.loader.grub.version = 2;
boot.loader.grub.useOSProber = true;
# 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
boot.loader.grub.extraEntries = ''
menuentry "ArchLinux" {
search --set=archlinux --fs-uuid 015a421c-f3b9-473d-a353-c54a67edcf96
configfile "($archlinux)/boot/grub/grub.cfg"
}
'';
I will have grub package installed on nixOS, but without to install it on any partition? Do I need to uncomment the “device” line and use “nodev”? Do I need also to disable grub completely(boot.loader.grub.enable=false)?
Yeah, that’s what you want even though you’re not on an EFI system. A couple comments in the module definition indicate that this will let you generate a menu (suitable for loading from Arch’s GRUB installation) without installing anything to any partition’s boot record. Calling grub-install is skipped for every boot entry where the device is set to "nodev".
No, you don’t want to do that. Being able to choose which generation to boot into is an important feature of NixOS. You want to leave GRUB enabled so that NixOS still generates the menu that lists all of your available NixOS generations, so if you break something you can reboot into your previous config.
PS: I can’t remember the behavior, exactly, but I think nixos-install might try to save you from installing a system with no bootloader configured to be installed. If it does, you could try passing --no-bootloader (see the very short section on it in the nixos-install manual) to nixos-install. Only bother with that if nixos-install gives you trouble for without passing that flag. Let me know whether you end up needing that or not.
Thanks, I updated the configuration file but now I’m stack on the command which starts nixos-install. When I run
sudo PATH="$PATH:/usr/sbin:/sbin" NIX_PATH="$NIX_PATH" which nixos-install --root /run/media/nixOS
I get the error
building the configuration in /run/media/nixOS/etc/nixos/configuration.nix...
error: file 'nixpkgs/nixos' was not found in the Nix search path (add it using $NIX_PATH or -I)
That’s such an annoying issue, lol. It’s got to do with how your sudo configuration manages environment variables on Arch. It makes it so setting environment variables in sudo invocations doesn’t work. The Arch documentation on this is surprisingly sparse.
In case the modifications to PATH are not actually needed (I think they may not be), you can work around this by just using the -Ioption for nixos-install instead. This would look like nixos-install -I $NIX_PATH.
If that doesn’t work, and you actually need to deal with the environment variables getting stripped, there are a few things you can do:
enable yourself to set environment variables in sudo invocations via SETENV, if you don’t have sufficient permissions already, then use sudo -E instead of just sudo
replace your Nix installation on Arch Linux with a multi-user install, then run nixos-install in a rootlogin shell, where the environment variables will get set in bashrc
Sorry for the information overload here. I’d definitely see if nixos-install -I does the trick first, since that’s the path of least resistance. If you do end up editing /etc/sudoers, don’t forget to use visudo, just in case you have a typo!
Thanks for giving the docs a good test on this type of installation. nixos-install-tools hasn’t been available in Nixpkgs for very long (it used to just be a NixOS module, IIRC), so I don’t think many people who aren’t already Nixers have tried it yet, and it can be hard to anticipate how different distros will configure sudo and PAM.
Oh! It also looks like if you install Nix via pacman, Arch will set up the environment variables for you via PAM by creating the required configuration file. To avoid any issues, I’d uninstall Nix first, but then you can pacman -S nix, assuming you have the community repos enabled. I don’t see offhand where Nix uninstallation is documented nowadays (), but for a single-user install, nuking /nix and removing any references to Nix from ~/.bashrc, ~/.zshrc, etc., should do it.
I just wanted to try it. I found some info about it which mention that is unic and easy to configure/install. But from my experience until now it’s not. So after I tried the suggestions and fail again I removed everything. Maybe I’ll try again the next days using arch’s repo to install nix, but I give up for now.
you could also use home-manager to recreate your setup since the syntax is the same for both configuration.nix and and home.nix. But be careful about what you do, i would recommend doing a backup of your dotfiles before attempting to change your home folder