From 617a84a384aa0584000b021d24433789a329cb00 Mon Sep 17 00:00:00 2001 From: Stefan Junker Date: Sun, 23 Sep 2018 14:09:35 +0200 Subject: [PATCH] tests: add buildwmwithbootloader stub --- tests/buildvmwithbootloader/build-vm.nix | 32 ++++++++++++++++ tests/buildvmwithbootloader/build-vm.sh | 16 ++++++++ tests/buildvmwithbootloader/configuration.nix | 38 +++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 tests/buildvmwithbootloader/build-vm.nix create mode 100755 tests/buildvmwithbootloader/build-vm.sh create mode 100644 tests/buildvmwithbootloader/configuration.nix diff --git a/tests/buildvmwithbootloader/build-vm.nix b/tests/buildvmwithbootloader/build-vm.nix new file mode 100644 index 0000000..8347b45 --- /dev/null +++ b/tests/buildvmwithbootloader/build-vm.nix @@ -0,0 +1,32 @@ +{ system ? builtins.currentSystem +, vmPkgsPath +, buildPkgsPath +, nixosConfigPath +}: + +let + buildPkgs = import buildPkgsPath {}; + vmPkgs'= import vmPkgsPath {}; + vmPkgs = vmPkgs' // { + runtimeShell = "${vmPkgs'.bash}/${vmPkgs'.bash.shellPath}"; + }; + + importWithPkgs = { path, pkgs }: args: import path (args // { inherit pkgs; }); + + nixosConfig = importWithPkgs { path = "${nixosConfigPath}"; pkgs = vmPkgs; }; + vmConfig = importWithPkgs { path = "${buildPkgsPath}/nixos/modules/virtualisation/qemu-vm.nix"; pkgs = vmPkgs; }; + evalConfig = importWithPkgs { path = "${vmPkgsPath}/nixos/lib/eval-config.nix"; pkgs = null; }; + + vmWithBootLoaderConfigMixed = (evalConfig { + modules = [ + nixosConfig + vmConfig + { + virtualisation.useBootLoader = true; + } + + ]; + }).config; +in { + vmWithBootLoaderMixed = vmWithBootLoaderConfigMixed.system.build.vm; +} diff --git a/tests/buildvmwithbootloader/build-vm.sh b/tests/buildvmwithbootloader/build-vm.sh new file mode 100755 index 0000000..520e0c8 --- /dev/null +++ b/tests/buildvmwithbootloader/build-vm.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -x +rm *.qcow2 +rm result* +set -e + +BUILD_NIXPKGS="${BUILD_NIXPKGS:-${HOME}/src/github/NixOS/nixpkgs.dev}" +NIXOS_CONFIG="${NIXOS_CONFIG_OVERRIDE:-${PWD}/configuration.nix}" + +nix-build -K --show-trace build-vm.nix \ + --arg vmPkgsPath '' \ + --argstr buildPkgsPath "${BUILD_NIXPKGS}" \ + --argstr nixosConfigPath "${NIXOS_CONFIG}" \ + -A vmWithBootLoaderMixed + +./result/bin/run-*-vm diff --git a/tests/buildvmwithbootloader/configuration.nix b/tests/buildvmwithbootloader/configuration.nix new file mode 100644 index 0000000..874bea1 --- /dev/null +++ b/tests/buildvmwithbootloader/configuration.nix @@ -0,0 +1,38 @@ +{ pkgs, lib, ... }: +let + +in + +{ + boot.loader.grub = { + enable = true; + version = 2; + device = "/dev/vda"; + efiSupport = true; + enableCryptodisk = true; + }; + boot.loader.efi.canTouchEfiVariables = true; + boot.loader.systemd-boot.enable = true; + + boot.initrd.luks.devices = [ { + name = "crypt"; + device = "/dev/disk/uuid/463d886d-7dfe-421b-8cef-f9af3a3fa09d"; + preLVM = true; + allowDiscards = true; + } + ]; + fileSystems."/" = { + label = "root"; + }; + + fileSystems."/boot" = { + label = "boot"; + }; + + boot.tmpOnTmpfs = true; + + boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "usb_storage" "sd_mod" "rtsx_pci_sdmmc" ]; + + users.extraUsers.root.initialPassword = lib.mkForce "toorroot"; + users.mutableUsers = false; +}