dotfiles/build_os.sh
Geoffrey Frogeye 224f769324
Do not restrict VMs to a single config
Also "allows" full-system build without install.
2023-11-30 18:59:50 +01:00

67 lines
1.2 KiB
Bash
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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 '<nixpkgs/nixos>' -I "nixos-config=${nixos_config}" -A "$attr" -o "${profile_dir}/${attr}"
echo