From 1d864e0dedde3e920ca8b1544155d53864ca3f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Mon, 15 Dec 2025 16:48:58 +0100 Subject: [PATCH] template: simplify with forAllSystems and inline module Use the forAllSystems pattern to reduce duplication and inline the NixOS module directly in nixosSystem call. This eliminates the need for separate nixosModules and nixosConfigurations outputs, making the template more concise and easier to understand. Also use virtualisation.munix namespace for the option. --- templates/musictest/flake.nix | 98 ++++++++++++++++------------------- 1 file changed, 46 insertions(+), 52 deletions(-) diff --git a/templates/musictest/flake.nix b/templates/musictest/flake.nix index 4178615..a2c7759 100644 --- a/templates/musictest/flake.nix +++ b/templates/musictest/flake.nix @@ -13,65 +13,59 @@ outputs = { - self, nixpkgs, munix, ... }: - { - nixosModules.musictest = - { pkgs, ... }: - { - system.stateVersion = "26.05"; - virtualisation.munix.defaultCommand = "euphonica"; + let + forAllSystems = nixpkgs.lib.genAttrs [ + "x86_64-linux" + "aarch64-linux" + ]; + musictest-vm = + system: + nixpkgs.lib.nixosSystem { + modules = [ + munix.nixosModules.default + ( + { pkgs, ... }: + { + system.stateVersion = "26.05"; + virtualisation.munix.defaultCommand = "euphonica"; - programs.dconf.enable = true; - fonts.packages = with pkgs; [ adwaita-fonts ]; - environment.systemPackages = with pkgs; [ euphonica ]; + nixpkgs.hostPlatform = system; - # Local background service as a demo that doesn't require network creds :) - services.mpd = { - enable = true; - startWhenNeeded = true; - musicDirectory = "/etc/demo-music"; - user = "appvm"; - group = "appvm"; - extraConfig = '' - audio_output { - type "pipewire" - name "Pipewire Output" + 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; + startWhenNeeded = true; + musicDirectory = "/etc/demo-music"; + user = "appvm"; + group = "appvm"; + extraConfig = '' + audio_output { + type "pipewire" + name "Pipewire Output" + } + ''; + }; + environment.etc."demo-music/0101GhostsI.ogg".source = pkgs.fetchurl { + # just a CC-BY-SA licensed example + url = "https://archive.org/download/NineInchNailsGhostsI-Iv24bit48khz/0101GhostsI.ogg"; + sha256 = "0iijm1c191aqkxybl4a4gvlpnf72hk4896lwvp0xixkhds88qzxi"; + }; } - ''; - }; - environment.etc."demo-music/0101GhostsI.ogg".source = pkgs.fetchurl { - # just a CC-BY-SA licensed example - url = "https://archive.org/download/NineInchNailsGhostsI-Iv24bit48khz/0101GhostsI.ogg"; - sha256 = "0iijm1c191aqkxybl4a4gvlpnf72hk4896lwvp0xixkhds88qzxi"; - }; + ) + ]; }; - - nixosConfigurations.musictest-aarch64 = nixpkgs.lib.nixosSystem { - system = "aarch64-linux"; - modules = [ - munix.nixosModules.default - self.nixosModules.musictest - ]; - }; - nixosConfigurations.musictest-x86_64 = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ - munix.nixosModules.default - self.nixosModules.musictest - ]; - }; - - apps.aarch64-linux.default = { - type = "app"; - program = "${self.nixosConfigurations.musictest-aarch64.config.system.build.munix}/bin/munix"; - }; - apps.x86_64-linux.default = { - type = "app"; - program = "${self.nixosConfigurations.musictest-x86_64.config.system.build.munix}/bin/munix"; - }; + in + { + packages = forAllSystems (system: { + default = (musictest-vm system).config.system.build.munix; + }); }; }