flake: move VM to separate file
This simplifies the flake.
This commit is contained in:
parent
7233b054d9
commit
1e94e891b2
35
examples/qemu-vm/minimal-vm.nix
Normal file
35
examples/qemu-vm/minimal-vm.nix
Normal file
|
@ -0,0 +1,35 @@
|
|||
nix-bitcoin: pkgs: system:
|
||||
|
||||
rec {
|
||||
inherit (nix-bitcoin.inputs) nixpkgs;
|
||||
|
||||
mkVMScript = vm: pkgs.writers.writeBash "run-vm" ''
|
||||
set -euo pipefail
|
||||
export TMPDIR=$(mktemp -d /tmp/nix-bitcoin-vm.XXX)
|
||||
trap "rm -rf $TMPDIR" EXIT
|
||||
export NIX_DISK_IMAGE=$TMPDIR/nixos.qcow2
|
||||
QEMU_OPTS="-smp $(nproc) -m 1500" ${vm}/bin/run-*-vm
|
||||
'';
|
||||
|
||||
vm = (import "${nixpkgs}/nixos" {
|
||||
inherit system;
|
||||
configuration = {
|
||||
imports = [
|
||||
nix-bitcoin.nixosModules.default
|
||||
"${nix-bitcoin}/modules/presets/secure-node.nix"
|
||||
];
|
||||
|
||||
nix-bitcoin.generateSecrets = true;
|
||||
services.clightning.enable = true;
|
||||
# For faster startup in offline VMs
|
||||
services.clightning.extraConfig = "disable-dns";
|
||||
|
||||
nixpkgs.pkgs = pkgs;
|
||||
virtualisation.graphics = false;
|
||||
services.getty.autologinUser = "root";
|
||||
nix.nixPath = [ "nixpkgs=${nixpkgs}" ];
|
||||
};
|
||||
}).vm;
|
||||
|
||||
runVM = mkVMScript vm;
|
||||
}
|
40
flake.nix
40
flake.nix
|
@ -66,46 +66,16 @@
|
|||
} // (flake-utils.lib.eachSystem supportedSystems (system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
|
||||
nbPkgs = self.lib.mkNbPkgs { inherit system pkgs; };
|
||||
|
||||
mkVMScript = vm: pkgs.writers.writeBash "run-vm" ''
|
||||
set -euo pipefail
|
||||
export TMPDIR=$(mktemp -d /tmp/nix-bitcoin-vm.XXX)
|
||||
trap "rm -rf $TMPDIR" EXIT
|
||||
export NIX_DISK_IMAGE=$TMPDIR/nixos.qcow2
|
||||
QEMU_OPTS="-smp $(nproc) -m 1500" ${vm}/bin/run-*-vm
|
||||
'';
|
||||
in rec {
|
||||
packages = flake-utils.lib.flattenTree (removeAttrs nbPkgs [
|
||||
"pinned" "modulesPkgs" "nixops19_09" "krops" "generate-secrets" "netns-exec"
|
||||
]) // {
|
||||
runVM = mkVMScript packages.vm;
|
||||
|
||||
# This is a simple demo VM.
|
||||
# See ./examples/flakes/flake.nix on how to use nix-bitcoin with flakes.
|
||||
vm = let
|
||||
nix-bitcoin = self;
|
||||
in
|
||||
(import "${nixpkgs}/nixos" {
|
||||
inherit system;
|
||||
configuration = {
|
||||
imports = [
|
||||
nix-bitcoin.nixosModules.default
|
||||
"${nix-bitcoin}/modules/presets/secure-node.nix"
|
||||
];
|
||||
|
||||
nix-bitcoin.generateSecrets = true;
|
||||
services.clightning.enable = true;
|
||||
# For faster startup in offline VMs
|
||||
services.clightning.extraConfig = "disable-dns";
|
||||
|
||||
nixpkgs.pkgs = pkgs;
|
||||
virtualisation.graphics = false;
|
||||
services.getty.autologinUser = "root";
|
||||
nix.nixPath = [ "nixpkgs=${nixpkgs}" ];
|
||||
};
|
||||
}).vm;
|
||||
inherit (import ./examples/qemu-vm/minimal-vm.nix self pkgs system)
|
||||
# A simple demo VM.
|
||||
# See ./examples/flakes/flake.nix on how to use nix-bitcoin with flakes.
|
||||
runVM
|
||||
vm;
|
||||
};
|
||||
|
||||
# Allow accessing the whole nested `nbPkgs` attrset (including `modulesPkgs`)
|
||||
|
|
Loading…
Reference in New Issue
Block a user