From 4cbd22d868af48cb88df4dd6e38a675924b9ba3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Thu, 21 Nov 2024 12:30:06 +0100 Subject: [PATCH 1/3] allow to run dry-run without using root --- disko-install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/disko-install b/disko-install index a10ff80..8ee5577 100755 --- a/disko-install +++ b/disko-install @@ -170,7 +170,7 @@ main() { fi # check if we are root - if [[ "$EUID" -ne 0 ]]; then + if [[ "$EUID" -ne 0 ]] && [[ -z ${dry_run-} ]]; then echo "This script must be run as root" >&2 exit 1 fi 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 2/3] 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[@]}" \ From fd3e326e9a75f919463184a53ca2ee9c31e4ebdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Thu, 21 Nov 2024 14:11:02 +0100 Subject: [PATCH 3/3] disable swap in disko-install Update disko-install Co-authored-by: Michael Hoang --- disko-install | 4 +++- lib/types/swap.nix | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/disko-install b/disko-install index f4a5963..4f0a8b7 100755 --- a/disko-install +++ b/disko-install @@ -240,7 +240,9 @@ main() { exit 0 fi - "$disko_script" + # We don't want swap as can break your running system in weird ways if you eject the disk + # Hopefully disko-install has enough RAM to run without swap, otherwise we can make this configurable in future. + DISKO_SKIP_SWAP=1 "$disko_script" for source in "${!extraFiles[@]}"; do destination=${extraFiles[$source]} diff --git a/lib/types/swap.nix b/lib/types/swap.nix index 401ac12..84e6b03 100644 --- a/lib/types/swap.nix +++ b/lib/types/swap.nix @@ -80,7 +80,7 @@ # TODO: we don't support encrypted swap yet default = lib.optionalAttrs (!config.randomEncryption) { fs.${config.device} = '' - if ! swapon --show | grep -q "^$(readlink -f "${config.device}") "; then + if test "''${DISKO_SKIP_SWAP:-}" != 1 && ! swapon --show | grep -q "^$(readlink -f "${config.device}") "; then swapon ${ lib.optionalString (config.discardPolicy != null) "--discard${lib.optionalString (config.discardPolicy != "both")