Skip to content

Commit 9811c4f

Browse files
Mic92mergify[bot]
authored andcommitted
allow to only mount or create partitions with disko
This allows to repair installations or create new filesystems without removing the existing data.
1 parent c89b16b commit 9811c4f

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/nixos-anywhere.sh

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ kexecUrl=""
88
kexecExtraFlags=""
99
enableDebug=""
1010
diskoScript=""
11+
diskoMode="disko"
1112
nixosSystem=""
1213
extraFiles=""
1314
vmTest="n"
@@ -116,6 +117,11 @@ Options:
116117
disko: first unmount and destroy all filesystems on the disks we want to format, then run the create and mount mode
117118
install: install the system
118119
reboot: reboot the machine
120+
* --disko-mode create|mount|disko
121+
set the disko mode to create, mount or destroy. Default is disko.
122+
format: create partition tables, zpools, lvms, raids and filesystems (Experimental: Can be run increntally, but use with caution and good backups)
123+
mount: mount the partition at the specified root-mountpoint
124+
disko: first unmount and destroy all filesystems on the disks we want to format, then run the create and mount mode
119125
USAGE
120126
}
121127

@@ -201,6 +207,18 @@ parseArgs() {
201207
printBuildLogs=y
202208
set -x
203209
;;
210+
--disko-mode)
211+
case "$2" in
212+
create | mount | disko)
213+
diskoMode=$2
214+
;;
215+
*)
216+
abort "Supported values for --disko-mode create, mount, disko. Unknown mode : $2"
217+
;;
218+
esac
219+
220+
shift
221+
;;
204222
--extra-files)
205223
extraFiles=$2
206224
shift
@@ -518,11 +536,11 @@ runDisko() {
518536
step Building disko script
519537
# We need to do a nix copy first because nix build doesn't have --no-check-sigs
520538
# Use ssh:// here to avoid https://github.com/NixOS/nix/issues/7359
521-
nixCopy --to "ssh://$sshConnection" "${flake}#nixosConfigurations.\"${flakeAttr}\".config.system.build.diskoScript" \
539+
nixCopy --to "ssh://$sshConnection" "${flake}#nixosConfigurations.\"${flakeAttr}\".config.system.build.${diskoMode}Script" \
522540
--derivation --no-check-sigs
523541
# If we don't use ssh-ng here, we get `error: operation 'getFSAccessor' is not supported by store`
524542
diskoScript=$(
525-
nixBuild "${flake}#nixosConfigurations.\"${flakeAttr}\".config.system.build.diskoScript" \
543+
nixBuild "${flake}#nixosConfigurations.\"${flakeAttr}\".config.system.build.${diskoMode}Script" \
526544
--eval-store auto --store "ssh-ng://$sshConnection?ssh-key=$sshKeyDir/nixos-anywhere"
527545
)
528546
fi
@@ -602,7 +620,7 @@ main() {
602620
# parse flake nixos-install style syntax, get the system attr
603621
if [[ -n ${flake} ]]; then
604622
if [[ ${buildOnRemote} == "n" ]] && [[ ${hardwareConfigBackend} == "none" ]]; then
605-
diskoScript=$(nixBuild "${flake}#nixosConfigurations.\"${flakeAttr}\".config.system.build.diskoScript")
623+
diskoScript=$(nixBuild "${flake}#nixosConfigurations.\"${flakeAttr}\".config.system.build.${diskoMode}Script")
606624
nixosSystem=$(nixBuild "${flake}#nixosConfigurations.\"${flakeAttr}\".config.system.build.toplevel")
607625
fi
608626
elif [[ -n ${diskoScript} ]] && [[ -n ${nixosSystem} ]]; then
@@ -658,7 +676,7 @@ main() {
658676
fi
659677

660678
if [[ ${buildOnRemote} == "n" ]] && [[ -n ${flake} ]] && [[ ${hardwareConfigBackend} != "none" ]]; then
661-
diskoScript=$(nixBuild "${flake}#nixosConfigurations.\"${flakeAttr}\".config.system.build.diskoScript")
679+
diskoScript=$(nixBuild "${flake}#nixosConfigurations.\"${flakeAttr}\".config.system.build.${diskoMode}Script")
662680
nixosSystem=$(nixBuild "${flake}#nixosConfigurations.\"${flakeAttr}\".config.system.build.toplevel")
663681
fi
664682

0 commit comments

Comments
 (0)