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;
|
||||||
|
}
|
38
flake.nix
38
flake.nix
@ -66,46 +66,16 @@
|
|||||||
} // (flake-utils.lib.eachSystem supportedSystems (system:
|
} // (flake-utils.lib.eachSystem supportedSystems (system:
|
||||||
let
|
let
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
|
||||||
nbPkgs = self.lib.mkNbPkgs { inherit system pkgs; };
|
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 {
|
in rec {
|
||||||
packages = flake-utils.lib.flattenTree (removeAttrs nbPkgs [
|
packages = flake-utils.lib.flattenTree (removeAttrs nbPkgs [
|
||||||
"pinned" "modulesPkgs" "nixops19_09" "krops" "generate-secrets" "netns-exec"
|
"pinned" "modulesPkgs" "nixops19_09" "krops" "generate-secrets" "netns-exec"
|
||||||
]) // {
|
]) // {
|
||||||
runVM = mkVMScript packages.vm;
|
inherit (import ./examples/qemu-vm/minimal-vm.nix self pkgs system)
|
||||||
|
# A simple demo VM.
|
||||||
# This is a simple demo VM.
|
|
||||||
# See ./examples/flakes/flake.nix on how to use nix-bitcoin with flakes.
|
# See ./examples/flakes/flake.nix on how to use nix-bitcoin with flakes.
|
||||||
vm = let
|
runVM
|
||||||
nix-bitcoin = self;
|
vm;
|
||||||
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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
# Allow accessing the whole nested `nbPkgs` attrset (including `modulesPkgs`)
|
# Allow accessing the whole nested `nbPkgs` attrset (including `modulesPkgs`)
|
||||||
|
Loading…
Reference in New Issue
Block a user