2023-11-30 18:59:50 +01:00
|
|
|
|
#!/usr/bin/env nix-shell
|
|
|
|
|
#! nix-shell -i bash
|
2024-02-17 23:35:53 +01:00
|
|
|
|
#! nix-shell -p nix
|
2024-01-06 19:10:47 +01:00
|
|
|
|
|
2023-11-30 18:59:50 +01:00
|
|
|
|
set -euo pipefail
|
|
|
|
|
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
|
|
|
|
|
|
|
|
|
# Parse arguments
|
|
|
|
|
function help {
|
2024-02-17 23:35:53 +01:00
|
|
|
|
echo "Usage: $0 [-h|-e|-b] [flake-uri#]name"
|
|
|
|
|
echo "Build a NixOS configuration on the local machine."
|
2023-11-30 18:59:50 +01:00
|
|
|
|
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."
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-17 23:35:53 +01:00
|
|
|
|
arg=build
|
2023-11-30 18:59:50 +01:00
|
|
|
|
while getopts "hvb" OPTION
|
|
|
|
|
do
|
|
|
|
|
case "$OPTION" in
|
|
|
|
|
h)
|
|
|
|
|
help
|
|
|
|
|
exit 0
|
|
|
|
|
;;
|
|
|
|
|
v)
|
2024-02-17 23:35:53 +01:00
|
|
|
|
arg=build-vm
|
2023-11-30 18:59:50 +01:00
|
|
|
|
;;
|
|
|
|
|
b)
|
2024-02-17 23:35:53 +01:00
|
|
|
|
arg=build-vm-with-bootloader
|
2023-11-30 18:59:50 +01:00
|
|
|
|
;;
|
|
|
|
|
?)
|
|
|
|
|
help
|
|
|
|
|
exit 2
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
2024-02-17 23:35:53 +01:00
|
|
|
|
shift "$((OPTIND -1))"
|
2023-11-30 18:59:50 +01:00
|
|
|
|
|
|
|
|
|
if [ "$#" -ne 1 ]
|
|
|
|
|
then
|
|
|
|
|
help
|
|
|
|
|
exit 2
|
|
|
|
|
fi
|
|
|
|
|
|
2024-02-17 23:35:53 +01:00
|
|
|
|
if [[ "$1" == *"#"* ]]
|
2023-11-30 18:59:50 +01:00
|
|
|
|
then
|
2024-02-17 23:35:53 +01:00
|
|
|
|
flake_uri="$(echo "$1" | cut -d'#' -f1)"
|
|
|
|
|
flake_uri=$( cd -- "$flake_uri" &> /dev/null && pwd )
|
|
|
|
|
name="$(echo "$1" | cut -d'#' -f2)"
|
|
|
|
|
else
|
|
|
|
|
flake_uri="$SCRIPT_DIR"
|
|
|
|
|
name="$1"
|
2023-11-30 18:59:50 +01:00
|
|
|
|
fi
|
|
|
|
|
|
2024-02-17 23:35:53 +01:00
|
|
|
|
if [ ! -f "$flake_uri/flake.nix" ]
|
2023-11-30 18:59:50 +01:00
|
|
|
|
then
|
2024-02-17 23:35:53 +01:00
|
|
|
|
echo "Flake not found."
|
2023-11-30 18:59:50 +01:00
|
|
|
|
fi
|
|
|
|
|
|
2024-02-17 23:35:53 +01:00
|
|
|
|
flake="${flake_uri}#${name}"
|
|
|
|
|
|
2023-11-30 18:59:50 +01:00
|
|
|
|
set -x
|
|
|
|
|
|
2024-02-17 23:35:53 +01:00
|
|
|
|
nix --extra-experimental-features "nix-command flakes" run "${SCRIPT_DIR}#nixos-rebuild" -- "$arg" --flake "$flake"
|
2023-11-30 18:59:50 +01:00
|
|
|
|
|
|
|
|
|
echo
|
2024-02-17 23:35:53 +01:00
|
|
|
|
|
|
|
|
|
# TODO Use update-local-flakes?
|