Skip to content

Commit 91f1f59

Browse files
make-disk-image: use nix path-info to automatically set the imageSize
1 parent 1144887 commit 91f1f59

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

lib/make-disk-image.nix

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ let
2424
util-linux
2525
];
2626
preVM = ''
27-
${lib.concatMapStringsSep "\n" (disk: "truncate -s ${disk.imageSize} ${disk.name}.raw") (lib.attrValues nixosConfig.config.disko.devices.disk)}
27+
export PATH=$PATH:${lib.makeBinPath (with pkgs; [ nix jq ])}
28+
export NIX_STATE_DIR=$TMPDIR/state
29+
export NIX_CONFIG="experimental-features = nix-command"
30+
nix-store --load-db < ${pkgs.closureInfo {
31+
rootPaths = [ systemToInstall.config.system.build.toplevel ];
32+
}}/registration
33+
34+
${lib.concatMapStringsSep "\n" (disk: "truncate -s $(($(set -x; nix path-info --json ${systemToInstall.config.system.build.toplevel} | jq .[].closureSize) + ${toString disk.imageSizeExtraBytes})) ${disk.name}.raw") (lib.attrValues nixosConfig.config.disko.devices.disk)}
2835
'';
2936
postVM = ''
3037
# shellcheck disable=SC2154

lib/types/disk.nix

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
type = diskoLib.optionTypes.absolute-pathname; # TODO check if subpath of /dev ? - No! eg: /.swapfile
1717
description = "Device path";
1818
};
19-
imageSize = lib.mkOption {
20-
type = lib.types.strMatching "[0-9]+[KMGTP]?";
19+
imageSizeExtraBytes = lib.mkOption {
20+
type = lib.types.int;
2121
description = ''
22-
size of the image if the makeDiskImages function from diksoLib is used.
23-
is used as an argument to truncate -s
22+
extra size in bytes to add to the end of the disk image if the makeDiskImages function from diksoLib is used.
23+
This is used as an argument to truncate -s
2424
'';
25-
default = "2G";
25+
default = 2000000000;
2626
};
2727
content = diskoLib.deviceType { parent = config; device = config.device; };
2828
_meta = lib.mkOption {

0 commit comments

Comments
 (0)