Oracle Cloud free tier, kexec, 'nixpkgs/nixos' was not found in the Nix search path

I have trying to install Nixos on an Oracle Cloud free tier instance using the kexec method. I have created an Ubuntu 22.04 instance on the following shape:

Shape: VM.Standard.A1.Flex (aarch64)

OCPU count: 2

Network bandwidth (Gbps): 2

Memory (GB): 12

Local disk: Block storage only

I have taken the following steps:

sh <(curl -L https://nixos.org/nix/install) --daemon

tee kexec.nix << "EOF"
{ config, pkgs, ... }:
{
  imports = [
    # this will work only under qemu, uncomment next line for full image
    # <nixpkgs/nixos/modules/installer/netboot/netboot-minimal.nix>
    <nixpkgs/nixos/modules/installer/netboot/netboot.nix>
    <nixpkgs/nixos/modules/profiles/qemu-guest.nix>
  ];

  # stripped down version of https://github.com/cleverca22/nix-tests/tree/master/kexec
  system.build = rec {
    image = pkgs.runCommand "image" { buildInputs = [ pkgs.nukeReferences ]; } ''
      mkdir $out
      cp ${config.system.build.kernel}/${config.system.boot.loader.kernelFile} $out/kernel
      cp ${config.system.build.netbootRamdisk}/initrd $out/initrd
      nuke-refs $out/kernel
    '';
    kexec_script = pkgs.writeTextFile {
      executable = true;
      name = "kexec-nixos";
      text = ''
        #!${pkgs.stdenv.shell}
        set -e
        ${pkgs.kexectools}/bin/kexec -l ${image}/kernel --initrd=${image}/initrd --append="init=${builtins.unsafeDiscardStringContext config.system.build.toplevel}/init ${toString config.boot.kernelParams}"
        sync
        echo "executing kernel, filesystems will be improperly umounted"
        ${pkgs.kexectools}/bin/kexec -e
      '';
    };
    kexec_tarball = pkgs.callPackage <nixpkgs/nixos/lib/make-system-tarball.nix> {
      storeContents = [
        {
          object = config.system.build.kexec_script;
          symlink = "/kexec_nixos";
        }
      ];
      contents = [ ];
      compressCommand = "cat";
      compressionExtension = "";
    };
    kexec_tarball_self_extract_script = pkgs.writeTextFile {
      executable = true;
      name = "kexec-nixos";
      text = ''
        #!/bin/sh
        set -eu
        ARCHIVE=`awk '/^__ARCHIVE_BELOW__/ { print NR + 1; exit 0; }' $0`
        tail -n+$ARCHIVE $0 | tar x -C /
        /kexec_nixos $@
        exit 1
        __ARCHIVE_BELOW__
      '';
    };
    kexec_bundle = pkgs.runCommand "kexec_bundle" { } ''
      cat \
        ${kexec_tarball_self_extract_script} \
        ${kexec_tarball}/tarball/nixos-system-${kexec_tarball.system}.tar \
        > $out
      chmod +x $out
    '';
  };

  boot.initrd.availableKernelModules = [ "ata_piix" "uhci_hcd" ];
  boot.kernelParams = [
    "panic=30" "boot.panic_on_fail" # reboot the machine upon fatal boot issues
    "console=ttyS0" # enable serial console
    "console=tty1"
  ];
  boot.kernel.sysctl."vm.overcommit_memory" = "1";

  environment.systemPackages = with pkgs; [ cryptsetup btrfs-progs ];
  environment.variables.GC_INITIAL_HEAP_SIZE = "1M";

  networking.hostName = "kexec";

  services.getty.autologinUser = "root";
  services.openssh = {
    enable = true;
    kbdInteractiveAuthentication = false;
    passwordAuthentication = false;
  };

  documentation.enable = false;
  documentation.nixos.enable = false;
  fonts.fontconfig.enable = false;
  programs.bash.enableCompletion = false;
  programs.command-not-found.enable = false;
  security.polkit.enable = false;
  security.rtkit.enable = pkgs.lib.mkForce false;
  services.udisks2.enable = false;
  i18n.supportedLocales = [ (config.i18n.defaultLocale + "/UTF-8") ];

  users.users.root.openssh.authorizedKeys.keys = [
    # add your ssh key here
    "ssh-rsa  ***"
  ];
  
  system.stateVersion = "22.05";
  
}
EOF

nix-build '<nixpkgs/nixos>' -A config.system.build.kexec_tarball -I nixos-config=./kexec.nix

cd /tmp && sudo tar xf /home/ubuntu/result/tarball/nixos-system-aarch64-linux.tar && sudo ./kexec_nixos

ssh root@somehost

I can ssh in, partition the disk, and generate config with no problems. The issues come when I try to do a nixos-install.

[root@kexec:~]# nixos-install --no-root-passwd
building the configuration in /mnt/etc/nixos/configuration.nix...
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixos' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
error: file 'nixpkgs/nixos' was not found in the Nix search path (add it using $NIX_PATH or -I)

[root@kexec:~]# $NIX_PATH
-bash: nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels: No such file or directory

[root@kexec:~]# ls -l /nix/var/nix/profiles/per-user/root/
total 0

I have not been able to resolve this issue, and Googling has not gotten me anywhere. Anyone has a suggestion?

Also, I am a where of the NixOS-Infect script. This works, but it has an issue with Oracle Cloud in that the boot partition is too small, and soon you will not be able to do an update. guide: formatting oracle cloud boot volumes as btrfs · Issue #94 · elitak/nixos-infect · GitHub

Thank you for your help

@Smithoo4 I’m not sure why this isn’t working for you, but have you tried running nix-channel --add https://nixos.org/channels/nixos-22.05 nixos and/or nix-channel --update? Maybe the channels just need to be bootstrapped for some reason.

You can use this script to kexec NixOS directly.
Then, modify this install script to satisfy your needs.

It seems that your config is not flake format

@noah that is a good point and one I thought I had already tried. I tried it again just in case and to record any errors, and sure enough it worked. It probably worked to just make me look bad.

Thank you

1 Like

@mlyxshi interesting, I will have to give it a try next time I want to do an install.

Thank you