2022-06-01 19:31:33 +00:00
|
|
|
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)
|
2022-08-08 12:57:19 +00:00
|
|
|
trap 'rm -rf $TMPDIR' EXIT
|
2022-06-01 19:31:33 +00:00
|
|
|
export NIX_DISK_IMAGE=$TMPDIR/nixos.qcow2
|
2022-08-08 12:57:19 +00:00
|
|
|
|
|
|
|
# shellcheck disable=SC2211
|
2022-06-01 19:31:33 +00:00
|
|
|
QEMU_OPTS="-smp $(nproc) -m 1500" ${vm}/bin/run-*-vm
|
|
|
|
'';
|
|
|
|
|
2022-10-22 17:37:47 +00:00
|
|
|
vm = (import (nixpkgs + "/nixos") {
|
2022-06-01 19:31:33 +00:00
|
|
|
inherit system;
|
2022-06-27 22:08:28 +00:00
|
|
|
configuration = { config, lib, modulesPath, ... }: {
|
2022-06-01 19:31:33 +00:00
|
|
|
imports = [
|
|
|
|
nix-bitcoin.nixosModules.default
|
2022-10-22 17:37:47 +00:00
|
|
|
(nix-bitcoin + "/modules/presets/secure-node.nix")
|
|
|
|
(modulesPath + "/virtualisation/qemu-vm.nix")
|
2022-06-01 19:31:33 +00:00
|
|
|
];
|
|
|
|
|
2022-06-27 22:08:28 +00:00
|
|
|
virtualisation.graphics = false;
|
|
|
|
|
2022-06-01 19:31:33 +00:00
|
|
|
nix-bitcoin.generateSecrets = true;
|
|
|
|
services.clightning.enable = true;
|
|
|
|
# For faster startup in offline VMs
|
|
|
|
services.clightning.extraConfig = "disable-dns";
|
|
|
|
|
2022-10-22 17:37:45 +00:00
|
|
|
# Avoid lengthy build of the nixos manual
|
|
|
|
documentation.nixos.enable = false;
|
|
|
|
|
2022-06-01 19:31:33 +00:00
|
|
|
nixpkgs.pkgs = pkgs;
|
|
|
|
services.getty.autologinUser = "root";
|
|
|
|
nix.nixPath = [ "nixpkgs=${nixpkgs}" ];
|
2022-06-01 19:35:50 +00:00
|
|
|
|
|
|
|
services.getty.helpLine = lib.mkAfter ''
|
|
|
|
|
|
|
|
Welcome to nix-bitcoin!
|
|
|
|
To explore running services, try the following commands:
|
|
|
|
- nodeinfo
|
|
|
|
- systemctl status bitcoind
|
|
|
|
- systemctl status clightning
|
2022-11-02 16:40:44 +00:00
|
|
|
- lightning-cli getinfo
|
2022-06-01 19:35:50 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
# Power off VM when the user exits the shell
|
|
|
|
systemd.services."serial-getty@".preStop = ''
|
|
|
|
echo o >/proc/sysrq-trigger
|
|
|
|
'';
|
2022-06-27 22:08:28 +00:00
|
|
|
|
2022-07-05 10:19:01 +00:00
|
|
|
system.stateVersion = lib.mkDefault config.system.nixos.release;
|
2022-06-01 19:31:33 +00:00
|
|
|
};
|
2022-06-27 22:08:28 +00:00
|
|
|
}).config.system.build.vm;
|
2022-06-01 19:31:33 +00:00
|
|
|
|
|
|
|
runVM = mkVMScript vm;
|
|
|
|
}
|