From 1e94e891b213bb045aa75579cd6018c8fbcc4a58 Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Wed, 1 Jun 2022 21:31:33 +0200 Subject: [PATCH] flake: move VM to separate file This simplifies the flake. --- examples/qemu-vm/minimal-vm.nix | 35 +++++++++++++++++++++++++++++ flake.nix | 40 +++++---------------------------- 2 files changed, 40 insertions(+), 35 deletions(-) create mode 100644 examples/qemu-vm/minimal-vm.nix diff --git a/examples/qemu-vm/minimal-vm.nix b/examples/qemu-vm/minimal-vm.nix new file mode 100644 index 0000000..041a310 --- /dev/null +++ b/examples/qemu-vm/minimal-vm.nix @@ -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; +} diff --git a/flake.nix b/flake.nix index 22767d3..338bce1 100644 --- a/flake.nix +++ b/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`)