diff --git a/flake.nix b/flake.nix index 2d7c6ca..41f992d 100644 --- a/flake.nix +++ b/flake.nix @@ -28,29 +28,15 @@ nixosGenerate options else nixosSystem options; - # TODO: find a faster way to run vm in devShell - mkVirtualMachine = efi: name: args: pkgs.writeShellApplication { - name = "${name}-vm"; - # disable spellcheck to build a command line - excludeShellChecks = [ "SC2086" ]; + vm = name: pkgs.writeShellApplication { + inherit name; text = '' - IMG="${name}-efi.img" - BIOS="${name}-efi-bios.img" - ARGS="${args}" - cp -ui --reflink=auto ${pkgs.OVMF.fd}/FV/OVMF.fd "$BIOS" - chmod a+w "$BIOS" - cp -ui --reflink=auto ${efi}/nixos.img "$IMG" - chmod a+w "$IMG" - qemu-system-${platform} \ - -bios "$BIOS" \ - -drive file="$IMG",format=raw \ - -m 2G \ - $ARGS + export USE_TMPDIR=0 + ${self.nixosConfigurations.${name}.config.formats.vm-nogui} ''; - runtimeInputs = with pkgs; [ qemu ]; }; }; - machines = import ./machines { + setups = import ./setups { inherit system pkgs; flake = self; }; @@ -58,14 +44,19 @@ { inherit lib; + nixosModules = { + inherit (setups.recover.modules) recover; + inherit (setups.cache.modules) cache; + }; + nixosConfigurations = { - inherit (machines.recover) recover-os; - inherit (machines.cache) cache-os; + inherit (setups.recover.machines) recover_0; + inherit (setups.cache.machines) cache_0; }; packages.${system} = { - inherit (machines.recover) recover-efi recover-vm recover-kvm; - inherit (machines.cache) cache-efi cache-vm cache-kvm; + inherit (setups.recover.packages) recover-efi recover-vm; + inherit (setups.cache.packages) cache-vm; }; }; diff --git a/machines/cache/default.nix b/setups/cache/default.nix similarity index 61% rename from machines/cache/default.nix rename to setups/cache/default.nix index 190dd3c..c06eaa8 100644 --- a/machines/cache/default.nix +++ b/setups/cache/default.nix @@ -1,30 +1,14 @@ { system, pkgs, flake, ... }: let - inherit (pkgs.lib) mkDefault; inherit (flake.inputs.everyday.nixosModules) logger; inherit (flake.inputs.attic.nixosModules) atticd; - inherit (flake.outputs.lib) mkSystem mkVirtualMachine; + inherit (flake.outputs.lib) mkSystem vm; domain = "cache.klarkc.is-a.dev"; cache-module = { config, ... }: { + system.stateVersion = config.system.nixos.version; imports = [ logger atticd ]; - networking = { - hostName = "cache-os"; - networkmanager.enable = true; - }; - boot = { - kernelParams = [ - "console=ttyS0,115200" - "console=tty1" - ]; - loader.grub = { - enable = true; - device = "nodev"; - efiSupport = true; - useOSProber = true; - }; - }; - fileSystems."/".device = mkDefault "none"; - + fileSystems."/".device = "none"; + boot.loader.grub.device = "nodev"; services.atticd = { enable = true; # echo -n 'ATTIC_SERVER_TOKEN_HS256_SECRET_BASE64="' > /tmp/atticd.env @@ -57,18 +41,17 @@ let }; in rec { - cache-os = mkSystem { - inherit system; - modules = [ cache-module ]; - }; + modules.cache = cache-module; - cache-efi = mkSystem { + machines.cache_0 = mkSystem { inherit system; - modules = [ cache-module ]; - format = "raw-efi"; + modules = [ + cache-module + { + networking.hostName = "cache_0"; + } + ]; }; - cache-vm = mkVirtualMachine cache-efi "cache" "--nographic"; - - cache-kvm = mkVirtualMachine cache-efi "cache" "--nographic --enable-kvm"; + packages.cache-vm = vm "cache_0"; } diff --git a/machines/default.nix b/setups/default.nix similarity index 100% rename from machines/default.nix rename to setups/default.nix diff --git a/machines/recover/default.nix b/setups/recover/default.nix similarity index 79% rename from machines/recover/default.nix rename to setups/recover/default.nix index 6470081..35ed3ae 100644 --- a/machines/recover/default.nix +++ b/setups/recover/default.nix @@ -1,8 +1,9 @@ { system, pkgs, flake, ... }: let - inherit (pkgs.lib) mkDefault; - inherit (flake.outputs.lib) mkSystem mkVirtualMachine; - recover-module = { + inherit (pkgs.lib) mkDefault version; + inherit (flake.outputs.lib) mkSystem vm; + recover-module = { config, ...}: { + system.stateVersion = config.system.nixos.version; nix = { extraOptions = '' experimental-features = nix-command flakes repl-flake @@ -20,10 +21,7 @@ let }; mutableUsers = false; }; - networking = { - hostName = "recover-os"; - networkmanager.enable = true; - }; + networking.networkmanager.enable = true; boot = { kernelParams = [ "copytoram" @@ -121,18 +119,25 @@ let }; in rec { - recover-os = mkSystem { - inherit system; - modules = [ recover-module ]; - }; + modules.recover = recover-module; - recover-efi = mkSystem { + machines.recover_0 = mkSystem { inherit system; - modules = [ recover-module ]; - format = "raw-efi"; + modules = [ + recover-module + { + networking.hostName = "recover_0"; + } + ]; }; - recover-vm = mkVirtualMachine recover-efi "recover" ""; + packages = { + recover-efi = mkSystem { + inherit system; + modules = [ recover-module ]; + format = "raw-efi"; + }; - recover-kvm = mkVirtualMachine recover-efi "recover" "--enable-kvm"; + recover-vm = vm "recover_0"; + }; }