mirror of
https://github.com/nix-community/disko.git
synced 2026-01-14 18:28:45 +01:00
Fixes #745 This adds a script to create a release. Running it will create two commits that would appear like this in `git log --oneline`: 67b5fff (master) release: reset released flag 0b808f3 (tag: v1.8.1) release: v1.8.1 100d2f3 docs: last change before release It also re-creates the `version.nix` file, which is used by the flake to determine the final version the disko CLI will print. If `disko --version` is run from exactly the commit tagged `v1.8.1`, it will print `1.8.1`. If it is run from any commit past that (like master), it will print `1.8.1-67b5fff`, and if it is run from a local folder with uncommitted changes, it will print `1.8.1-67b5fff-dirty`.
166 lines
4 KiB
Bash
Executable file
166 lines
4 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
readonly libexec_dir="${0%/*}"
|
|
|
|
# a file with the disko config
|
|
declare disko_config
|
|
|
|
# mount was chosen as the default mode because it's less destructive
|
|
mode=mount
|
|
nix_args=()
|
|
|
|
# DISKO_VERSION is set by the wrapper in package.nix
|
|
DISKO_VERSION="${DISKO_VERSION:="unknown! This is a bug, please report it!"}"
|
|
onlyPrintVersion=false
|
|
|
|
showUsage() {
|
|
cat <<USAGE
|
|
Usage: $0 [options] disk-config.nix
|
|
or $0 [options] --flake github:somebody/somewhere#disk-config
|
|
|
|
With flakes, disk-config is discovered first under the .diskoConfigurations top level attribute
|
|
or else from the disko module of a NixOS configuration of that name under .nixosConfigurations.
|
|
|
|
Options:
|
|
|
|
* -m, --mode mode
|
|
set the mode, either format, mount or disko
|
|
format: create partition tables, zpools, lvms, raids and filesystems
|
|
mount: mount the partition at the specified root-mountpoint
|
|
disko: first unmount and destroy all filesystems on the disks we want to format, then run the create and mount mode
|
|
* -f, --flake uri
|
|
fetch the disko config relative to this flake's root
|
|
* --arg name value
|
|
pass value to nix-build. can be used to set disk-names for example
|
|
* --argstr name value
|
|
pass value to nix-build as string
|
|
* --root-mountpoint /some/other/mnt
|
|
where to mount the device tree (default: /mnt)
|
|
* --dry-run
|
|
just show the path to the script instead of running it
|
|
* --no-deps
|
|
avoid adding another dependency closure to an in-memory installer
|
|
requires all necessary dependencies to be available in the environment
|
|
* --debug
|
|
run with set -x
|
|
* --help
|
|
show this help
|
|
USAGE
|
|
}
|
|
|
|
abort() {
|
|
echo "aborted: $*" >&2
|
|
exit 1
|
|
}
|
|
|
|
## Main ##
|
|
|
|
[[ $# -eq 0 ]] && {
|
|
showUsage
|
|
exit 1
|
|
}
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--debug)
|
|
set -x
|
|
;;
|
|
-m | --mode)
|
|
mode=$2
|
|
shift
|
|
;;
|
|
-f | --flake)
|
|
flake=$2
|
|
shift
|
|
;;
|
|
--argstr | --arg)
|
|
nix_args+=("$1" "$2" "$3")
|
|
shift
|
|
shift
|
|
;;
|
|
-h | --help)
|
|
showUsage
|
|
exit 0
|
|
;;
|
|
--dry-run)
|
|
dry_run=y
|
|
;;
|
|
--root-mountpoint)
|
|
nix_args+=(--argstr rootMountPoint "$2")
|
|
shift
|
|
;;
|
|
--no-deps)
|
|
nix_args+=(--arg noDeps true)
|
|
;;
|
|
--show-trace)
|
|
nix_args+=("$1")
|
|
;;
|
|
--version)
|
|
onlyPrintVersion=true
|
|
;;
|
|
*)
|
|
if [ -z ${disko_config+x} ]; then
|
|
disko_config=$1
|
|
else
|
|
showUsage
|
|
exit 1
|
|
fi
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
if [[ "$onlyPrintVersion" = true ]]; then
|
|
echo "$DISKO_VERSION"
|
|
exit 0
|
|
fi
|
|
# Always print version information to help with debugging
|
|
echo "disko version $DISKO_VERSION"
|
|
|
|
nixBuild() {
|
|
if command -v nom-build > /dev/null; then
|
|
nom-build "$@"
|
|
else
|
|
nix-build "$@"
|
|
fi
|
|
}
|
|
|
|
if ! { [[ $mode = "format" ]] || [[ $mode = "mount" ]] || [[ $mode = "disko" ]] || [[ $mode = "create" ]] || [[ $mode = "zap_create_mount" ]] ; }; then
|
|
abort "mode must be either format, mount or disko"
|
|
fi
|
|
|
|
if [[ -n "${flake+x}" ]]; then
|
|
if [[ $flake =~ ^(.*)\#([^\#\"]*)$ ]]; then
|
|
flake="${BASH_REMATCH[1]}"
|
|
flakeAttr="${BASH_REMATCH[2]}"
|
|
fi
|
|
if [[ -z "${flakeAttr-}" ]]; then
|
|
echo "Please specify the name of the NixOS configuration to be installed, as a URI fragment in the flake-uri."
|
|
echo "For example, to use the output diskoConfigurations.foo from the flake.nix, append \"#foo\" to the flake-uri."
|
|
exit 1
|
|
fi
|
|
if [[ -e "$flake" ]]; then
|
|
flake="$(realpath "$flake")"
|
|
fi
|
|
nix_args+=("--arg" "flake" "\"$flake\"")
|
|
nix_args+=("--argstr" "flakeAttr" "$flakeAttr")
|
|
nix_args+=(--extra-experimental-features flakes)
|
|
elif [[ -n "${disko_config+x}" ]] && [[ -e "$disko_config" ]]; then
|
|
nix_args+=("--arg" "diskoFile" "$(realpath "$disko_config")")
|
|
else
|
|
abort "disko config must be an existing file or flake must be set"
|
|
fi
|
|
|
|
# The "--impure" is still pure, as the path is within the nix store.
|
|
script=$(nixBuild "${libexec_dir}"/cli.nix \
|
|
--no-out-link \
|
|
--impure \
|
|
--argstr mode "$mode" \
|
|
"${nix_args[@]}"
|
|
)
|
|
if [[ -n "${dry_run+x}" ]]; then
|
|
echo "$script"
|
|
else
|
|
exec "$script"
|
|
fi
|