From eb1bb9fe2739efc7a6ee82b2cd120c403d8e2632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Thu, 21 Nov 2024 13:09:06 +0100 Subject: [PATCH] disko-install: allow to override mountpoints and don't manage them in dry-run --- disko-install | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/disko-install b/disko-install index 8ee5577..f4a5963 100755 --- a/disko-install +++ b/disko-install @@ -20,6 +20,8 @@ Usage: $0 [OPTIONS] Specify this option if you plan to boot from this disk on the current machine, but not if you plan to move the disk to another machine. --system-config JSON Merges the specified JSON object into the NixOS configuration. + --mount-point PATH Specify the mount point for the NixOS installation. + Default: /mnt/disko-install-root EOF } @@ -46,6 +48,7 @@ dry_run= extraSystemConfig="{}" diskoAttr=diskoScript writeEfiBootEntries=false +mountPoint=/mnt/disko-install-root declare -A diskMappings declare -A extraFiles @@ -135,6 +138,14 @@ parseArgs() { shift shift ;; + --mount-point) + if [[ $# -lt 2 ]]; then + echo "Option $1 requires an argument" >&2 + exit 1 + fi + mountPoint=$2 + shift + ;; *) echo "Unknown option: $1" >&2 showUsage @@ -146,7 +157,6 @@ parseArgs() { } cleanupMountPoint() { - mountPoint=$1 if mountpoint -q "${mountPoint}"; then umount -R "${mountPoint}" fi @@ -161,6 +171,14 @@ nixBuild() { fi } +maybeRun () { + if [[ -z ${dry_run-} ]]; then + "$@" + else + echo "Would run: $*" + fi +} + main() { parseArgs "$@" @@ -190,12 +208,12 @@ main() { exit 1 fi - mountPoint="/mnt/disko-install-root" - mkdir -p "${mountPoint}" - chmod 755 "${mountPoint}" # bcachefs wants 755 - escapeMountPoint=$(printf '%q' "$mountPoint") + maybeRun mkdir -p "${mountPoint}" + maybeRun chmod 755 "${mountPoint}" # bcachefs wants 755 # shellcheck disable=SC2064 - trap "cleanupMountPoint ${escapeMountPoint}" EXIT + if [[ -z ${dry_run-} ]]; then + trap cleanupMountPoint EXIT + fi outputs=$(nixBuild "${libexec_dir}"/install-cli.nix \ "${nix_args[@]}" \