Giter Site home page Giter Site logo

Improve `flk vm` (bash script) about bud HOT 14 CLOSED

divnix avatar divnix commented on August 19, 2024 1
Improve `flk vm` (bash script)

from bud.

Comments (14)

zimbatm avatar zimbatm commented on August 19, 2024 1

looks good, I like how simple the script is

from bud.

blaggacao avatar blaggacao commented on August 19, 2024 1

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."

from bud.

Narice avatar Narice commented on August 19, 2024 1

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.

from bud.

Narice avatar Narice commented on August 19, 2024 1

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

from bud.

blaggacao avatar blaggacao commented on August 19, 2024

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 😉

from bud.

Narice avatar Narice commented on August 19, 2024

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?

from bud.

Narice avatar Narice commented on August 19, 2024

@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!

from bud.

Narice avatar Narice commented on August 19, 2024

This seems to be relevant:
https://github.com/NixOS/nixpkgs/blob/690496c4e545e68482b5c162a03f0a4f97d35373/nixos/default.nix#L12-L43

from bud.

blaggacao avatar blaggacao commented on August 19, 2024

I guess it's:

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

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

from bud.

Narice avatar Narice commented on August 19, 2024

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.

from bud.

Narice avatar Narice commented on August 19, 2024

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

from bud.

Narice avatar Narice commented on August 19, 2024

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!

from bud.

blaggacao avatar blaggacao commented on August 19, 2024

@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?

from bud.

Narice avatar Narice commented on August 19, 2024

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

from bud.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.