mirror of
https://github.com/TECHNOFAB11/disko.git
synced 2025-12-12 08:00:05 +01:00
feat: allow to declare disko-config relative to flake
This commit is contained in:
parent
a023d391a0
commit
0af2a7c206
2 changed files with 26 additions and 4 deletions
8
cli.nix
8
cli.nix
|
|
@ -1,10 +1,14 @@
|
||||||
{ pkgs ? import <nixpkgs> {}
|
{ pkgs ? import <nixpkgs> {}
|
||||||
, mode ? "mount"
|
, mode ? "mount"
|
||||||
|
, fromFlake ? null
|
||||||
, diskoFile
|
, diskoFile
|
||||||
, ... }@args:
|
, ... }@args:
|
||||||
let
|
let
|
||||||
disko = import ./. { inherit (pkgs) lib; };
|
disko = import ./. { };
|
||||||
diskFormat = import diskoFile;
|
diskFormat =
|
||||||
|
if fromFlake != null
|
||||||
|
then (builtins.getFlake fromFlake) + "/${diskoFile}"
|
||||||
|
else import diskoFile;
|
||||||
diskoEval = if (mode == "create") then
|
diskoEval = if (mode == "create") then
|
||||||
disko.createScript diskFormat pkgs
|
disko.createScript diskFormat pkgs
|
||||||
else if (mode == "mount") then
|
else if (mode == "mount") then
|
||||||
|
|
|
||||||
22
disko
22
disko
|
|
@ -6,6 +6,9 @@ readonly libexec_dir="${0%/*}"
|
||||||
# a file with the disko config
|
# a file with the disko config
|
||||||
declare 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
|
# mount was chosen as the default mode because it's less destructive
|
||||||
mode=mount
|
mode=mount
|
||||||
nix_args=()
|
nix_args=()
|
||||||
|
|
@ -18,6 +21,8 @@ Options:
|
||||||
|
|
||||||
* -m, --mode mode
|
* -m, --mode mode
|
||||||
set the mode, either create or mount
|
set the mode, either create or mount
|
||||||
|
* -f, --flake uri
|
||||||
|
fetch the disko config relative to this flake's root
|
||||||
* --arg name value
|
* --arg name value
|
||||||
pass value to nix-build. can be used to set disk-names for example
|
pass value to nix-build. can be used to set disk-names for example
|
||||||
* --argstr name value
|
* --argstr name value
|
||||||
|
|
@ -43,6 +48,11 @@ while [[ $# -gt 0 ]]; do
|
||||||
mode=$2
|
mode=$2
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-f | --flake)
|
||||||
|
from_flake="$2"
|
||||||
|
nix_args+=("--argstr" "fromFlake" "$2")
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--argstr | --arg)
|
--argstr | --arg)
|
||||||
nix_args+=("$1" "$2" "$3")
|
nix_args+=("$1" "$2" "$3")
|
||||||
shift
|
shift
|
||||||
|
|
@ -53,7 +63,7 @@ while [[ $# -gt 0 ]]; do
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
if [ -z ${disko_config+x} ] && [ -e "$1" ]; then
|
if [ -z ${disko_config+x} ]; then
|
||||||
disko_config=$1
|
disko_config=$1
|
||||||
else
|
else
|
||||||
showUsage
|
showUsage
|
||||||
|
|
@ -68,8 +78,16 @@ if ! ([[ $mode = "create" ]] || [[ $mode = "mount" ]]); then
|
||||||
abort "mode must be either create or mount"
|
abort "mode must be either create or mount"
|
||||||
fi
|
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 \
|
script=$(nix-build "${libexec_dir}"/cli.nix \
|
||||||
--arg diskoFile "$disko_config" \
|
--argstr diskoFile "$disko_config" \
|
||||||
--argstr mode "$mode" \
|
--argstr mode "$mode" \
|
||||||
"${nix_args[@]}"
|
"${nix_args[@]}"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue