Mic92 / nixos-shell

Spawns lightweight nixos vms in a shell
MIT License
642 stars 37 forks source link

virtualisation.msize error #52

Closed 573 closed 2 years ago

573 commented 2 years ago
error: The option `virtualisation.msize' defined in `<unknown-file>' does not exist.
Mic92 commented 2 years ago

Not sure what is going wrong on your device. This option definitely exists on 21.11: https://github.com/NixOS/nixpkgs/blob/17ee68bc368e175369258b97316328d6bca11d3b/nixos/modules/virtualisation/qemu-vm.nix#L306

573 commented 2 years ago

I did as described in https://github.com/Mic92/nixos-shell#channelsnix_path

Then started nixos-shell as in

NIX_PATH=nixpkgs=channel:nixos-19.09-small make test

Reason:

/nix/store/qcsabcswq1sswl20nrnyi1i14zx24sp4-nixos-shell/bin/nixos-shell examples/vm.nix /nix/store/y5kvyby13kv6li8c1zaagmx0i651in9g-nixos-vm Could not access KVM kernel module: No such file or directory qemu-system-aarch64: failed to initialize kvm: No such file or directory

I want to circumvent this error by using the old channel. Does not seem to use the channel though.

573 commented 2 years ago

With kvm disabled and 21.11 channel I got the same error message.

Mic92 commented 2 years ago

the virtualisation module in nixos uses qemu-kvm by default: https://github.com/NixOS/nixpkgs/blob/17ee68bc368e175369258b97316328d6bca11d3b/nixos/modules/virtualisation/qemu-vm.nix#L563 You would need to disable that if you want to use on a platform without kvm support.

Mic92 commented 2 years ago

https://github.com/NixOS/nixpkgs/blob/master/nixos/lib/qemu-common.nix#L24

573 commented 2 years ago
diff --git a/examples/vm.nix b/examples/vm.nix
index 54480b8..9751765 100644
--- a/examples/vm.nix
+++ b/examples/vm.nix
@@ -1,4 +1,8 @@
 { pkgs, ... }: {
+  virtualisation.qemu = {
+    package = pkgs.qemu;
+    options = [ "-cpu max" ];
+  };
   boot.kernelPackages = pkgs.linuxPackages_latest;
   services.openssh.enable = true;
 }

The error persists.

573 commented 2 years ago

I'd have to replace the options differently I guess as they seem to not get picked up.

Mic92 commented 2 years ago

aarch64 seems to pass -enable-kvm regardless: https://github.com/NixOS/nixpkgs/blob/master/nixos/lib/qemu-common.nix#L27 This is a limitation that needs to be fixed in nixpkgs itself. It cannot be fixed in nixos-shell.

573 commented 2 years ago

qemu-common-patched.nix:

aarch64-linux = "${qemuPkg}/bin/qemu-system-aarch64 -machine virt -cpu max";

changes in local copies of the files you linked, qemu-vm.nix importing the locally patched copy allow me to boot nixos-shell on https://github.com/t184256/nix-on-droid

NIXOS_EXTRA_MODULE_PATH=~/nixos-shell/qemu-vm.nix NIX_PATH=nixpkgs=file:///data/data/com.termux.nix/files/home/nixexprs.tar.xz nix-shell -p gnumake --run "bin/nixos-shell -v --show-trace examples/vm.nix"
diff --git a/examples/vm.nix b/examples/vm.nix
index 54480b8..d37f371 100644
--- a/examples/vm.nix
+++ b/examples/vm.nix
@@ -1,4 +1,11 @@
 { pkgs, ... }: {
   boot.kernelPackages = pkgs.linuxPackages_latest;
   services.openssh.enable = true;
+  nixos-shell = {
+    mounts = {
+      mountHome = false;
+      mountNixProfile = false;
+      cache = "none"; # default is "loose"
+    };
+  };
 }
diff --git a/share/modules/nixos-shell.nix b/share/modules/nixos-shell.nix
index c0fec7a..e55365f 100644
--- a/share/modules/nixos-shell.nix
+++ b/share/modules/nixos-shell.nix
@@ -1,7 +1,7 @@
 { lib, options, pkgs, modulesPath, ... }:

 {
-  imports = [
+  disabledModules = [
     "${toString modulesPath}/virtualisation/qemu-vm.nix"
   ];