-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
90 lines (88 loc) · 2.94 KB
/
flake.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
83
84
85
86
87
88
89
90
{
description = "a barebones UEFI implementation of the game snake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-parts.url = "github:hercules-ci/flake-parts";
default-systems.url = "github:nix-systems/default";
};
outputs = inputs @ { self, ... }:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = (import inputs.default-systems);
perSystem = { pkgs, ... }: let
name = "snakefi";
version = "1.0.2";
in {
packages = rec {
default = pkgs.stdenv.mkDerivation {
pname = "${name}";
inherit version;
src = self;
# we're doing some seriously questionable cross-compilation shenanigans
# and nix's normally great security practices just breaks things.
hardeningDisable = [ "pic" "stackprotector" ];
installPhase = ''
mkdir -p $out/share
cp BOOTX64.EFI $out/share
'';
buildInputs = with pkgs; [
gnu-efi
lld_16
llvmPackages_16.clang
];
};
image = pkgs.stdenv.mkDerivation {
pname = "${name}-vm-image";
inherit version;
# this is a no-op for unpack, since this derivation has no sources
unpackPhase = "true";
buildPhase = ''
dd if=/dev/zero of=snakEFI.img bs=1k count=1440
mformat -i snakEFI.img -f 1440 ::
mmd -i snakEFI.img ::/EFI
mmd -i snakEFI.img ::/EFI/BOOT
mcopy -o -s -i snakEFI.img ${default}/share/BOOTX64.EFI ::/EFI/BOOT
'';
installPhase = ''
mkdir -p $out/share
cp snakEFI.img $out/share
'';
nativeBuildInputs = [
pkgs.mtools
default
];
};
vm = pkgs.writeShellApplication {
name = "${name}-vm-wrapper";
runtimeInputs = [
pkgs.OVMF
pkgs.qemu
default
image
];
text = ''
cd "$(realpath "$(dirname "$0")")"
IMG_TMP="$(mktemp -d)"
trap 'rm -rf "$IMG_TMP"' EXIT
cp --no-preserve=mode,ownership ${image}/share/snakEFI.img "$IMG_TMP"
cp --no-preserve=mode,ownership ${pkgs.OVMF.fd}/FV/OVMF_CODE.fd "$IMG_TMP"
${pkgs.qemu}/bin/qemu-system-x86_64 \
-drive if=pflash,format=raw,file="$IMG_TMP/OVMF_CODE.fd" \
-drive format=raw,file="$IMG_TMP/snakEFI.img"
'';
};
};
devShells.default = pkgs.mkShell {
inherit name;
inherit version;
hardeningDisable = [ "pic" "stackprotector" ];
packages = with pkgs; [
gnu-efi
clang-tools
clang
lld
bear
];
};
};
};
}