Skip to content
This repository has been archived by the owner on Dec 18, 2022. It is now read-only.

Improve flk vm (bash script) #9

Closed
5 tasks
nova-nowiz opened this issue Jun 3, 2021 · 14 comments
Closed
5 tasks

Improve flk vm (bash script) #9

nova-nowiz opened this issue Jun 3, 2021 · 14 comments

Comments

@nova-nowiz
Copy link

This is a tracking issue for incremental change propositions that were brought up in pull request divnix/digga#41.

Here are the different possible changes that were brought up:

  • Making error messages for each step of the vm / vm run process
  • Making the documentation for vm a one liner (or a help menu could be created for the vm subcommand)
  • For the vm script and one-shot vm, getting the nix store path created from the nix build instead of making a link to it
  • The user should be able to choose the ram and cpu limit of the vm
  • The user should be able to choose if he wants to build the vm with the bootloader of not
@blaggacao
Copy link
Collaborator

blaggacao commented Jun 4, 2021

Maybe we could ask @zimbatm for a friendly review of https://github.com/divnix/digga/blob/develop/src/pkgs-lib/shell/flk.sh.

zimbatm by definition (with devshell) counts as family member, I guess 😉

@blaggacao blaggacao changed the title Improve flk vm Improve flk vm (shell script) Jun 4, 2021
@blaggacao blaggacao changed the title Improve flk vm (shell script) Improve flk vm (bash script) Jun 4, 2021
@zimbatm
Copy link

zimbatm commented Jun 4, 2021

looks good, I like how simple the script is

@nova-nowiz
Copy link
Author

We should also be able to choose how much resources we put for the vm, now it is static (I didn't check how much memory and cpu there is but I think not much). It makes it unusable to test out a plasma based setup :/
I'm going to add that to the tracking comment. Do you happen to know if there is something I can do to specify the ram and number of threads as of now?

@blaggacao
Copy link
Collaborator

blaggacao commented Jun 6, 2021

I happen to do a refactoring of the testing framwork in nixpkgs and as a result am currently familiar with the qemu instrumentation.

The thing you could have a look at is startVM.

At the end it receives a QEMU_OPTIONS env var and even $@.

A couple of lines back, cores and memory are already defined, so I'd hope later flags would peacefully override them. (Hoping only)

If my hope is in vain, I'd argue that this might be something that needs to be addressed upstream (it doesn't appear to be an exotic use case to run a vm with different ram settings during runtime).

So we could run the vm with something ./start-script -m 1024.

If that dynamic is not needed it might suffice to put config.virtualisation.memorySize / config.virtualisation.cores in the host config (but without enabling virtualization itself). Like saying: "if this where to be a VM, it needs so much resources."

@nova-nowiz
Copy link
Author

Thanks for the help @blaggacao!
Here is the script I have made to launch the one-shot vm with a custom memory size and cpu count:

#!/usr/bin/env bash
set -euo pipefail

export QEMU_OPTS="-m 4G -smp 8"

../devos/digga/src/pkgs-lib/shell/flk.sh vm run NixOS

the last line is because I am using my local develop digga repository so that I have flk vm run.

For reference in case someone stumbles upon this issue later, here is a script that should work for anyone on devos if put at the root of devos and if the flk vm run command is present:

#!/usr/bin/env bash
set -euo pipefail

export QEMU_OPTS="-m 4G -smp 8" # Here you change the memory (-m) and the number of cores (-smp)

flk vm run NixOS # Here you change the HOST you want to run

These options could most probably be added to the vm run command.

@nova-nowiz
Copy link
Author

also one can add -vga virtio to the QEMU_OPTS to have a way better resolution for the machine, I highly recommend it!

@nova-nowiz
Copy link
Author

@blaggacao my method is not enough and I happen to notice that in the file you linked, there are some options:
https://github.com/NixOS/nixpkgs/blob/690496c4e545e68482b5c162a03f0a4f97d35373/nixos/modules/virtualisation/qemu-vm.nix#L267
however, where can I set them?
If we answer this question, there would be no need for a bash script and the user would be able to set it in their config directly which would be awesome!

@nova-nowiz
Copy link
Author

@blaggacao
Copy link
Collaborator

blaggacao commented Jun 7, 2021

I guess it's:

{
    config.virtualization = {
        memorySize = 1024;
        cores = 4;
    };
}

Didn't find from my cel phone where those options are defined.

@nova-nowiz
Copy link
Author

I went to the manual and saw this:
image
I'm going to try and set them in my core profile and see if it has any effect, it would be rather strange if it works as these options are not findable in the option search site. if it works I will probably file an issue about it.

@nova-nowiz
Copy link
Author

well no it's not as simple as to put it in the config of the host 🤔
that is really strange, I'll make an issue on nixpkgs and see

@nova-nowiz
Copy link
Author

Well, it is actually possible to use the options as is but you have to check if you are in a vm or not, that was the missing thing!

  virtualisation = {
    kvmgt.enable = true;
    libvirtd.enable = true;
    docker.enable = true;
  } //
  (lib.optionalAttrs (builtins.hasAttr "qemu" options.virtualisation) {
    memorySize = 16 * 1024;
    msize = 16 * 1024;
    cores = 8;
    qemu = {
      options = [ "-vga virtio" ];
    };
  });

so here I set my normal virtualisation options for my host and if we are in a vm, then some other options are added on top.
for reference if someone stumbles upon this while searching on the net, here are the options:
https://github.com/NixOS/nixpkgs/blob/fcc1f7752ed71b0c94e5bf70e0a9c964a41073c7/nixos/modules/virtualisation/qemu-vm.nix#L267-L538
this should be way easier to do indeed. having something in digga to help the user setup these options would be awesome!

@blaggacao blaggacao transferred this issue from another repository Jul 4, 2021
@blaggacao
Copy link
Collaborator

blaggacao commented Oct 10, 2021

@Narice Do we still want to pursue this or could we close it in the meanwhile and re-open once the underlaying need regains momentum?

@nova-nowiz
Copy link
Author

Yes if someone has an issue with the current implementation, they should open an issue ;)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants