Skip to content

Commit d002ce9

Browse files
authored
Merge pull request #421 from mexisme/fix/diskSize-type/convert-explicitly
fix: Make sure the "--disk-size" arg is correctly interpreted as an int by Nix, when an int is provided
2 parents 74b8e31 + 90a2c43 commit d002ce9

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

nixos-generate

+15-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ abort() {
5858
exit 1
5959
}
6060

61+
# TODO: Is there a better name for this?
62+
fixDiskSizeFormat() {
63+
# If the arg is an int, pass it back unchanged:
64+
if [[ "$1" =~ ^[0-9][0-9]*$ ]]; then
65+
echo "$1"
66+
return
67+
fi
68+
69+
# If the arg is _not_ an int, we'll assume it's a string.
70+
# Therefore, we'll make sure it's wrapped in quotes, so its eval'd as a string by Nix:
71+
echo "\"$1\""
72+
}
73+
6174
## Main ##
6275

6376
while [[ $# -gt 0 ]]; do
@@ -81,7 +94,8 @@ while [[ $# -gt 0 ]]; do
8194
shift
8295
;;
8396
--disk-size)
84-
nix_build_args+=("--argstr" "diskSize" "$2")
97+
# Note: make sure integers are not incorrectly interpreted as strings by Nix:
98+
nix_build_args+=("--arg" "diskSize" "$(fixDiskSizeFormat "$2")")
8599
shift
86100
;;
87101
--special-arg)

0 commit comments

Comments
 (0)