-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
amazon-image.nix
82 lines (72 loc) · 2.39 KB
/
amazon-image.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
{ config, modulesPath, lib, pkgs, ... }:
let
efiArch = pkgs.stdenv.hostPlatform.efiArch;
in
{
imports = [
(modulesPath + "/image/repart.nix")
./amazon-profile.nix
];
system.build.amazonImage =
pkgs.runCommand config.system.build.image.name { } ''
mkdir -p $out
mkdir -p $out/nix-support
${pkgs.qemu-utils}/bin/qemu-img convert -f raw -O vpc ${config.system.build.image}/${config.image.repart.imageFile} $out/${config.image.repart.imageFileBasename}.vhd
cat <<EOF > $out/nix-support/image-info.json
{
"boot_mode": "uefi",
"label": "${config.system.nixos.label}",
"system": "${pkgs.stdenv.hostPlatform.system}",
"file": "$out/${config.image.repart.imageFileBasename}.vhd"
}
EOF
'';
image.repart.name = "${config.system.nixos.distroId}-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}";
image.repart.partitions = {
"00-esp" = {
contents = {
"/EFI/systemd/systemd-boot${efiArch}.efi".source =
"${pkgs.systemd}/lib/systemd/boot/efi/systemd-boot${efiArch}.efi";
"/EFI/BOOT/BOOT${lib.toUpper efiArch}.EFI".source =
"${pkgs.systemd}/lib/systemd/boot/efi/systemd-boot${efiArch}.efi";
# TODO: nixos-generation-1.conf
"/loader/entries/nixos.conf".source = pkgs.writeText "nixos.conf" ''
title NixOS
linux /EFI/nixos/kernel.efi
initrd /EFI/nixos/initrd.efi
options init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams}
'';
"/EFI/nixos/kernel.efi".source =
"${config.boot.kernelPackages.kernel}/${config.system.boot.loader.kernelFile}";
"/EFI/nixos/initrd.efi".source =
"${config.system.build.initialRamdisk}/${config.system.boot.loader.initrdFile}";
};
repartConfig = {
Type = "esp";
Format = "vfat";
SizeMinBytes = "1G";
};
};
"01-root" = {
storePaths = [ config.system.build.toplevel ];
repartConfig = {
Type = "root";
Label = "nixos";
Format = "ext4";
Minimize = "guess";
GrowFileSystem = true;
};
};
};
systemd.repart.enable = true;
systemd.repart.partitions = {
"01-root" = { Type = "root"; };
};
fileSystems = {
"/" = {
device = "/dev/disk/by-partlabel/nixos";
fsType = "ext4";
autoResize = true;
};
};
}