about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorTuomas Tynkkynen <tuomas@tuxera.com>2018-03-31 20:27:45 +0300
committerTuomas Tynkkynen <tuomas@tuxera.com>2018-04-02 15:18:25 +0300
commit4c21180a1303fdafa556fb83d9b6839b2eeb0616 (patch)
treeeee0bbb575ead33c660958429325efa88d0d3f47 /nixos
parente410315f18f5b350c8ee1381218d83a54818f473 (diff)
downloadnixlib-4c21180a1303fdafa556fb83d9b6839b2eeb0616.tar
nixlib-4c21180a1303fdafa556fb83d9b6839b2eeb0616.tar.gz
nixlib-4c21180a1303fdafa556fb83d9b6839b2eeb0616.tar.bz2
nixlib-4c21180a1303fdafa556fb83d9b6839b2eeb0616.tar.lz
nixlib-4c21180a1303fdafa556fb83d9b6839b2eeb0616.tar.xz
nixlib-4c21180a1303fdafa556fb83d9b6839b2eeb0616.tar.zst
nixlib-4c21180a1303fdafa556fb83d9b6839b2eeb0616.zip
nixos/sd-image: Make it more similar to iso-image.nix
- Add `imageName` and `imageBaseName` options similar to the `isoName`
  and `isoBaseName` options
- Make the filename of the iso match what iso-image.nix does
- Generate a nix-support/hydra-build-products like iso-image.nix does
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/installer/cd-dvd/sd-image.nix34
1 files changed, 27 insertions, 7 deletions
diff --git a/nixos/modules/installer/cd-dvd/sd-image.nix b/nixos/modules/installer/cd-dvd/sd-image.nix
index 23312c073d56..c091923de60f 100644
--- a/nixos/modules/installer/cd-dvd/sd-image.nix
+++ b/nixos/modules/installer/cd-dvd/sd-image.nix
@@ -20,6 +20,20 @@ let
 in
 {
   options.sdImage = {
+    imageName = mkOption {
+      default = "${config.sdImage.imageBaseName}-${config.system.nixos.label}-${pkgs.stdenv.system}.img";
+      description = ''
+        Name of the generated image file.
+      '';
+    };
+
+    imageBaseName = mkOption {
+      default = "nixos-sd-image";
+      description = ''
+        Prefix of the name of the generated image file.
+      '';
+    };
+
     storePaths = mkOption {
       type = with types; listOf package;
       example = literalExample "[ pkgs.stdenv ]";
@@ -61,19 +75,25 @@ in
     sdImage.storePaths = [ config.system.build.toplevel ];
 
     system.build.sdImage = pkgs.stdenv.mkDerivation {
-      name = "sd-image-${pkgs.stdenv.system}.img";
+      name = config.sdImage.imageName;
 
       buildInputs = with pkgs; [ dosfstools e2fsprogs mtools libfaketime utillinux ];
 
       buildCommand = ''
+        mkdir -p $out/nix-support $out/sd-image
+        export img=$out/sd-image/${config.sdImage.imageName}
+
+        echo "${pkgs.stdenv.system}" > $out/nix-support/system
+        echo "file sd-image $img" >> $out/nix-support/hydra-build-products
+
         # Create the image file sized to fit /boot and /, plus 20M of slack
         rootSizeBlocks=$(du -B 512 --apparent-size ${rootfsImage} | awk '{ print $1 }')
         bootSizeBlocks=$((${toString config.sdImage.bootSize} * 1024 * 1024 / 512))
         imageSize=$((rootSizeBlocks * 512 + bootSizeBlocks * 512 + 20 * 1024 * 1024))
-        truncate -s $imageSize $out
+        truncate -s $imageSize $img
 
         # type=b is 'W95 FAT32', type=83 is 'Linux'.
-        sfdisk $out <<EOF
+        sfdisk $img <<EOF
             label: dos
             label-id: 0x2178694e
 
@@ -82,11 +102,11 @@ in
         EOF
 
         # Copy the rootfs into the SD image
-        eval $(partx $out -o START,SECTORS --nr 2 --pairs)
-        dd conv=notrunc if=${rootfsImage} of=$out seek=$START count=$SECTORS
+        eval $(partx $img -o START,SECTORS --nr 2 --pairs)
+        dd conv=notrunc if=${rootfsImage} of=$img seek=$START count=$SECTORS
 
         # Create a FAT32 /boot partition of suitable size into bootpart.img
-        eval $(partx $out -o START,SECTORS --nr 1 --pairs)
+        eval $(partx $img -o START,SECTORS --nr 1 --pairs)
         truncate -s $((SECTORS * 512)) bootpart.img
         faketime "1970-01-01 00:00:00" mkfs.vfat -i 0x2178694e -n NIXOS_BOOT bootpart.img
 
@@ -96,7 +116,7 @@ in
 
         # Copy the populated /boot into the SD image
         (cd boot; mcopy -bpsvm -i ../bootpart.img ./* ::)
-        dd conv=notrunc if=bootpart.img of=$out seek=$START count=$SECTORS
+        dd conv=notrunc if=bootpart.img of=$img seek=$START count=$SECTORS
       '';
     };