nixos: add munix.defaultCommand option and system.build.munix

Add a NixOS option to configure the default command for the VM and
provide a system.build.munix output that wraps munix with the correct
toplevel and default command. This reduces boilerplate in downstream
flakes since they no longer need to manually wrap munix.

The template now uses these new features, significantly simplifying
the apps definition.
This commit is contained in:
Jörg Thalheim 2025-12-15 16:20:04 +01:00
parent 2d721419e6
commit ced0559be8
2 changed files with 317 additions and 275 deletions

View file

@ -19,14 +19,16 @@
...
}:
{
# First, define system configuration in a module:
nixosModules.musictest =
{ pkgs, ... }:
{
system.stateVersion = "26.05";
virtualisation.munix.defaultCommand = "euphonica";
programs.dconf.enable = true;
fonts.packages = with pkgs; [ adwaita-fonts ];
environment.systemPackages = with pkgs; [ euphonica ];
# Local background service as a demo that doesn't require network creds :)
services.mpd = {
enable = true;
@ -48,7 +50,6 @@
};
};
# And then define system closures per arch using the module above:
nixosConfigurations.musictest-aarch64 = nixpkgs.lib.nixosSystem {
system = "aarch64-linux";
modules = [
@ -66,31 +67,11 @@
apps.aarch64-linux.default = {
type = "app";
program = "${
nixpkgs.legacyPackages.aarch64-linux.symlinkJoin {
name = "munix";
paths = [ munix.packages.aarch64-linux.munix ];
buildInputs = [ nixpkgs.legacyPackages.aarch64-linux.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/munix --add-flags ${self.nixosConfigurations.musictest-aarch64.config.system.build.toplevel} --set MICROVM_DEFAULT_COMMAND euphonica
'';
}
}/bin/munix";
meta.description = "Run Music Demo App";
program = "${self.nixosConfigurations.musictest-aarch64.config.system.build.munix}/bin/munix";
};
apps.x86_64-linux.default = {
type = "app";
program = "${
nixpkgs.legacyPackages.x86_64-linux.symlinkJoin {
name = "munix";
paths = [ munix.packages.x86_64-linux.munix ];
buildInputs = [ nixpkgs.legacyPackages.x86_64-linux.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/munix --add-flags ${self.nixosConfigurations.musictest-x86_64.config.system.build.toplevel} --set MICROVM_DEFAULT_COMMAND euphonica
'';
}
}/bin/munix";
meta.description = "Run Music Demo App";
program = "${self.nixosConfigurations.musictest-x86_64.config.system.build.munix}/bin/munix";
};
};
}