macs: build clover.qcow2 ourselves
Graham Christensen committed
Jun 5, 2019 at 15:13 UTC
ed324ccebb1624cf677ca919caffab82fb266c5d
6 files changed
+123
-34
delft/network.nix
-1
@@ -18,7 +18,6 @@ let
18
zvolName = "rpool/mac-hdd-2-initial-setup-startup-script.img";
19
ovmfCodeFile = ../macs/dist/OVMF_CODE.fd;
20
ovmfVarsFile = ../macs/dist/OVMF_VARS-1024x768.fd;
21
- cloverImage = ../macs/dist/Clover.qcow2;
21
guestConfigDir = ../macs/guest;
22
};
23
};
macs/build.nix
deleted
-32
@@ -1,32 +0,0 @@
1
-import <nixpkgs/nixos> {
2
-configuration = { pkgs, lib, config, ... }: {
3
- imports = [
4
- ./host/default.nix
5
- ];
6
- nixpkgs.config.allowUnfree = true;
7
-
8
- fileSystems."/" =
9
- { device = "rpool/root";
10
- fsType = "zfs";
11
- };
12
-
13
- networking.hostId = "aaaaaaaa";
14
- boot.loader.systemd-boot.enable = true;
15
- boot.loader.efi.canTouchEfiVariables = true;
16
-
17
- networking.hostName = "dummy";
18
- macosGuest.guest = {
19
- cores = 2;
20
- threads = 2;
21
- sockets = 2;
22
- memoryInMegs = 6 * 1024;
23
-
24
- zvolName = "rpool/example";
25
- guestConfigDir = ./guest;
26
-
27
- ovmfCodeFile = ./dist/OVMF_CODE.fd;
28
- ovmfVarsFile = ./dist/OVMF_VARS-1024x768.fd;
29
- cloverImage = ./dist/Clover.qcow2;
30
- };
31
- };
32
-}
macs/dist/Clover.qcow2
Binary files a/macs/dist/Clover.qcow2 and /dev/null differ
macs/dist/config.plist.template
new
+53
@@ -0,0 +1,53 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+<plist version="1.0">
4
+<dict>
5
+ <key>Boot</key>
6
+ <dict>
7
+ <key>Arguments</key>
8
+ <string>@params@</string>
9
+ <key>DefaultVolume</key>
10
+ <string>system</string>
11
+ <key>Log</key>
12
+ <true/>
13
+ <key>Secure</key>
14
+ <false/>
15
+ <key>Timeout</key>
16
+ <integer>@timeout@</integer>
17
+ </dict>
18
+ <key>GUI</key>
19
+ <dict>
20
+ <key>Scan</key>
21
+ <dict>
22
+ <key>Entries</key>
23
+ <true/>
24
+ <key>Tool</key>
25
+ <true/>
26
+ </dict>
27
+ <key>ScreenResolution</key>
28
+ <string>@resolution@</string>
29
+ <key>Theme</key>
30
+ <string>embedded</string>
31
+ </dict>
32
+ <key>RtVariables</key>
33
+ <dict>
34
+ <key>BooterConfig</key>
35
+ <string>0x28</string>
36
+ <key>CsrActiveConfig</key>
37
+ <string>@csrFlag@</string>
38
+ </dict>
39
+ <key>SMBIOS</key>
40
+ <dict>
41
+ <key>Trust</key>
42
+ <false/>
43
+ </dict>
44
+ <key>SystemParameters</key>
45
+ <dict>
46
+ <key>InjectKexts</key>
47
+ <false/>
48
+ <key>InjectSystemID</key>
49
+ <true/>
50
+ </dict>
51
+</dict>
52
+</plist>
53
+
macs/host/clover.qcow2.nix
new
+64
@@ -0,0 +1,64 @@
1
+{ lib
2
+, runCommand
3
+, fetchurl
4
+, libguestfs
5
+, libguestfs-appliance
6
+, resolution ? "1024x768"
7
+, csrFlag ? "0x3"
8
+, params ? "-v"
9
+, timeout ? "3"
10
+# https://github.com/Clover-EFI-Bootloader/clover/blob/6b8018b1fec958d672951f87cefd8b6cfd5318ac/rEFIt_UEFI/Platform/boot.h#L127-L135
11
+}:
12
+
13
+lib.fix (self: {
14
+ clover-image = runCommand "clover.qcow2" {
15
+ buildInputs = [ libguestfs ];
16
+ inherit resolution csrFlag params timeout;
17
+ LIBGUESTFS_PATH = libguestfs-appliance;
18
+ } ''
19
+ export HOME=$NIX_BUILD_TOP
20
+ mkdir work
21
+ cp --no-preserve=mode ${self.clover-iso} clover.iso
22
+ guestfish -a clover.iso -m "/dev/sda:/:norock" <<EOF
23
+ copy-out /EFI work
24
+ EOF
25
+ eval $(guestfish --listen)
26
+ guestfish --remote disk-create clover2.img qcow2 256M
27
+ guestfish --remote add clover2.img
28
+ time guestfish --remote run
29
+ guestfish --remote part-init /dev/sda gpt
30
+ guestfish --remote part-add /dev/sda p 2048 200000
31
+ guestfish --remote -- part-add /dev/sda p 202048 -2048
32
+ guestfish --remote part-set-gpt-type /dev/sda 1 C12A7328-F81F-11D2-BA4B-00A0C93EC93B
33
+ guestfish --remote part-set-bootable /dev/sda 1 true
34
+ guestfish --remote mkfs vfat /dev/sda1 label:EFI
35
+ guestfish --remote mkfs vfat /dev/sda2 label:clover
36
+ guestfish --remote mount /dev/sda2 /
37
+ guestfish --remote mkdir /ESP
38
+ guestfish --remote mount /dev/sda1 /ESP
39
+ guestfish --remote mkdir /ESP/EFI
40
+ guestfish --remote mkdir /ESP/EFI/CLOVER
41
+ guestfish --remote copy-in work/EFI/BOOT /ESP/EFI
42
+ guestfish --remote copy-in work/EFI/CLOVER/CLOVERX64.efi /ESP/EFI/CLOVER
43
+ guestfish --remote copy-in work/EFI/CLOVER/drivers64UEFI /ESP/EFI/CLOVER
44
+ guestfish --remote copy-in work/EFI/CLOVER/drivers-Off/drivers64UEFI/PartitionDxe-64.efi /ESP/EFI/CLOVER/drivers64UEFI
45
+ guestfish --remote copy-in work/EFI/CLOVER/drivers-Off/drivers64UEFI/ApfsDriverLoader-64.efi /ESP/EFI/CLOVER/drivers64UEFI
46
+ guestfish --remote copy-in work/EFI/CLOVER/drivers-Off/drivers64UEFI/OsxAptioFix3Drv-64.efi /ESP/EFI/CLOVER/drivers64UEFI
47
+ guestfish --remote copy-in work/EFI/CLOVER/tools /ESP/EFI/CLOVER
48
+ substituteAll ${./../dist/config.plist.template} work/config.plist
49
+ guestfish --remote copy-in work/config.plist /ESP/EFI/CLOVER
50
+ guestfish --remote rm /ESP/EFI/CLOVER/drivers64UEFI/AudioDxe-64.efi
51
+ guestfish --remote umount-all
52
+ guestfish --remote shutdown
53
+ mv clover2.img $out
54
+ '';
55
+ cloverVersion = "4934";
56
+ clover-iso-lzma = fetchurl {
57
+ url = "mirror://sourceforge/cloverefiboot/CloverISO-${self.cloverVersion}.tar.lzma";
58
+ sha256 = "0ivwaapgir2yvsyp7gi9ddj6r97j99n99cz0xwqhcrijimp06hcl";
59
+ };
60
+ clover-iso = runCommand "clover.iso" {} ''
61
+ tar -xvf ${self.clover-iso-lzma}
62
+ mv -v *.iso $out
63
+ '';
64
+})
macs/host/default.nix
+6
-1
@@ -1,5 +1,5 @@
1
2
-{ lib, config, ... }:
2
+{ pkgs, lib, config, ... }:
3
let
4
inherit (lib) mkOption types;
5
in {
@@ -197,6 +197,11 @@ in {
197
198
cloverImage = mkOption {
199
type = types.path;
200
+ default = (pkgs.callPackage ./clover.qcow2.nix {
201
+ # 0x23 means allow dtrace and untrusted kexts
202
+ # https://github.com/Clover-EFI-Bootloader/clover/blob/6b8018b1fec958d672951f87cefd8b6cfd5318ac/rEFIt_UEFI/Platform/boot.h#L127-L135
203
+ csrFlag = "0x23";
204
+ }).clover-image;
205
description = ''
206
Path to the Clover bootloader.
207
'';