Mic92/nixos-shell

The option virtualisation.* does not exist

Bert-Proesmans opened this issue · 4 comments

Hi, I'm fairly new to nixos so forgive me if the answer is obvious.

I have built a monorepo based on https://aldoborrero.com/posts/2023/01/15/setting-up-my-machines-nix-style/, basically flake-parts + mission-control + multiple nixos configurations.
I can run my nixos-configurations through nixos-shell just fine, but defining qemu config for port forwarding etc doesn't work.

The following works;

# flake.nix
{
inputs ={..}
outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ ./host.nix ];
};
}

# host.nix
{self, inputs, lib, ...}:
{
flake.nixosConfiguration = {
machine = lib.nixosSystem {
modules = [ .. ];
};
};
}

nixos-shell --flake .#machine builds and runs the configuration as expected.

What doesn't work is adding qemu config to the machine attribute set, also creating a new machine with additional qemu config doesn't work either;

# host.nix
{self, inputs, lib, ...}:
{
flake.nixosConfiguration = {
machine = lib.nixosSystem {
modules = [ .. ];
};
# Below attribute is added to keep the nixos-shell specific settings separated from the machine config
vm-machine = lib.nixosSystem {
modules = [ .. ] ++ [({...}: {
virtualisation.forwardPorts = [{from = "host"; host.port = 6667; guest.port = 67;}];
})];
};
};
}

nixos-shell --flake .#vm-machine fails. I'm not sure at which build step exactly, but I do understand that the nixos module for qemu should be included (because of /share/modules/nixos-shell.nix) but isn't.
I guess it has to do something with lib and the way flake-parts abstracts some attributes away, but I'm coming up blank on fixing this properly.

The error message

error: The option `virtualisation.forwardPorts' does not exist. Definition values:
       - In `/nix/store/6kp2ql3nww07p270y2qfjpl4habskbkb-source/flake.nix':
           [
             {
               from = "host";
               guest = {
                 port = 67;
           ...
(use '--show-trace' to show detailed location information)

I'm not sure how to pass --show-trace into the process to get more detailed information out.

I should note that I haven't done any of the module argument injections that the author of the article shows. I'm not fully understanding why he does that and I'm trying to get as far as possible without.
My code has basic nix and basic flake-parts usage.

so, every example I've seen uses explicitly

flake.nixosConfiguration = {
machine = inputs.nixpkgs.lib.nixosSystem { .. }
}

Note that nixosSystem comes from the set hierarchy nixpkgs.lib. And that works! I don't understand why.

I lack some understanding on properly passing and handling lib, my interpretation is that lib is only augmented onto like default nixos.
But it looks like the specific definition layer of lib is important depending on the attribute? Closer in similarity to overlays and forking.
I'm not sure what flake-parts does to the lib passed down into flake modules. Understanding the source is hard. But I do understand the upsides of the library, this barrier to my understanding drives me nuts.

Wait no, I messed up. It's still not working as expected.

I fixed this by reimplementing nixos-shell in my flake using the nixos modules from the nixos-shell flake, also a twoliner script.