tangled
alpha
login
or
join now
tjh.dev
/
nixpkgs
Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
0
fork
atom
overview
issues
pulls
pipelines
azure-image: switch to use the common make-disk-image.nix
Dan Peebles
8 years ago
ee2cffbd
3ab98d09
+11
-85
1 changed file
expand all
collapse all
unified
split
nixos
modules
virtualisation
azure-image.nix
+11
-85
nixos/modules/virtualisation/azure-image.nix
···
2
2
3
3
with lib;
4
4
let
5
5
-
diskSize = "30720";
5
5
+
diskSize = 30720;
6
6
in
7
7
{
8
8
-
system.build.azureImage =
9
9
-
pkgs.vmTools.runInLinuxVM (
10
10
-
pkgs.runCommand "azure-image"
11
11
-
{ preVM =
12
12
-
''
13
13
-
mkdir $out
14
14
-
diskImage=$out/$diskImageBase
15
15
-
16
16
-
cyl=$(((${diskSize}*1024*1024)/(512*63*255)))
17
17
-
size=$(($cyl*255*63*512))
18
18
-
roundedsize=$((($size/(1024*1024)+1)*(1024*1024)))
19
19
-
${pkgs.vmTools.qemu-220}/bin/qemu-img create -f raw $diskImage $roundedsize
20
20
-
mv closure xchg/
21
21
-
'';
22
22
-
23
23
-
postVM =
24
24
-
''
25
25
-
mkdir -p $out
26
26
-
${pkgs.vmTools.qemu-220}/bin/qemu-img convert -f raw -o subformat=fixed -O vpc $diskImage $out/disk.vhd
27
27
-
rm $diskImage
28
28
-
'';
29
29
-
diskImageBase = "nixos-image-${config.system.nixosLabel}-${pkgs.stdenv.system}.raw";
30
30
-
buildInputs = [ pkgs.utillinux pkgs.perl ];
31
31
-
exportReferencesGraph =
32
32
-
[ "closure" config.system.build.toplevel ];
33
33
-
}
34
34
-
''
35
35
-
# Create partition table
36
36
-
${pkgs.parted}/sbin/parted /dev/vda mklabel msdos
37
37
-
${pkgs.parted}/sbin/parted /dev/vda mkpart primary ext4 1 ${diskSize}M
38
38
-
${pkgs.parted}/sbin/parted /dev/vda print
39
39
-
. /sys/class/block/vda1/uevent
40
40
-
mknod /dev/vda1 b $MAJOR $MINOR
41
41
-
42
42
-
# Create an empty filesystem and mount it.
43
43
-
${pkgs.e2fsprogs}/sbin/mkfs.ext4 -L nixos /dev/vda1
44
44
-
${pkgs.e2fsprogs}/sbin/tune2fs -c 0 -i 0 /dev/vda1
45
45
-
46
46
-
mkdir /mnt
47
47
-
mount /dev/vda1 /mnt
48
48
-
49
49
-
# The initrd expects these directories to exist.
50
50
-
mkdir /mnt/dev /mnt/proc /mnt/sys
51
51
-
52
52
-
mount --bind /proc /mnt/proc
53
53
-
mount --bind /dev /mnt/dev
54
54
-
mount --bind /sys /mnt/sys
55
55
-
56
56
-
# Copy all paths in the closure to the filesystem.
57
57
-
storePaths=$(perl ${pkgs.pathsFromGraph} /tmp/xchg/closure)
58
58
-
59
59
-
mkdir -p /mnt/nix/store
60
60
-
echo "copying everything (will take a while)..."
61
61
-
cp -prd $storePaths /mnt/nix/store/
62
62
-
63
63
-
echo Register the paths in the Nix database.
64
64
-
printRegistration=1 perl ${pkgs.pathsFromGraph} /tmp/xchg/closure | \
65
65
-
chroot /mnt ${config.nix.package.out}/bin/nix-store --load-db --option build-users-group ""
66
66
-
67
67
-
echo Create the system profile to allow nixos-rebuild to work.
68
68
-
chroot /mnt ${config.nix.package.out}/bin/nix-env \
69
69
-
-p /nix/var/nix/profiles/system --set ${config.system.build.toplevel} --option build-users-group ""
70
70
-
71
71
-
echo nixos-rebuild requires an /etc/NIXOS.
72
72
-
mkdir -p /mnt/etc
73
73
-
touch /mnt/etc/NIXOS
74
74
-
75
75
-
echo switch-to-configuration requires a /bin/sh
76
76
-
mkdir -p /mnt/bin
77
77
-
ln -s ${config.system.build.binsh}/bin/sh /mnt/bin/sh
78
78
-
79
79
-
echo Install a configuration.nix.
80
80
-
mkdir -p /mnt/etc/nixos /mnt/boot/grub
81
81
-
cp ${./azure-config-user.nix} /mnt/etc/nixos/configuration.nix
82
82
-
83
83
-
echo Generate the GRUB menu.
84
84
-
ln -s vda /dev/sda
85
85
-
chroot /mnt ${config.system.build.toplevel}/bin/switch-to-configuration boot
86
86
-
87
87
-
echo Almost done
88
88
-
umount /mnt/proc /mnt/dev /mnt/sys
89
89
-
umount /mnt
90
90
-
''
91
91
-
);
8
8
+
system.build.azureImage = import ../../lib/make-disk-image.nix {
9
9
+
name = "azure-image";
10
10
+
postVM = ''
11
11
+
${pkgs.vmTools.qemu-220}/bin/qemu-img convert -f raw -o subformat=fixed -O vpc $diskImage $out/disk.vhd
12
12
+
'';
13
13
+
configFile = ./azure-config-user.nix;
14
14
+
format = "raw";
15
15
+
inherit diskSize;
16
16
+
inherit config lib pkgs;
17
17
+
};
92
18
93
19
imports = [ ./azure-common.nix ];
94
20