@@ -24,6 +24,7 @@ in
2424
2525 postVM =
2626 ''
27+ echo Converting
2728 mkdir -p $out
2829 ${pkgs.vmTools.qemu}/bin/qemu-img convert -f raw -O vpc $diskImage $out/disk.vhd
2930 rm $diskImage
@@ -62,30 +63,31 @@ in
6263 echo "copying everything (will take a while)..."
6364 cp -prd $storePaths /mnt/nix/store/
6465
65− # Register the paths in the Nix database.
66+ echo Register the paths in the Nix database.
6667 printRegistration=1 perl ${pkgs.pathsFromGraph} /tmp/xchg/closure | \
67− chroot /mnt ${config.nix.package}/bin/nix-store --load-db
68+ chroot /mnt ${config.nix.package}/bin/nix-store --load-db --option build-users-group ""
6869
69− # Create the system profile to allow nixos-rebuild to work.
70+ echo Create the system profile to allow nixos-rebuild to work.
7071 chroot /mnt ${config.nix.package}/bin/nix-env \
71− -p /nix/var/nix/profiles/system --set ${config.system.build.toplevel}
72+ -p /nix/var/nix/profiles/system --set ${config.system.build.toplevel} --option build-users-group ""
7273
73− # `nixos-rebuild' requires an /etc/NIXOS.
74+ echo nixos-rebuild requires an /etc/NIXOS.
7475 mkdir -p /mnt/etc
7576 touch /mnt/etc/NIXOS
7677
77− # `switch-to-configuration' requires a /bin/sh
78+ echo switch-to-configuration requires a /bin/sh
7879 mkdir -p /mnt/bin
7980 ln -s ${config.system.build.binsh}/bin/sh /mnt/bin/sh
8081
81− # Install a configuration.nix.
82+ echo Install a configuration.nix.
8283 mkdir -p /mnt/etc/nixos /mnt/boot/grub
8384 cp ${./azure-config.nix} /mnt/etc/nixos/configuration.nix
8485
85− # Generate the GRUB menu.
86+ echo Generate the GRUB menu.
8687 ln -s vda /dev/sda
8788 chroot /mnt ${config.system.build.toplevel}/bin/switch-to-configuration boot
8889
90+ echo Almost done
8991 umount /mnt/proc /mnt/dev /mnt/sys
9092 umount /mnt
9193 ''
@@ -119,7 +121,44 @@ in
119121 # Always include cryptsetup so that NixOps can use it.
120122 environment.systemPackages = [ pkgs.cryptsetup ];
121123
124+ systemd.services.fetch-ssh-keys =
125+ { description = "Fetch host keys and authorized_keys for root user";
126+
127+ wantedBy = [ "sshd.service" ];
128+ before = [ "sshd.service" ];
129+ after = [ "local-fs.target" ];
130+
131+ path = [ pkgs.coreutils ];
132+ script =
133+ ''
134+ eval "$(base64 --decode /metadata/CustomData.bin)"
135+ if ! [ -z "$ssh_host_ecdsa_key" ]; then
136+ echo "downloaded ssh_host_ecdsa_key"
137+ echo "$ssh_host_ecdsa_key" > /etc/ssh/ssh_host_ecdsa_key
138+ chmod 600 /etc/ssh/ssh_host_ecdsa_key
139+ fi
140+
141+ if ! [ -z "$ssh_host_ecdsa_key_pub" ]; then
142+ echo "downloaded ssh_host_ecdsa_key_pub"
143+ echo "$ssh_host_ecdsa_key_pub" > /etc/ssh/ssh_host_ecdsa_key.pub
144+ chmod 644 /etc/ssh/ssh_host_ecdsa_key.pub
145+ fi
146+
147+ if ! [ -z "$ssh_root_auth_key" ]; then
148+ echo "downloaded ssh_root_auth_key"
149+ mkdir -m 0700 -p /root/.ssh
150+ echo "$ssh_root_auth_key" > /root/.ssh/authorized_keys
151+ chmod 600 /root/.ssh/authorized_keys
152+ fi
153+ '';
154+ serviceConfig.Type = "oneshot";
155+ serviceConfig.RemainAfterExit = true;
156+ serviceConfig.StandardError = "journal+console";
157+ serviceConfig.StandardOutput = "journal+console";
158+ };
159+
122160 networking.usePredictableInterfaceNames = false;
123161
124− users.extraUsers.root.openssh.authorizedKeys.keys = [ (builtins.readFile <ssh-pub-key>) ];
162+ #users.extraUsers.root.openssh.authorizedKeys.keys = [ (builtins.readFile <ssh-pub-key>) ];
163+
125164}