Skip to content

Commit 84e3f1a

Browse files
authored
Merge pull request #2284 from MagnusS/nix-improvements
Make it easier to write nix files that depend on IncludeOS
2 parents 66f1afd + 32ccef3 commit 84e3f1a

5 files changed

Lines changed: 58 additions & 56 deletions

File tree

chainloader.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ stdenv.mkDerivation rec {
3434

3535
sourceRoot = "./src/chainload/";
3636

37-
cmakeFlags = [
38-
"-DINCLUDEOS_PACKAGE=${includeos}"
37+
buildInputs = [
38+
includeos
3939
];
4040

4141
srcs = [

example.nix

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
{ withCcache ? false,
22

3-
nixpkgs ? ./pinned.nix,
3+
doCheck ? true, # boot unikernel after building it
44
includeos ? import ./default.nix { inherit withCcache; },
5-
pkgs ? (import nixpkgs { }).pkgsStatic,
6-
llvmPkgs ? pkgs.llvmPackages_18
75
}:
86

97
includeos.stdenv.mkDerivation rec {
108
pname = "includeos_example";
11-
src = pkgs.lib.cleanSource ./example;
12-
doCheck = false;
9+
src = includeos.pkgs.lib.cleanSource ./example;
1310
dontStrip = true;
11+
inherit doCheck;
1412

1513
nativeBuildInputs = [
16-
pkgs.buildPackages.nasm
17-
pkgs.buildPackages.cmake
14+
includeos.pkgs.buildPackages.nasm
15+
includeos.pkgs.buildPackages.cmake
1816
];
1917

2018
buildInputs = [
2119
includeos
20+
includeos.chainloader
2221
];
2322

23+
nativeCheckInputs = [
24+
includeos.vmrunner
25+
includeos.pkgs.qemu
26+
];
27+
28+
checkPhase = ''
29+
boot *.elf.bin
30+
'';
31+
2432
version = "dev";
2533
}

overlay.nix

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,17 @@ final: prev: {
159159

160160
cmakeFlags = archFlags ++ smpFlags;
161161

162-
# Add some pasthroughs, for easily building the depdencies (for debugging):
162+
# Add some pasthroughs, for easily building the dependencies (for debugging):
163163
# $ nix-build -A NAME
164+
165+
passthru.vmrunner = prev.callPackage (builtins.fetchGit {
166+
url = "https://github.com/includeos/vmrunner";
167+
}) {};
168+
passthru.chainloader = import ./chainloader.nix { inherit withCcache; };
169+
passthru.lest = self.callPackage ./deps/lest {};
170+
passthru.pkgsStatic = prev.pkgsStatic; # this is for convenience for other packages that depend on includeos
171+
passthru.pkgs = prev.pkgs; # this is for convenience for other packages that depend on includeos
172+
164173
passthru = {
165174
inherit (self) uzlib;
166175
inherit (self) http-parser;

shell.nix

Lines changed: 27 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,56 +15,39 @@
1515
# Enable multicore suport.
1616
smp ? false,
1717

18-
nixpkgs ? ./pinned.nix,
19-
overlays ? [ (import ./overlay.nix { inherit withCcache; inherit smp; }) ],
20-
chainloader ? (import ./chainloader.nix { inherit withCcache; }),
21-
pkgs ? import nixpkgs {
22-
config = {};
23-
inherit overlays;
24-
},
18+
includeos ? import ./default.nix { inherit withCcache; inherit smp; }
19+
2520
}:
26-
pkgs.mkShell rec {
27-
includeos = pkgs.pkgsIncludeOS.includeos;
28-
stdenv = pkgs.pkgsIncludeOS.stdenv;
2921

22+
includeos.pkgs.mkShell.override { inherit (includeos) stdenv; } rec {
3023
vmrunnerPkg =
3124
if vmrunner == "" then
32-
pkgs.callPackage (builtins.fetchGit {
33-
url = "https://github.com/includeos/vmrunner";
34-
}) {}
25+
includeos.vmrunner
3526
else
36-
pkgs.callPackage (builtins.toPath /. + vmrunner) {};
37-
38-
lest = pkgs.callPackage ./deps/lest {};
27+
includeos.pkgs.callPackage (builtins.toPath /. + vmrunner) {};
3928

4029
packages = [
41-
vmrunnerPkg
42-
stdenv.cc
43-
pkgs.buildPackages.cmake
44-
pkgs.buildPackages.nasm
45-
pkgs.qemu
46-
pkgs.which
47-
pkgs.grub2
48-
pkgs.iputils
30+
(includeos.pkgs.python3.withPackages (p: [
31+
vmrunnerPkg
32+
]))
33+
includeos.pkgs.buildPackages.cmake
34+
includeos.pkgs.buildPackages.nasm
35+
includeos.pkgs.qemu
36+
includeos.pkgs.which
37+
includeos.pkgs.grub2
38+
includeos.pkgs.iputils
39+
includeos.pkgs.xorriso
4940
];
5041

5142
buildInputs = [
52-
chainloader
53-
lest
54-
pkgs.openssl
55-
pkgs.rapidjson
56-
pkgs.xorriso
43+
includeos
44+
includeos.chainloader
45+
includeos.lest
46+
includeos.pkgs.openssl
47+
includeos.pkgs.rapidjson
5748
];
5849

59-
bootloader="${includeos}/boot/bootloader";
60-
6150
shellHook = ''
62-
CC=${stdenv.cc}/bin/clang
63-
CXX=${stdenv.cc}/bin/clang++
64-
65-
# The 'boot' utility in the vmrunner package requires these env vars
66-
export INCLUDEOS_VMRUNNER=${vmrunnerPkg}
67-
export INCLUDEOS_CHAINLOADER=${chainloader}/bin
6851
6952
unikernel=$(realpath ${unikernel})
7053
echo -e "Attempting to build unikernel: \n$unikernel"
@@ -74,13 +57,13 @@ pkgs.mkShell rec {
7457
fi
7558
export BUILDPATH=${buildpath}
7659
if [ -z "${buildpath}" ]; then
77-
export BUILDPATH=$(mktemp -d)
78-
pushd $BUILDPATH
60+
export BUILDPATH="$(mktemp -d)"
61+
pushd "$BUILDPATH"
7962
else
80-
mkdir -p $BUILDPATH
81-
pushd $BUILDPATH
63+
mkdir -p "$BUILDPATH"
64+
pushd "$BUILDPATH"
8265
fi
83-
cmake $unikernel -DARCH=x86_64 -DINCLUDEOS_PACKAGE=${includeos} -DCMAKE_MODULE_PATH=${includeos}/cmake \
66+
cmake "$unikernel" -DARCH=x86_64 -DINCLUDEOS_PACKAGE=${includeos} -DCMAKE_MODULE_PATH=${includeos}/cmake \
8467
-DFOR_PRODUCTION=OFF
8568
make -j $NIX_BUILD_CORES
8669
echo -e "\n====================== IncludeOS nix-shell ====================="
@@ -98,15 +81,15 @@ pkgs.mkShell rec {
9881
echo "The vmrunner for IncludeOS tests requires bridged networking for full functionality."
9982
echo "The following commands requiring sudo privileges can be used to set this up:"
10083
echo "1. the qemu-bridge-helper needs sudo to create a bridge. Can be enabled with:"
101-
echo " sudo chmod u+s ${pkgs.qemu}/libexec/qemu-bridge-helper"
84+
echo " sudo chmod u+s ${includeos.pkgs.qemu}/libexec/qemu-bridge-helper"
10285
echo "2. bridge43 must exist. Can be set up with vmrunner's create_bridge.sh script:"
10386
echo " ${vmrunnerPkg.create_bridge}"
10487
echo "3. /etc/qemu/bridge.conf must contain this line:"
10588
echo " allow bridge43"
10689
echo ""
10790
echo "Some tests require ping, which requires premissions to send raw packets. On some hosts"
10891
echo "this is not enabled by default for iputils provided by nix. It can be enabled with:"
109-
echo "4. sudo setcap cap_net_raw+ep ${pkgs.iputils}/bin/ping"
92+
echo "4. sudo setcap cap_net_raw+ep ${includeos.pkgs.iputils}/bin/ping"
11093
echo " "
11194
echo
11295
'';

src/chainload/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
cmake_minimum_required(VERSION 3.5)
1+
cmake_minimum_required(VERSION 3.6)
22
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
33
# IncludeOS install location
44
project(chainloader C CXX)
55

6+
find_package(IncludeOS REQUIRED)
7+
68
set(ARCH i686)
79
set(PLATFORM nano)
810
set(ELF_SYMBOLS true)
911

10-
include(${INCLUDEOS_PACKAGE}/cmake/os.cmake)
12+
include(os)
1113

1214
option(default_stdout "" ON)
1315
set(SOURCES

0 commit comments

Comments
 (0)