mirror of
https://github.com/nix-community/disko.git
synced 2026-12-02 14:03:28 +01:00
Merge pull request #890 from nix-community/disko-install
disko-install: dry-run improvements
This commit is contained in:
2 files changed
+29
-9
No files matched your search
+28
-8
@@ -20,6 +20,8 @@ Usage: $0 [OPTIONS]
|
|||||||
Specify this option if you plan to boot from this disk on the current machine,
|
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.
|
but not if you plan to move the disk to another machine.
|
||||||
--system-config JSON Merges the specified JSON object into the NixOS configuration.
|
--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
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,6 +48,7 @@ dry_run=
|
|||||||
extraSystemConfig="{}"
|
extraSystemConfig="{}"
|
||||||
diskoAttr=diskoScript
|
diskoAttr=diskoScript
|
||||||
writeEfiBootEntries=false
|
writeEfiBootEntries=false
|
||||||
|
mountPoint=/mnt/disko-install-root
|
||||||
declare -A diskMappings
|
declare -A diskMappings
|
||||||
declare -A extraFiles
|
declare -A extraFiles
|
||||||
|
|
||||||
@@ -135,6 +138,14 @@ parseArgs() {
|
|||||||
shift
|
shift
|
||||||
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
|
echo "Unknown option: $1" >&2
|
||||||
showUsage
|
showUsage
|
||||||
@@ -146,7 +157,6 @@ parseArgs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanupMountPoint() {
|
cleanupMountPoint() {
|
||||||
mountPoint=$1
|
|
||||||
if mountpoint -q "${mountPoint}"; then
|
if mountpoint -q "${mountPoint}"; then
|
||||||
umount -R "${mountPoint}"
|
umount -R "${mountPoint}"
|
||||||
fi
|
fi
|
||||||
@@ -161,6 +171,14 @@ nixBuild() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
maybeRun () {
|
||||||
|
if [[ -z ${dry_run-} ]]; then
|
||||||
|
"$@"
|
||||||
|
else
|
||||||
|
echo "Would run: $*"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
parseArgs "$@"
|
parseArgs "$@"
|
||||||
|
|
||||||
@@ -170,7 +188,7 @@ main() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# check if we are root
|
# 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
|
echo "This script must be run as root" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -190,12 +208,12 @@ main() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mountPoint="/mnt/disko-install-root"
|
maybeRun mkdir -p "${mountPoint}"
|
||||||
mkdir -p "${mountPoint}"
|
maybeRun chmod 755 "${mountPoint}" # bcachefs wants 755
|
||||||
chmod 755 "${mountPoint}" # bcachefs wants 755
|
|
||||||
escapeMountPoint=$(printf '%q' "$mountPoint")
|
|
||||||
# shellcheck disable=SC2064
|
# shellcheck disable=SC2064
|
||||||
trap "cleanupMountPoint ${escapeMountPoint}" EXIT
|
if [[ -z ${dry_run-} ]]; then
|
||||||
|
trap cleanupMountPoint EXIT
|
||||||
|
fi
|
||||||
|
|
||||||
outputs=$(nixBuild "${libexec_dir}"/install-cli.nix \
|
outputs=$(nixBuild "${libexec_dir}"/install-cli.nix \
|
||||||
"${nix_args[@]}" \
|
"${nix_args[@]}" \
|
||||||
@@ -222,7 +240,9 @@ main() {
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
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
|
for source in "${!extraFiles[@]}"; do
|
||||||
destination=${extraFiles[$source]}
|
destination=${extraFiles[$source]}
|
||||||
|
|||||||
+1
-1
@@ -80,7 +80,7 @@
|
|||||||
# TODO: we don't support encrypted swap yet
|
# TODO: we don't support encrypted swap yet
|
||||||
default = lib.optionalAttrs (!config.randomEncryption) {
|
default = lib.optionalAttrs (!config.randomEncryption) {
|
||||||
fs.${config.device} = ''
|
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 ${
|
swapon ${
|
||||||
lib.optionalString (config.discardPolicy != null)
|
lib.optionalString (config.discardPolicy != null)
|
||||||
"--discard${lib.optionalString (config.discardPolicy != "both")
|
"--discard${lib.optionalString (config.discardPolicy != "both")
|
||||||
|
|||||||
Reference in new issue
Block a user