From 224f769324191250697da5c00533dd1d872edea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geoffrey=20=E2=80=9CFrogeye=E2=80=9D=20Preud=27homme?= Date: Thu, 30 Nov 2023 18:59:50 +0100 Subject: [PATCH] Do not restrict VMs to a single config Also "allows" full-system build without install. --- .gitignore | 4 +++ build_os.sh | 66 ++++++++++++++++++++++++++++++++++++++++ full/README.md | 6 ++++ {vm => full}/options.nix | 2 +- {vm => full}/os.nix | 0 install_os.sh | 6 ++-- vm/.gitignore | 2 -- vm/build.sh | 11 ------- 8 files changed, 80 insertions(+), 17 deletions(-) create mode 100644 .gitignore create mode 100755 build_os.sh create mode 100644 full/README.md rename {vm => full}/options.nix (77%) rename {vm => full}/os.nix (100%) delete mode 100644 vm/.gitignore delete mode 100755 vm/build.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..29ae37f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*/system +*/vm +*/vmWithBootLoader +*.qcow2 diff --git a/build_os.sh b/build_os.sh new file mode 100755 index 0000000..7c15d89 --- /dev/null +++ b/build_os.sh @@ -0,0 +1,66 @@ +#!/usr/bin/env nix-shell +#! nix-shell -i bash +#! nix-shell -p bash nix-output-monitor + +set -euo pipefail +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +# Parse arguments +function help { + echo "Usage: $0 [-h|-v|-b] profile" + echo + echo "Arguments:" + echo " profile: OS/disk profile to use" + echo + echo "Options:" + echo " -h: Display this help message." + echo " -v: Build a virtual machine." + echo " -b: Build a virtual machine with boot loader." +} + +attr=system +while getopts "hvb" OPTION +do + case "$OPTION" in + h) + help + exit 0 + ;; + v) + attr=vm + ;; + b) + attr=vmWithBootLoader + ;; + ?) + help + exit 2 + ;; + esac +done +shift "$(($OPTIND -1))" + +if [ "$#" -ne 1 ] +then + help + exit 2 +fi +profile="$1" + +profile_dir="${SCRIPT_DIR}/${profile}" +if [ ! -d "$profile_dir" ] +then + echo "Profile not found." +fi + +nixos_config="${profile_dir}/os.nix" +if [ ! -f "$nixos_config" ] +then + echo "NixOS configuration not found." +fi + +set -x + +nom-build '' -I "nixos-config=${nixos_config}" -A "$attr" -o "${profile_dir}/${attr}" + +echo  diff --git a/full/README.md b/full/README.md new file mode 100644 index 0000000..0f087b5 --- /dev/null +++ b/full/README.md @@ -0,0 +1,6 @@ +# full profile + +Fake configuration that contains everything I could ever need, +used for debugging. +Can't build a full system due to not having a filesystem / bootloader configuration, +build as a VM (without bootloader). diff --git a/vm/options.nix b/full/options.nix similarity index 77% rename from vm/options.nix rename to full/options.nix index f342e90..33b7620 100644 --- a/vm/options.nix +++ b/full/options.nix @@ -9,6 +9,6 @@ fpga = true; python = true; }; - # extra = true; # FIXME Should support aarch64 + extra = true; }; } diff --git a/vm/os.nix b/full/os.nix similarity index 100% rename from vm/os.nix rename to full/os.nix diff --git a/install_os.sh b/install_os.sh index a77eb18..87bf1b3 100755 --- a/install_os.sh +++ b/install_os.sh @@ -7,10 +7,10 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) # Parse arguments function help { - echo "Usage: $0 [-e] [-h] profile" + echo "Usage: $0 [-h|-e] profile" echo echo "Arguments:" - echo " file: OS/disk profile to use" + echo " profile: OS/disk profile to use" echo echo "Options:" echo " -h: Display this help message." @@ -18,7 +18,7 @@ function help { } disko_mode=mount -while getopts "e" OPTION +while getopts "he" OPTION do case "$OPTION" in h) diff --git a/vm/.gitignore b/vm/.gitignore deleted file mode 100644 index ee0c388..0000000 --- a/vm/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.qcow2 -result diff --git a/vm/build.sh b/vm/build.sh deleted file mode 100755 index 97e698d..0000000 --- a/vm/build.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env nix-shell -#! nix-shell -i bash -#! nix-shell -p bash nix-output-monitor - -# Build a NixOS VM for testing - -set -euo pipefail -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) - -nom-build '' -A vm \ - -I nixos-config=./os.nix