astro / microvm.nix

NixOS MicroVMs
https://astro.github.io/microvm.nix/
MIT License
1.38k stars 101 forks source link

`gtk3` fails to build when included in vm closure #167

Closed samhug closed 11 months ago

samhug commented 11 months ago

I'm not sure this is an issue with microvm.nix but I figured I'd start here.

I'm getting an error building gtk3 when I include the package in a microvm, but when the gtk3 package is included in the host system it seems to build just fine.

flake.nix ```nix { inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; inputs.microvm-nix = { url = "github:astro/microvm.nix"; inputs.nixpkgs.follows = "nixpkgs"; }; outputs = { self, nixpkgs, microvm-nix, ... }: { nixosConfigurations.host = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = [ microvm-nix.nixosModules.host ({ pkgs, ... }: { boot.loader.systemd-boot.enable = true; fileSystems."/" = { device = "none"; fsType = "tmpfs"; }; microvm.vms."vm0".flake = self; # No problem when the host system depends on gtk3 environment.systemPackages = [ pkgs.gtk3 ]; }) ]; }; nixosConfigurations.vm0 = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = [ microvm-nix.nixosModules.microvm ({ pkgs, ... }: { # gtk3 fails to build when included in the VM closure environment.systemPackages = [ pkgs.gtk3 ]; }) ]; }; }; } ```
flake.lock ```json { "nodes": { "flake-utils": { "inputs": { "systems": "systems" }, "locked": { "lastModified": 1694529238, "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", "owner": "numtide", "repo": "flake-utils", "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", "type": "github" }, "original": { "owner": "numtide", "repo": "flake-utils", "type": "github" } }, "microvm-nix": { "inputs": { "flake-utils": "flake-utils", "nixpkgs": [ "nixpkgs" ] }, "locked": { "lastModified": 1702170787, "narHash": "sha256-qWCS4lNDiKSEpSvNloc2OD9p30LyEVrGLNxv8bBCscI=", "owner": "astro", "repo": "microvm.nix", "rev": "9e7b4c8e036b1958ef8ac2bc19c695c43910a2d7", "type": "github" }, "original": { "owner": "astro", "repo": "microvm.nix", "type": "github" } }, "nixpkgs": { "locked": { "lastModified": 1702151865, "narHash": "sha256-9VAt19t6yQa7pHZLDbil/QctAgVsA66DLnzdRGqDisg=", "owner": "NixOS", "repo": "nixpkgs", "rev": "666fc80e7b2afb570462423cb0e1cf1a3a34fedd", "type": "github" }, "original": { "owner": "NixOS", "ref": "nixos-unstable", "repo": "nixpkgs", "type": "github" } }, "root": { "inputs": { "microvm-nix": "microvm-nix", "nixpkgs": "nixpkgs" } }, "systems": { "locked": { "lastModified": 1681028828, "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", "owner": "nix-systems", "repo": "default", "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", "type": "github" }, "original": { "owner": "nix-systems", "repo": "default", "type": "github" } } }, "root": "root", "version": 7 } ```

Using the above flake.nix, and running the following command:

nix build .#nixosConfigurations.host.config.system.build.toplevel

I get this:

Build error ``` error: builder for '/nix/store/cwqganhag9y7qxv7y038j15wysrgsbpi-gtk+3-3.24.38.drv' failed with exit code 1; last 25 log lines: > Run-time dependency glib-2.0 found: YES 2.78.1 > Run-time dependency gobject-2.0 found: YES 2.78.1 > Run-time dependency gio-unix-2.0 found: YES 2.78.1 > Run-time dependency gmodule-2.0 found: YES 2.78.1 > Run-time dependency cairo found: YES 1.18.0 > Run-time dependency cairo-gobject found: YES 1.18.0 > Run-time dependency pango found: YES 1.51.0 > Run-time dependency fribidi found: YES 1.0.13 > Run-time dependency pangoft2 found: YES 1.51.0 > Run-time dependency freetype2 found: YES 26.1.20 > Run-time dependency pangocairo found: YES 1.51.0 > Run-time dependency gdk-pixbuf-2.0 found: YES 2.42.10 > Run-time dependency epoxy found: YES 1.5.10 > Run-time dependency atk found: YES 2.50.0 > Run-time dependency harfbuzz found: YES 7.3.0 > Run-time dependency xkbcommon found: YES 1.5.0 > Run-time dependency iso-codes found: YES 4.15.0 > Run-time dependency tracker-sparql-3.0 found: YES 3.6.0 > Did not find CMake 'cmake' > Found CMake: NO > Run-time dependency cairo-xlib found: NO (tried pkgconfig) > > meson.build:506:9: ERROR: Dependency "cairo-xlib" not found, tried pkgconfig > > A full log can be found at /build/gtk+-3.24.38/build/meson-logs/meson-log.txt For full logs, run 'nix log /nix/store/cwqganhag9y7qxv7y038j15wysrgsbpi-gtk+3-3.24.38.drv'. error: 1 dependencies of derivation '/nix/store/5zkz454rj2f3pz9jvndcb3inl2088wb6-system-path.drv' failed to build error: 1 dependencies of derivation '/nix/store/lm39c0ji2ygw7zr1zpg0gl5ajdmmm1ha-nixos-system-nixos-24.05.20231209.666fc80.drv' failed to build error (ignored): error: cannot unlink '/tmp/nix-build-qemu-host-cpu-only-for-vm-tests-8.1.3.drv-0/qemu-8.1.3/hw': Directory not empty error: 1 dependencies of derivation '/nix/store/l4pa9ficldk8cnnrfh3prw7rn1yxc4xh-X-Restart-Triggers-microvm-vm0.drv' failed to build error: 1 dependencies of derivation '/nix/store/j2c1hs475pgpdqz6jrvwhfhifw7ckss0-microvm-qemu-nixos.drv' failed to build error: 1 dependencies of derivation '/nix/store/ln88jl4sy7v2n3p7iy13i2y5cnhw3j4f-unit-microvm-vm0.service.drv' failed to build error: 1 dependencies of derivation '/nix/store/7vrjyqw2rhvpjb3mvkfc4v08iswq5xym-unit-script-install-microvm-vm0-start.drv' failed to build error: 1 dependencies of derivation '/nix/store/sc8zshqdk5kg92m853ngx2nkfpph7y2g-system-units.drv' failed to build error: 1 dependencies of derivation '/nix/store/rl1j9i4v5j4f6sxy3r1m1hf363my4dav-etc.drv' failed to build error: 1 dependencies of derivation '/nix/store/k1ahpdgb9jifik149wkbsq9avs6dl7hw-nixos-system-nixos-24.05.20231209.666fc80.drv' failed to build ```

If I comment out line 37, removing gtk3 from the VM closure:

  # environment.systemPackages = [ pkgs.gtk3 ];

The same command builds without error even though the gtk3 package is included in the host system closure still.

astro commented 11 months ago

We do environment.noXlibs = lib.mkDefault true in the optimizations. So, just set:

environment.noXlibs = false;

I know this could be frustrating for anyone who doesn't know about environment.noXlibs. This really should be fixed in upstream NixOS...

samhug commented 11 months ago

Thanks!

Avi-D-coder commented 10 months ago

The #qemu-vnc example does not build for me without setting environment.noXlibs = false;