Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

make-disk-image: Add an argument to only build a Nix store image

Add the `onlyNixStore` argument which enables building images
containing the contents of the Nix store at the root, instead of a
full system.

authored by talyz and committed by Yuka 46f75211 ed2497b4

+32 -17
+32 -17
nixos/lib/make-disk-image.nix
··· 51 fsType ? "ext4" 52 53 , # Filesystem label 54 - label ? "nixos" 55 56 , # The initial NixOS configuration file to be copied to 57 # /etc/nixos/configuration.nix. ··· 59 60 , # Shell code executed after the VM has finished. 61 postVM ? "" 62 63 , name ? "nixos-disk-image" 64 ··· 83 (attrs: ((attrs.user or null) == null) 84 == ((attrs.group or null) == null)) 85 contents; 86 87 with lib; 88 ··· 345 ''} 346 347 echo "copying staging root to image..." 348 - cptofs -p ${optionalString (partitionTableType != "none") "-P ${rootPartition}"} -t ${fsType} -i $diskImage $root/* / || 349 (echo >&2 "ERROR: cptofs failed. diskSize might be too small for closure."; exit 1) 350 ''; 351 - in pkgs.vmTools.runInLinuxVM ( 352 - pkgs.runCommand name 353 - { preVM = prepareImage; 354 buildInputs = with pkgs; [ util-linux e2fsprogs dosfstools ]; 355 - postVM = '' 356 - ${if format == "raw" then '' 357 - mv $diskImage $out/${filename} 358 - '' else '' 359 - ${pkgs.qemu}/bin/qemu-img convert -f raw -O ${format} ${compress} $diskImage $out/${filename} 360 - ''} 361 - diskImage=$out/${filename} 362 - ${postVM} 363 - ''; 364 memSize = 1024; 365 - } 366 - '' 367 export PATH=${binPath}:$PATH 368 369 rootDisk=${if partitionTableType != "none" then "/dev/vda${rootPartition}" else "/dev/vda"} ··· 425 tune2fs -T now -c 0 -i 0 $rootDisk 426 ''} 427 '' 428 - )
··· 51 fsType ? "ext4" 52 53 , # Filesystem label 54 + label ? if onlyNixStore then "nix-store" else "nixos" 55 56 , # The initial NixOS configuration file to be copied to 57 # /etc/nixos/configuration.nix. ··· 59 60 , # Shell code executed after the VM has finished. 61 postVM ? "" 62 + 63 + , # Copy the contents of the Nix store to the root of the image and 64 + # skip further setup. Incompatible with `contents`, 65 + # `installBootLoader` and `configFile`. 66 + onlyNixStore ? false 67 68 , name ? "nixos-disk-image" 69 ··· 88 (attrs: ((attrs.user or null) == null) 89 == ((attrs.group or null) == null)) 90 contents; 91 + assert onlyNixStore -> contents == [] && configFile == null && !installBootLoader; 92 93 with lib; 94 ··· 351 ''} 352 353 echo "copying staging root to image..." 354 + cptofs -p ${optionalString (partitionTableType != "none") "-P ${rootPartition}"} \ 355 + -t ${fsType} \ 356 + -i $diskImage \ 357 + $root${optionalString onlyNixStore builtins.storeDir}/* / || 358 (echo >&2 "ERROR: cptofs failed. diskSize might be too small for closure."; exit 1) 359 ''; 360 + 361 + moveOrConvertImage = '' 362 + ${if format == "raw" then '' 363 + mv $diskImage $out/${filename} 364 + '' else '' 365 + ${pkgs.qemu}/bin/qemu-img convert -f raw -O ${format} ${compress} $diskImage $out/${filename} 366 + ''} 367 + diskImage=$out/${filename} 368 + ''; 369 + 370 + buildImage = pkgs.vmTools.runInLinuxVM ( 371 + pkgs.runCommand name { 372 + preVM = prepareImage; 373 buildInputs = with pkgs; [ util-linux e2fsprogs dosfstools ]; 374 + postVM = moveOrConvertImage + postVM; 375 memSize = 1024; 376 + } '' 377 export PATH=${binPath}:$PATH 378 379 rootDisk=${if partitionTableType != "none" then "/dev/vda${rootPartition}" else "/dev/vda"} ··· 435 tune2fs -T now -c 0 -i 0 $rootDisk 436 ''} 437 '' 438 + ); 439 + in 440 + if onlyNixStore then 441 + pkgs.runCommand name {} 442 + (prepareImage + moveOrConvertImage + postVM) 443 + else buildImage