-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.nix
132 lines (130 loc) · 4.29 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
crane.url = "github:ipetkov/crane";
crane.inputs.nixpkgs.follows = "nixpkgs";
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs = {
nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
nixpkgs,
flake-parts,
crane,
rust-overlay,
...
}@inputs:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ flake-parts.flakeModules.easyOverlay ];
systems = nixpkgs.lib.platforms.all;
perSystem =
{
pkgs,
system,
lib,
self',
...
}:
let
platform = lib.systems.elaborate system;
inherit (if platform.isx86_64 -> platform.isDarwin then pkgs.pkgsCross.x86_64-embedded else pkgs)
OVMF
;
toolchain = p: p.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
buildCargoPackage = import ./nix/build-rust-app.nix { inherit craneLib lib; };
in
{
packages =
let
extraExclude = [
./rust-toolchain.toml
./nix
./apps
./demo
./.github
];
extraInclude = [ ./src/vm/genop.tab ];
src = lib.cleanSourceWith {
filter = (
path: type:
(!builtins.elem path (map toString extraExclude))
&& (craneLib.filterCargoSources path type || builtins.elem path (map toString extraInclude))
);
src = ./.;
name = "source";
};
boss = buildCargoPackage {
doCheck = false;
fixBuildStd = true;
inherit src;
target = ./x86_64-boss-uefi.json;
extraArgs = {
# https://github.com/ipetkov/crane/issues/262
dummyrs = ./nix/dummy.rs;
};
};
inherit (pkgs.callPackage ./nix { }) buildEmulator bosbaima buildIso;
in
{
kernel = boss.package;
inherit (boss)
audit
clippy
rustdoc
rustfmt
deps
;
emulator = buildEmulator {
src = lib.getExe' self'.packages.kernel "boss.efi";
magic-offset = "0x141000000";
reloc-offset = "0x141001000";
};
bosbaima = bosbaima.override {
bossApps =
let
apps = self'.legacyPackages.bossApps;
in
[ apps.base ];
};
iso = buildIso {
inherit (self'.packages) bosbaima;
boss-emulator = self'.packages.emulator;
};
qemu = pkgs.writeShellApplication {
name = "qemu-boss";
runtimeInputs = [ pkgs.qemu ];
text = ''
qemu-system-x86_64 \
-drive if=pflash,format=raw,readonly=on,file=${lib.escapeShellArg OVMF.fd}/FV/OVMF.fd \
-device ahci,id=ahci \
-device ide-hd,drive=disk,bus=ahci.0 \
-drive if=none,id=disk,format=raw,snapshot=on,file=${lib.escapeShellArg self'.packages.iso} \
-m 128 \
-smp 1,sockets=1,cores=1,threads=1 \
-boot menu=off,splash-time=0 \
-serial stdio
'';
};
};
legacyPackages = {
inherit (pkgs.callPackage ./nix/boss-lib { }) buildBossApp;
bossApps = {
base = self'.legacyPackages.buildBossApp {
src = ./apps/base;
pname = "base";
version = "0.1.0";
};
};
};
apps.default.program = self'.packages.qemu;
_module.args.pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
};
};
}