git.iko.soy/typeable/nixpkgs
on master help sign in
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

commit4c21180a1303fdafa556fb83d9b6839b2eeb0616 authorTuomas Tynkkynen <tuomas@tuxera.com> dateSat 31 Mar 2018, 20:27 (9 years ago) parente410315
1 file changed+27−7
nixos/modules/installer/cd-dvd/sd-image.nix+27−7
nixos/modules/installer/cd-dvd/sd-image.nix+27−7
@@ -20,6 +20,20 @@ let
2020in
2121{
2222 options.sdImage = {
23+ imageName = mkOption {
24+ default = "${config.sdImage.imageBaseName}-${config.system.nixos.label}-${pkgs.stdenv.system}.img";
25+ description = ''
26+ Name of the generated image file.
27+ '';
28+ };
29+
30+ imageBaseName = mkOption {
31+ default = "nixos-sd-image";
32+ description = ''
33+ Prefix of the name of the generated image file.
34+ '';
35+ };
36+
2337 storePaths = mkOption {
2438 type = with types; listOf package;
2539 example = literalExample "[ pkgs.stdenv ]";
@@ -61,19 +75,25 @@ in
6175 sdImage.storePaths = [ config.system.build.toplevel ];
6276
6377 system.build.sdImage = pkgs.stdenv.mkDerivation {
64− name = "sd-image-${pkgs.stdenv.system}.img";
78+ name = config.sdImage.imageName;
6579
6680 buildInputs = with pkgs; [ dosfstools e2fsprogs mtools libfaketime utillinux ];
6781
6882 buildCommand = ''
83+ mkdir -p $out/nix-support $out/sd-image
84+ export img=$out/sd-image/${config.sdImage.imageName}
85+
86+ echo "${pkgs.stdenv.system}" > $out/nix-support/system
87+ echo "file sd-image $img" >> $out/nix-support/hydra-build-products
88+
6989 # Create the image file sized to fit /boot and /, plus 20M of slack
7090 rootSizeBlocks=$(du -B 512 --apparent-size ${rootfsImage} | awk '{ print $1 }')
7191 bootSizeBlocks=$((${toString config.sdImage.bootSize} * 1024 * 1024 / 512))
7292 imageSize=$((rootSizeBlocks * 512 + bootSizeBlocks * 512 + 20 * 1024 * 1024))
73− truncate -s $imageSize $out
93+ truncate -s $imageSize $img
7494
7595 # type=b is 'W95 FAT32', type=83 is 'Linux'.
76− sfdisk $out <<EOF
96+ sfdisk $img <<EOF
7797 label: dos
7898 label-id: 0x2178694e
7999
@@ -82,11 +102,11 @@ in
82102 EOF
83103
84104 # Copy the rootfs into the SD image
85− eval $(partx $out -o START,SECTORS --nr 2 --pairs)
86− dd conv=notrunc if=${rootfsImage} of=$out seek=$START count=$SECTORS
105+ eval $(partx $img -o START,SECTORS --nr 2 --pairs)
106+ dd conv=notrunc if=${rootfsImage} of=$img seek=$START count=$SECTORS
87107
88108 # Create a FAT32 /boot partition of suitable size into bootpart.img
89− eval $(partx $out -o START,SECTORS --nr 1 --pairs)
109+ eval $(partx $img -o START,SECTORS --nr 1 --pairs)
90110 truncate -s $((SECTORS * 512)) bootpart.img
91111 faketime "1970-01-01 00:00:00" mkfs.vfat -i 0x2178694e -n NIXOS_BOOT bootpart.img
92112
@@ -96,7 +116,7 @@ in
96116
97117 # Copy the populated /boot into the SD image
98118 (cd boot; mcopy -bpsvm -i ../bootpart.img ./* ::)
99− dd conv=notrunc if=bootpart.img of=$out seek=$START count=$SECTORS
119+ dd conv=notrunc if=bootpart.img of=$img seek=$START count=$SECTORS
100120 '';
101121 };
102122