flake: move VM to separate file

This simplifies the flake.
This commit is contained in:
Erik Arvstedt 2022-06-01 21:31:33 +02:00
parent 7233b054d9
commit 1e94e891b2
No known key found for this signature in database
GPG Key ID: 33312B944DD97846
2 changed files with 40 additions and 35 deletions

View 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;
}

View File

@ -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`)