readme: move example to flake template
Replace inline flake.nix example with a proper flake template that users can instantiate with `nix flake init`. This makes it easier to get started and we can easier test the example.
This commit is contained in:
parent
fb53769c7a
commit
2d721419e6
3 changed files with 148 additions and 104 deletions
89
README.md
89
README.md
|
|
@ -23,91 +23,16 @@ nix run '.#munix' -- testvm fastfetch
|
|||
|
||||
**Create a custom VM:**
|
||||
|
||||
Create a `flake.nix` in a new directory using this flake as an input providing the necessary NixOS module:
|
||||
Use the template to bootstrap a new munix project:
|
||||
|
||||
```nix
|
||||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
munix.url = "git+https://git.clan.lol/clan/munix?shallow=1&ref=main";
|
||||
munix.inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, munix, ... }: {
|
||||
# First, define system configuration in a module:
|
||||
nixosModules.musictest = { pkgs, ... }: {
|
||||
system.stateVersion = "26.05";
|
||||
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";
|
||||
};
|
||||
};
|
||||
|
||||
# And then define system closures per arch using the module above:
|
||||
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 = "${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";
|
||||
};
|
||||
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";
|
||||
};
|
||||
};
|
||||
}
|
||||
```bash
|
||||
mkdir my-vm && cd my-vm
|
||||
nix flake init -t 'git+https://git.clan.lol/clan/munix#musictest'
|
||||
git init && git add flake.nix
|
||||
nix run
|
||||
```
|
||||
|
||||
And `nix run`!
|
||||
|
||||
(TODO: helpers will be provided to reduce the necessary boilerplate)
|
||||
This creates a `flake.nix` with a music player demo (MPD + Euphonica). Edit the module to customize your VM.
|
||||
|
||||
## munix Options
|
||||
|
||||
|
|
|
|||
67
flake.nix
67
flake.nix
|
|
@ -27,34 +27,56 @@
|
|||
};
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, virtwl, sidebus, muvm-src, libkrun-src, libkrunfw-src, ... }: {
|
||||
nixosModules.testvm = nixpkgs.lib.modules.importApply ./nixosModules/testvm.nix { inherit virtwl; };
|
||||
nixosModules.default = nixpkgs.lib.modules.importApply ./nixosModules/default.nix { inherit self virtwl sidebus; };
|
||||
outputs =
|
||||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
flake-utils,
|
||||
virtwl,
|
||||
sidebus,
|
||||
muvm-src,
|
||||
libkrun-src,
|
||||
libkrunfw-src,
|
||||
...
|
||||
}:
|
||||
{
|
||||
nixosModules.testvm = nixpkgs.lib.modules.importApply ./nixosModules/testvm.nix { inherit virtwl; };
|
||||
nixosModules.default = nixpkgs.lib.modules.importApply ./nixosModules/default.nix {
|
||||
inherit self virtwl sidebus;
|
||||
};
|
||||
|
||||
nixosConfigurations.testvm-x86_64 = nixpkgs.lib.nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
modules = [
|
||||
self.nixosModules.default
|
||||
self.nixosModules.testvm
|
||||
{ nixpkgs.config.allowUnfree = true; }
|
||||
];
|
||||
};
|
||||
templates.musictest = {
|
||||
description = "Music player demo VM with MPD and Euphonica";
|
||||
path = ./templates/musictest;
|
||||
};
|
||||
|
||||
nixosConfigurations.testvm-aarch64 = nixpkgs.lib.nixosSystem {
|
||||
system = "aarch64-linux";
|
||||
modules = [
|
||||
self.nixosModules.default
|
||||
self.nixosModules.testvm
|
||||
{ nixpkgs.config.allowUnfree = true; }
|
||||
];
|
||||
};
|
||||
} // flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" ] (system:
|
||||
nixosConfigurations.testvm-x86_64 = nixpkgs.lib.nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
modules = [
|
||||
self.nixosModules.default
|
||||
self.nixosModules.testvm
|
||||
{ nixpkgs.config.allowUnfree = true; }
|
||||
];
|
||||
};
|
||||
|
||||
nixosConfigurations.testvm-aarch64 = nixpkgs.lib.nixosSystem {
|
||||
system = "aarch64-linux";
|
||||
modules = [
|
||||
self.nixosModules.default
|
||||
self.nixosModules.testvm
|
||||
{ nixpkgs.config.allowUnfree = true; }
|
||||
];
|
||||
};
|
||||
}
|
||||
// flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" ] (
|
||||
system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
config.allowUnfree = true;
|
||||
};
|
||||
in {
|
||||
in
|
||||
{
|
||||
|
||||
checks =
|
||||
(pkgs.lib.mapAttrs' (n: pkgs.lib.nameValuePair "package-${n}") self.packages.${system})
|
||||
|
|
@ -99,5 +121,6 @@
|
|||
muvm = self.packages.${system}.muvm;
|
||||
sidebus-broker = sidebus.packages.${system}.sidebus-broker;
|
||||
};
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
96
templates/musictest/flake.nix
Normal file
96
templates/musictest/flake.nix
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
{
|
||||
nixConfig = {
|
||||
extra-substituters = [ "https://cache.clan.lol" ];
|
||||
extra-trusted-public-keys = [
|
||||
"cache.clan.lol-1:3KztgSAB5R1M+Dz7vzkBGzXdodizbgLXGXKXlcQLA28="
|
||||
];
|
||||
};
|
||||
|
||||
inputs = {
|
||||
munix.url = "git+https://git.clan.lol/clan/munix?shallow=1&ref=main";
|
||||
nixpkgs.follows = "munix/nixpkgs";
|
||||
};
|
||||
|
||||
outputs =
|
||||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
munix,
|
||||
...
|
||||
}:
|
||||
{
|
||||
# First, define system configuration in a module:
|
||||
nixosModules.musictest =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
system.stateVersion = "26.05";
|
||||
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";
|
||||
};
|
||||
};
|
||||
|
||||
# And then define system closures per arch using the module above:
|
||||
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 = "${
|
||||
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";
|
||||
};
|
||||
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";
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue