nix-bitcoin/examples/qemu-vm/minimal-vm.nix
Erik Arvstedt f946a7cd9b
examples: use mkDefault for setting system.stateVersion
This makes it easier for users to override the default.
2022-07-08 15:10:03 +02:00

54 lines
1.5 KiB
Nix

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 = { config, lib, modulesPath, ... }: {
imports = [
nix-bitcoin.nixosModules.default
"${nix-bitcoin}/modules/presets/secure-node.nix"
"${modulesPath}/virtualisation/qemu-vm.nix"
];
virtualisation.graphics = false;
nix-bitcoin.generateSecrets = true;
services.clightning.enable = true;
# For faster startup in offline VMs
services.clightning.extraConfig = "disable-dns";
nixpkgs.pkgs = pkgs;
services.getty.autologinUser = "root";
nix.nixPath = [ "nixpkgs=${nixpkgs}" ];
services.getty.helpLine = lib.mkAfter ''
Welcome to nix-bitcoin!
To explore running services, try the following commands:
- nodeinfo
- systemctl status bitcoind
- systemctl status clightning
'';
# Power off VM when the user exits the shell
systemd.services."serial-getty@".preStop = ''
echo o >/proc/sysrq-trigger
'';
system.stateVersion = lib.mkDefault config.system.nixos.release;
};
}).config.system.build.vm;
runVM = mkVMScript vm;
}