Skip to content

Commit

Permalink
Merge pull request #1 from thecaralice/nix
Browse files Browse the repository at this point in the history
Add a Nix flake
  • Loading branch information
portasynthinca3 authored Aug 8, 2024
2 parents 997c70c + 914ddf9 commit eb46411
Show file tree
Hide file tree
Showing 14 changed files with 497 additions and 6 deletions.
17 changes: 12 additions & 5 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ debug = true
incremental = false
opt-level = 0
rustflags = [
"-Cembed-bitcode=no",
"-Crelocation-model=pie",
"-Cdebuginfo=2",
"-Zmacro-backtrace",
"-Cembed-bitcode=no",
"-Crelocation-model=pie",
"-Cdebuginfo=2",
"-Zmacro-backtrace",
]

[profile.release.build-override]
opt-level=3
opt-level = 3

[unstable]
build-std-features = ["compiler-builtins-mem"]
build-std = ["core", "compiler_builtins", "alloc"]

[build]
target = "x86_64-boss-uefi.json"
100 changes: 100 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

132 changes: 132 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,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) ];
};
};
};
}
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bosbaima:
profile := "release" # "dev" or "release"
profile_dir := "release" # "debug" or "release"
features := ","
cargo_flags := "--target x86_64-boss-uefi.json -Zbuild-std=core,compiler_builtins,alloc -Zbuild-std-features=compiler-builtins-mem --profile " + profile + " --features " + features
cargo_flags := "--profile " + profile + " --features " + features
magic_section_offset := "0x141000000"
reloc_section_offset := "0x141001000"
# EFI executable
Expand Down
28 changes: 28 additions & 0 deletions nix/bosbaima.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
stdenvNoCC,
lib,
bossApps ? [ ],
}:
stdenvNoCC.mkDerivation {
pname = "bosbaima";
version = "0.1.0";

dontUnpack = true;
dontBuild = true;

installPhase =
''
mkdir -p "$out"
''
+ lib.concatLines (
map (
app:
# sh
''
cp ${lib.escapeShellArg app.bop} "$out"/${lib.escapeShellArg app.app-name}.bop
'') bossApps
);
passthru = {
apps = bossApps;
};
}
54 changes: 54 additions & 0 deletions nix/boss-lib/build-boss-app.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
erlang_27,
stdenv,
etfify,
lib,
}:
{
pname,
version,
src,
app-name ? pname,
...
}@args:
stdenv.mkDerivation (
{
inherit pname version src;
outputs = [
"out"
"bop"
];
nativeBuildInputs = [
erlang_27
etfify
];
buildPhase = ''
runHook preBuild
mkdir build
find src/ -name '*.erl' -exec erlc -b beam -o build/ '{}' +
etfify src/${lib.escapeShellArg app-name}.app.src app
runHook postBuild
'';
installPhase = ''
runHook preInstall
mv build "$out"
mv app "$out"/
tar --create --file="$bop" --directory="$out" --transform='s%\.%ebin%' .
runHook postInstall
'';
passthru = {
inherit app-name;
};
}
// builtins.removeAttrs args [
"pname"
"version"
"src"
"app-name"
]
)
7 changes: 7 additions & 0 deletions nix/boss-lib/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ callPackage }:
let
etfify = callPackage ./etfify.nix { };
in
{
buildBossApp = callPackage ./build-boss-app.nix { inherit etfify; };
}
22 changes: 22 additions & 0 deletions nix/boss-lib/etfify.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{ erlang_27, stdenvNoCC }:
stdenvNoCC.mkDerivation {
pname = "etfify";
version = "0.1.0";
src = ../../apps/etfify;
dontUnpack = true;
dontPatch = true;
dontConfigure = true;
dontBuild = true;

buildInputs = [ erlang_27 ];
installPhase = ''
runHook preInstall
mkdir -p "$out/bin"
install -m 0555 "$src" "$out/bin/etfify"
runHook postInstall
'';

meta.mainProgram = "etfify";
}
Loading

0 comments on commit eb46411

Please sign in to comment.