Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make-disk-image: use nix path-info to automatically set the imageSize #465

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/make-disk-image.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ let
util-linux
];
preVM = ''
${lib.concatMapStringsSep "\n" (disk: "truncate -s ${disk.imageSize} ${disk.name}.raw") (lib.attrValues nixosConfig.config.disko.devices.disk)}
export PATH=$PATH:${lib.makeBinPath (with pkgs; [ nix jq ])}
export NIX_STATE_DIR=$TMPDIR/state
export NIX_CONFIG="experimental-features = nix-command"
nix-store --load-db < ${pkgs.closureInfo {
rootPaths = [ systemToInstall.config.system.build.toplevel ];
}}/registration

${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)}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newlines could help to make that more readable. and probably using '' instead of "

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also assign variables so that in the event of a failure it's easier to spot which part failed.

'';
postVM = ''
# shellcheck disable=SC2154
Expand Down
10 changes: 5 additions & 5 deletions lib/types/disk.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
type = diskoLib.optionTypes.absolute-pathname; # TODO check if subpath of /dev ? - No! eg: /.swapfile
description = "Device path";
};
imageSize = lib.mkOption {
type = lib.types.strMatching "[0-9]+[KMGTP]?";
imageSizeExtraBytes = lib.mkOption {
type = lib.types.int;
description = ''
size of the image if the makeDiskImages function from diksoLib is used.
is used as an argument to truncate -s
extra size in bytes to add to the end of the disk image if the makeDiskImages function from diksoLib is used.
This is used as an argument to truncate -s
'';
default = "2G";
default = 2000000000;
};
content = diskoLib.deviceType { parent = config; device = config.device; };
_meta = lib.mkOption {
Expand Down