From 0fb19bbbe0c408cdbf6fbf54e1b770b6c71c2c8a Mon Sep 17 00:00:00 2001 From: xtrm Date: Wed, 19 Feb 2025 14:25:05 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20better=20vm=20?= =?UTF-8?q?handling,=20no=20more=20scripts,=20we're=20true=20nix=20elitist?= =?UTF-8?q?s=20here?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xtrm --- vm/cleanup.sh | 4 ---- vm/configuration.nix | 8 +++++++- vm/flake.nix | 37 ++++++++++++++++++++++++++++++------- vm/run.sh | 5 ----- 4 files changed, 37 insertions(+), 17 deletions(-) delete mode 100755 vm/cleanup.sh delete mode 100755 vm/run.sh diff --git a/vm/cleanup.sh b/vm/cleanup.sh deleted file mode 100755 index ec906f4..0000000 --- a/vm/cleanup.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -rm -v nixos.qcow2 -rm -vfr result diff --git a/vm/configuration.nix b/vm/configuration.nix index fa89dfc..4afa1ad 100644 --- a/vm/configuration.nix +++ b/vm/configuration.nix @@ -1,4 +1,10 @@ -{ config, pkgs, modulesPath, hostname, ... }: +{ + config, + pkgs, + modulesPath, + hostname, + ... +}: { imports = [ diff --git a/vm/flake.nix b/vm/flake.nix index fff73d0..1cfb2c5 100644 --- a/vm/flake.nix +++ b/vm/flake.nix @@ -47,14 +47,37 @@ apps = forAllSystems ( system: let - vm = { - type = "app"; - program = "${self.packages.${system}.vm}/bin/run-${hostname}-vm"; - programArgs = [ "-enable-kvm" ]; - }; + pkgs = import nixpkgs { inherit system; }; + lib = pkgs.lib; + selfPkgs = self.packages.${system}; in - { - inherit vm; + rec { + vm = + let + scriptName = "run-${hostname}-vm"; + script = pkgs.writeShellScriptBin "${scriptName}" '' + ${selfPkgs.vm}/bin/run-${hostname}-vm \ + -enable-kvm \ + -virtfs local,path=$(${pkgs.coreutils}/bin/pwd)/..,mount_tag=host0,security_model=passthrough,id=host0 + ''; + in + { + type = "app"; + program = "${script}/bin/${scriptName}"; + }; + + clean = + let + scriptName = "clean-${hostname}-vm"; + script = pkgs.writeShellScriptBin "${scriptName}" '' + ${pkgs.coreutils}/bin/rm -rfv result ${hostname}.qcow2 + ''; + in + { + type = "app"; + program = "${script}/bin/${scriptName}"; + }; + default = vm; } ); diff --git a/vm/run.sh b/vm/run.sh deleted file mode 100755 index 82cc610..0000000 --- a/vm/run.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail - -nix run . -- -virtfs local,path=$(pwd)/..,mount_tag=host0,security_model=passthrough,id=host0