dotfiles/build_os.sh

74 lines
1.4 KiB
Bash
Raw Normal View History

#!/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
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."
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
while getopts "hvb" OPTION
do
case "$OPTION" in
h)
help
exit 0
;;
v)
2024-02-17 23:35:53 +01:00
arg=build-vm
;;
b)
2024-02-17 23:35:53 +01:00
arg=build-vm-with-bootloader
;;
?)
help
exit 2
;;
esac
done
2024-02-17 23:35:53 +01:00
shift "$((OPTIND -1))"
if [ "$#" -ne 1 ]
then
help
exit 2
fi
2024-02-17 23:35:53 +01:00
if [[ "$1" == *"#"* ]]
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"
fi
2024-02-17 23:35:53 +01:00
if [ ! -f "$flake_uri/flake.nix" ]
then
2024-02-17 23:35:53 +01:00
echo "Flake not found."
fi
2024-02-17 23:35:53 +01:00
flake="${flake_uri}#${name}"
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"
echo 
2024-02-17 23:35:53 +01:00
# TODO Use update-local-flakes?