Fix OS scripts for flakes
This commit is contained in:
parent
448a154d74
commit
833320e3fa
9 changed files with 97 additions and 79 deletions
39
build_os.sh
39
build_os.sh
|
@ -1,17 +1,14 @@
|
|||
#!/usr/bin/env nix-shell
|
||||
#! nix-shell -i bash
|
||||
#! nix-shell -p bash nix-output-monitor
|
||||
|
||||
echo FIXME Not flakes ready
|
||||
exit 1
|
||||
#! nix-shell -p nix
|
||||
|
||||
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 "Build NixOS configuration on the local machine."
|
||||
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"
|
||||
|
@ -22,7 +19,7 @@ function help {
|
|||
echo " -b: Build a virtual machine with boot loader."
|
||||
}
|
||||
|
||||
attr=system
|
||||
arg=build
|
||||
while getopts "hvb" OPTION
|
||||
do
|
||||
case "$OPTION" in
|
||||
|
@ -31,10 +28,10 @@ do
|
|||
exit 0
|
||||
;;
|
||||
v)
|
||||
attr=vm
|
||||
arg=build-vm
|
||||
;;
|
||||
b)
|
||||
attr=vmWithBootLoader
|
||||
arg=build-vm-with-bootloader
|
||||
;;
|
||||
?)
|
||||
help
|
||||
|
@ -42,29 +39,35 @@ do
|
|||
;;
|
||||
esac
|
||||
done
|
||||
shift "$(($OPTIND -1))"
|
||||
shift "$((OPTIND -1))"
|
||||
|
||||
if [ "$#" -ne 1 ]
|
||||
then
|
||||
help
|
||||
exit 2
|
||||
fi
|
||||
profile="$1"
|
||||
|
||||
profile_dir="${SCRIPT_DIR}/${profile}"
|
||||
if [ ! -d "$profile_dir" ]
|
||||
if [[ "$1" == *"#"* ]]
|
||||
then
|
||||
echo "Profile not found."
|
||||
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
|
||||
|
||||
nixos_config="${profile_dir}/os.nix"
|
||||
if [ ! -f "$nixos_config" ]
|
||||
if [ ! -f "$flake_uri/flake.nix" ]
|
||||
then
|
||||
echo "NixOS configuration not found."
|
||||
echo "Flake not found."
|
||||
fi
|
||||
|
||||
flake="${flake_uri}#${name}"
|
||||
|
||||
set -x
|
||||
|
||||
nom-build '<nixpkgs/nixos>' -I "nixos-config=${nixos_config}" -A "$attr" -o "${profile_dir}/${attr}"
|
||||
nix --extra-experimental-features "nix-command flakes" run "${SCRIPT_DIR}#nixos-rebuild" -- "$arg" --flake "$flake"
|
||||
|
||||
echo
|
||||
|
||||
# TODO Use update-local-flakes?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue