Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ build_i686/
build_x86_64/
build_conan/

# nix
/result

# ignore log files in test tree
test/**/*.log

Expand Down
2 changes: 2 additions & 0 deletions example/vm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
63 changes: 63 additions & 0 deletions flake.lock

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

92 changes: 92 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
description = "IncludeOS";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/25.05";
vmrunner.url = "github:includeos/vmrunner";
};

outputs = { self, nixpkgs, vmrunner }:
let
system = "x86_64-linux";

mkIncludeos = { withCcache ? false, smp ? false }:
let
overlays = [
(import ./overlay.nix {
inherit withCcache smp;
disableTargetWarning = true;
})
];
pkgs = import nixpkgs { config = {}; inherit overlays system; };
pkgsIncludeOS = pkgs.pkgsIncludeOS;
stdenvIncludeOS = pkgs.stdenvIncludeOS;
includeos = pkgsIncludeOS.includeos;

chainloader =
let
chainloaderPkgs = import nixpkgs {
inherit system;
config = {};
overlays = [
(import ./overlay.nix { inherit withCcache; smp = false; disableTargetWarning = true; })
];
crossSystem = { config = "i686-unknown-linux-musl"; };
};
in import ./chainloader.nix {
inherit nixpkgs withCcache;
pkgs = chainloaderPkgs;
};
in {
inherit stdenvIncludeOS; # modified stdenv scope used by includeos (llvm, musl, libcxx)
inherit pkgsIncludeOS; # the musl/clang package scope used by IncludeOS
inherit pkgs; # nixpkgs with the IncludeOS overlay applied
inherit includeos; # the IncludeOS derivation to add to buildInputs
inherit chainloader; # 32-bit boot stub that hotswaps into the 64-bit unikernel
};

default = mkIncludeos {};
mkUnikernel = import ./mkUnikernel.nix { inherit system default vmrunner; };
in {
packages.${system} = {
default = default.includeos;
chainloader = default.chainloader;
example = mkUnikernel { unikernel = ./example; };
};

devShells.${system}.default = import ./develop.nix { includeos = default.includeos; };

lib.${system} = { inherit mkIncludeos mkUnikernel; };

apps.${system} = {
default = self.apps.${system}.boot-unikernel;

boot = {
type = "app";
program = "${vmrunner.lib.${system}.mkBoot default.chainloader}/bin/boot";
};

boot-unikernel = {
type = "app";
program = "${default.pkgs.writeShellScript "boot-unikernel" ''
set -e
dir="''${1:-./result}"
shift || true
exec ${vmrunner.lib.${system}.mkBoot default.chainloader}/bin/boot \
-j $dir/vm.json \
$dir/*.elf.bin \
"$@"
''}";
};

example = {
type = "app";
program = "${default.pkgs.writeShellScript "run-example" ''
set -e
built=$(nix build path:${self.outPath}#example --no-link --print-out-paths)
exec ${self.apps.${system}.boot-unikernel.program} $built "$@"
''}";
};
};
};
}
79 changes: 79 additions & 0 deletions mkUnikernel.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# mkUnikernel.nix
{ system, default, vmrunner }:
args:
let
ios = if args ? includeos then args.includeos else default;
vmrunnerPkg = if args ? vmrunner then args.vmrunner
else vmrunner.packages.${system}.default;

unikernel = args.unikernel or ./example;
test = args.test or "test.py";
doCheck = args.doCheck or false;
arch = args.arch or "x86_64";
forProduction = args.forProduction or false;

src = unikernel;
in
ios.includeos.stdenv.mkDerivation {
pname = "includeos_unikernel";
version = "dev";
dontStrip = true;
inherit doCheck;
inherit src;

nativeBuildInputs = [
ios.pkgs.buildPackages.nasm
ios.pkgs.buildPackages.cmake
ios.pkgsIncludeOS.suppressTargetWarningHook
];

buildInputs = [
ios.includeos
ios.chainloader
];

cmakeFlags = [
"-DARCH=${arch}"
"-DINCLUDEOS_PACKAGE=${ios.includeos}"
"-DCMAKE_MODULE_PATH=${ios.includeos}/cmake"
"-DFOR_PRODUCTION=${if forProduction then "ON" else "OFF"}"
];

installPhase = ''
runHook preInstall
# we want to place any files required by the test into the output
find -mindepth 1 -maxdepth 1 -type f -exec install -v -D -t "$out/" {} \;

# especially the unikernel image, in case it wasn't at the rootdir already
find -mindepth 2 -name '*.elf.bin' -exec install -v -t "$out/" {} \;
runHook postInstall
'';

nativeCheckInputs = [
vmrunnerPkg
ios.pkgs.grub2
ios.pkgs.python3
ios.pkgs.qemu
ios.pkgs.iputils
ios.pkgs.xorriso
];

checkInputs = [
ios.includeos.lest
];

checkPhase = ''
runHook preCheck
set -e
if [ -e "${src}/${test}" ]; then
echo "Running IncludeOS test: ${src}/${test}"
python3 "${src}/${test}"
else
echo "Default test script '${test}', but no test was found 😟"
echo "For a custom path, consider specifying the path to the test script:"
echo " --argstr test 'path/to/test.py'"
exit 1
fi
runHook postCheck
'';
}