summaryrefslogtreecommitdiffstats
path: root/disko
diff options
context:
space:
mode:
authorDavid Arnold <david.arnold@iohk.io>2022-11-06 01:46:48 -0500
committerlassulus <lassulus@lassul.us>2022-11-09 12:30:06 +0100
commit0af2a7c206bd69ecdc01361e12c7cb0ec9820911 (patch)
treed4efbdf4713aa4428a4922c0389ca4c61c808b9e /disko
parenta023d391a08f8c8b1b7c26fcbb8d06edd5ceb203 (diff)
feat: allow to declare disko-config relative to flake
Diffstat (limited to 'disko')
-rwxr-xr-xdisko22
1 files changed, 20 insertions, 2 deletions
diff --git a/disko b/disko
index f51339e..deb3cbd 100755
--- a/disko
+++ b/disko
@@ -6,6 +6,9 @@ readonly libexec_dir="${0%/*}"
# a file with the disko config
declare disko_config
+# a flake uri, if present disko config is relative to the flake root
+declare from_flake
+
# mount was chosen as the default mode because it's less destructive
mode=mount
nix_args=()
@@ -18,6 +21,8 @@ Options:
* -m, --mode mode
set the mode, either create or mount
+* -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
@@ -43,6 +48,11 @@ while [[ $# -gt 0 ]]; do
mode=$2
shift
;;
+ -f | --flake)
+ from_flake="$2"
+ nix_args+=("--argstr" "fromFlake" "$2")
+ shift
+ ;;
--argstr | --arg)
nix_args+=("$1" "$2" "$3")
shift
@@ -53,7 +63,7 @@ while [[ $# -gt 0 ]]; do
exit 0
;;
*)
- if [ -z ${disko_config+x} ] && [ -e "$1" ]; then
+ if [ -z ${disko_config+x} ]; then
disko_config=$1
else
showUsage
@@ -68,8 +78,16 @@ if ! ([[ $mode = "create" ]] || [[ $mode = "mount" ]]); then
abort "mode must be either create or mount"
fi
+if [[ -e "${disko_config}" ]]; then
+ nix_args+=("--arg" "diskoFile" "$disko_config")
+elif [[ -n "${from_flake+x}" ]]; then
+ nix_args+=("--argstr" "diskoFile" "$disko_config")
+else
+ abort "disko config must be an exising file of flake must be set"
+fi
+
script=$(nix-build "${libexec_dir}"/cli.nix \
- --arg diskoFile "$disko_config" \
+ --argstr diskoFile "$disko_config" \
--argstr mode "$mode" \
"${nix_args[@]}"
)