2
0
Fork 0

Documentation and cleanup

This commit is contained in:
Ehmry - 2020-08-02 16:46:34 +02:00
parent f54b0c7d51
commit 4f74ff9452
7 changed files with 244 additions and 249 deletions

303
flake.nix
View File

@ -55,127 +55,101 @@
in rec { in rec {
overlay = import ./overlay; overlay =
# Overlay of fixes applied to Nixpkgs
import ./overlay;
lib = forAllCrossSystems ({ system, localSystem, crossSystem }: lib =
nixpkgs.lib // (import ./lib { # Local utilities merged with the Nixpkgs lib
inherit system localSystem crossSystem; forAllCrossSystems ({ system, localSystem, crossSystem }:
apps = self.apps.${system}; nixpkgs.lib // (import ./lib {
genodepkgs = self; inherit system localSystem crossSystem;
nixpkgs = nixpkgsFor.${system}; apps = self.apps.${system};
})); genodepkgs = self;
nixpkgs = nixpkgsFor.${system};
}));
legacyPackages = forAllSystems legacyPackages =
# The nixpkgs.legacyPackages after overlaying
# and with some additional Genode packages
forAllSystems
({ system, localSystem, crossSystem }: nixpkgsFor.${system}); ({ system, localSystem, crossSystem }: nixpkgsFor.${system});
# pass thru Nixpkgs # pass thru Nixpkgs
packages = forAllCrossSystems ({ system, localSystem, crossSystem }: packages =
nixpkgs.lib.filterAttrs (n: v: v != null) # Genode native packages, not packages in the traditional
nixpkgsFor.${system}.genodePackages); # sense in that these cannot be installed within a profile
forAllCrossSystems ({ system, localSystem, crossSystem }:
nixpkgs.lib.filterAttrs (n: v: v != null)
nixpkgsFor.${system}.genodePackages);
devShell = forAllLocalSystems (system: devShell =
let # Development shell for working with the
pkgs = nixpkgsFor.${system}; # upstream Genode source repositories
fhs = pkgs.buildFHSUserEnv { forAllLocalSystems (system:
name = "genode-env";
targetPkgs = pkgs:
(with pkgs; [
binutils
bison
expect
flex
git
glibc.dev
gnumake
libxml2
qemu
tcl
which
xorriso
]);
runScript = "bash";
extraBuildCommands = let
toolchain = pkgs.fetchzip {
url =
"file://${packages.x86_64-linux-x86_64-genode.genodeSources.toolchain.src}";
hash = "sha256-26rPvLUPEJm40zLSqTquwuFTJ1idTB0T4VXgaHRN+4o=";
};
in "ln -s ${toolchain}/local usr/local";
};
in pkgs.stdenv.mkDerivation {
name = "genode-fhs-shell";
nativeBuildInputs = [ fhs ];
shellHook = "exec genode-env";
});
apps = let
apps' = forAllCrossSystems ({ system, localSystem, crossSystem }:
import ./apps {
inherit system;
self = self.apps.${system};
nixpkgs = nixpkgsFor.${system};
nixpkgsLocal = nixpkgsFor.${localSystem};
packages = self.packages.${system};
} // {
nixosModule = {
type = "app";
program =
"${self.checks.${localSystem}.nixosGuest}/bin/run-nixos-vm";
};
});
in apps' // { x86_64-linux = apps'.x86_64-linux-x86_64-genode; };
nixosModules = import ./nixos-modules { inherit self; };
checks = let
checks' = forAllCrossSystems ({ system, localSystem, crossSystem }:
let let
nixos = nixpkgs.lib.nixosSystem { pkgs = nixpkgsFor.${system};
system = localSystem; fhs = pkgs.buildFHSUserEnv {
modules = [ name = "genode-env";
self.nixosModules.genodeHost targetPkgs = pkgs:
({ modulesPath, ... }: { (with pkgs; [
imports = [ "${modulesPath}/virtualisation/qemu-vm.nix" ]; binutils
boot.loader.grub.extraEntriesBeforeNixOS = true; bison
genode.inputFilter.extraChargen = expect
"${./nixos-modules/dhall/workman.chargen.dhall}"; flex
virtualisation = { git
cores = 2; glibc.dev
memorySize = 1024; gnumake
useBootLoader = true; libxml2
qemu = { qemu
options = tcl
[ "-machine q35" "-cpu phenom" "-serial mon:stdio" ]; which
networkingOptions = [ xorriso
"-net nic,netdev=user.0,model=e1000" ]);
"-netdev user,id=user.0\${QEMU_NET_OPTS:+,$QEMU_NET_OPTS}" runScript = "bash";
]; extraBuildCommands = let
}; toolchain = pkgs.fetchzip {
}; url =
}) "file://${packages.x86_64-linux-x86_64-genode.genodeSources.toolchain.src}";
]; hash = "sha256-26rPvLUPEJm40zLSqTquwuFTJ1idTB0T4VXgaHRN+4o=";
};
in "ln -s ${toolchain}/local usr/local";
}; };
in import ./tests { in pkgs.stdenv.mkDerivation {
inherit self; name = "genode-fhs-shell";
apps = self.apps.${system}; nativeBuildInputs = [ fhs ];
localPackages = nixpkgsFor.${localSystem}; shellHook = "exec genode-env";
genodepkgs = self.packages.${system}; });
lib = self.lib.${system};
nixpkgs = nixpkgsFor.${system};
legacyPackages = self.legacyPackages.${system};
} // {
ports = nixpkgsFor.${localSystem}.symlinkJoin { apps =
name = "ports"; # Utilities accessible via "nix run"
paths = (builtins.attrValues let
self.packages.${system}.genodeSources.ports); apps' = forAllCrossSystems ({ system, localSystem, crossSystem }:
}; import ./apps {
inherit system;
self = self.apps.${system};
nixpkgs = nixpkgsFor.${system};
nixpkgsLocal = nixpkgsFor.${localSystem};
packages = self.packages.${system};
} // {
nixosModule = {
type = "app";
program =
"${self.checks.${localSystem}.nixosGuest}/bin/run-nixos-vm";
};
});
in apps' // { x86_64-linux = apps'.x86_64-linux-x86_64-genode; };
nixosModule = nixos.config.system.build.vm; nixosModules =
nixosXML = nixos.config.system.build.genode.xml; # Modules for composing Genode and NixOS
import ./nixos-modules { inherit self; };
nixosGuest = let checks =
# Checks for continous testing
let
checks' = forAllCrossSystems ({ system, localSystem, crossSystem }:
let
nixos = nixpkgs.lib.nixosSystem { nixos = nixpkgs.lib.nixosSystem {
system = localSystem; system = localSystem;
modules = [ modules = [
@ -196,40 +170,89 @@
]; ];
}; };
}; };
genode.guests = {
flakeCheck = {
config = { config, lib, pkgs, ... }: {
networking.firewall.allowedTCPPorts = [ 80 ];
services.mingetty.autologinUser =
lib.mkDefault "root";
services.nginx.enable = true;
services.openssh.permitRootLogin =
lib.mkDefault "yes";
services.sshd.enable = true;
users.users.root.password = "nixos";
virtualbox.memorySize = 128;
};
};
azimuth = {
bootFormat = "vdi";
config = { config, lib, pkgs, ... }: {
services.cage = {
enable = true;
program = "${pkgs.azimuth}/bin/tor-azimuth";
};
users.users.demo.isNormalUser = true;
virtualbox.memorySize = 1024;
};
};
};
}) })
]; ];
}; };
in nixos.config.system.build.vm; in import ./tests {
inherit self;
apps = self.apps.${system};
localPackages = nixpkgsFor.${localSystem};
genodepkgs = self.packages.${system};
lib = self.lib.${system};
nixpkgs = nixpkgsFor.${system};
legacyPackages = self.legacyPackages.${system};
} // {
}); ports = nixpkgsFor.${localSystem}.symlinkJoin {
in { x86_64-linux = checks'.x86_64-linux-x86_64-genode; }; name = "ports";
paths = (builtins.attrValues
self.packages.${system}.genodeSources.ports);
};
nixosModule = nixos.config.system.build.vm;
nixosXML = nixos.config.system.build.genode.xml;
nixosGuest = let
nixos = nixpkgs.lib.nixosSystem {
system = localSystem;
modules = [
self.nixosModules.genodeHost
({ modulesPath, ... }: {
imports = [ "${modulesPath}/virtualisation/qemu-vm.nix" ];
boot.loader.grub.extraEntriesBeforeNixOS = true;
virtualisation = {
cores = 2;
memorySize = 1024;
useBootLoader = true;
qemu = {
options = [
"-machine q35"
"-cpu phenom"
"-serial mon:stdio"
];
networkingOptions = [
"-net nic,netdev=user.0,model=e1000"
"-netdev user,id=user.0\${QEMU_NET_OPTS:+,$QEMU_NET_OPTS}"
];
};
};
genode.guests = {
flakeCheck = {
config = { config, lib, pkgs, ... }: {
networking.firewall.allowedTCPPorts = [ 80 ];
services.mingetty.autologinUser =
lib.mkDefault "root";
services.nginx.enable = true;
services.openssh.permitRootLogin =
lib.mkDefault "yes";
services.sshd.enable = true;
users.users.root.password = "nixos";
virtualbox.memorySize = 128;
};
};
azimuth = {
bootFormat = "vdi";
config = { config, lib, pkgs, ... }: {
services.cage = {
enable = true;
program = "${pkgs.azimuth}/bin/tor-azimuth";
};
users.users.demo.isNormalUser = true;
virtualbox.memorySize = 1024;
};
};
};
})
];
};
in nixos.config.system.build.vm;
});
in {
aarch64-linux = checks'.aarch64-linux-aarch64-genode;
x86_64-linux = checks'.x86_64-linux-x86_64-genode;
};
}; };
} }

View File

@ -16,49 +16,53 @@ let
else else
throw "unknown Genode arch for platform ${platform.system}"; throw "unknown Genode arch for platform ${platform.system}";
genodeSources = let genodeSources =
# The Genode source repository
let
toolPrefix = if platform.isx86 then toolPrefix = if platform.isx86 then
"genode-x86-" "genode-x86-"
else if platform.isAarch64 then else if platform.isAarch64 then
"genode-aarch64-" "genode-aarch64-"
else else
throw "unknown tool prefix for Genode arch ${arch}"; throw "unknown tool prefix for Genode arch ${arch}";
in stdenvNoCC.mkDerivation { in stdenvNoCC.mkDerivation {
pname = "genode-sources"; pname = "genode-sources";
inherit version; inherit version;
src = fetchurl { src = fetchurl {
url = "https://github.com/genodelabs/genode/archive/${version}.tar.gz"; url = "https://github.com/genodelabs/genode/archive/${version}.tar.gz";
hash = "sha256-5Fd8ywGbDtQF+9yDZ5xAQ7l1Vzh1jQAQeqVj+EtO1us="; hash = "sha256-5Fd8ywGbDtQF+9yDZ5xAQ7l1Vzh1jQAQeqVj+EtO1us=";
};
nativeBuildInputs = [ expect gnumake tcl ];
patches = [ ./LIB.patch ./binary-labels.patch ];
configurePhase = ''
patchShebangs ./tool
substituteInPlace repos/base/etc/tools.conf \
--replace "/usr/local/genode/tool/19.05/bin/" ""
substituteInPlace tool/check_abi \
--replace "exec nm" "exec ${toolPrefix}nm"
'';
buildPhase = ''
echo { >> ports.nix
find repos/*/ports -name '*.hash' | while read hashFile
do
echo " $(basename --suffix=.hash $hashFile) = \"$(cut -c -6 $hashFile)\";" >> ports.nix
done
echo } >> ports.nix
'';
installPhase = "cp -a . $out";
}; };
nativeBuildInputs = [ expect gnumake tcl ];
patches = [ ./LIB.patch ./binary-labels.patch ];
configurePhase = ''
patchShebangs ./tool
substituteInPlace repos/base/etc/tools.conf \
--replace "/usr/local/genode/tool/19.05/bin/" ""
substituteInPlace tool/check_abi \
--replace "exec nm" "exec ${toolPrefix}nm"
'';
buildPhase = ''
echo { >> ports.nix
find repos/*/ports -name '*.hash' | while read hashFile
do
echo " $(basename --suffix=.hash $hashFile) = \"$(cut -c -6 $hashFile)\";" >> ports.nix
done
echo } >> ports.nix
'';
installPhase = "cp -a . $out";
};
toolchain = callPackage ./toolchain.nix { }; toolchain = callPackage ./toolchain.nix { };
stdenv' = stdenv' =
targetPackages.stdenvAdapters.overrideCC targetPackages.stdenv toolchain; targetPackages.stdenvAdapters.overrideCC targetPackages.stdenv toolchain;
preparePort = name: preparePort =
# Prepare a "port" of source code declared in the Genode sources
name:
{ hash ? "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" { hash ? "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
, patches ? [ ], ... }@args: , patches ? [ ], ... }@args:
let let
@ -118,9 +122,10 @@ let
ports = stdenv.lib.mapAttrs preparePort ports = stdenv.lib.mapAttrs preparePort
(import ./ports.nix { inherit buildPackages; }); (import ./ports.nix { inherit buildPackages; });
buildUpstream = { name, targets, portInputs ? [ ], nativeBuildInputs ? [ ] buildUpstream =
, patches ? [ ], enableParallelBuilding ? true, meta ? { }, ... # Build from the Genode sources
}@extraAttrs: { name, targets, portInputs ? [ ], nativeBuildInputs ? [ ], patches ? [ ]
, enableParallelBuilding ? true, meta ? { }, ... }@extraAttrs:
let havePatches = patches != [ ]; let havePatches = patches != [ ];
in stdenv'.mkDerivation (extraAttrs // { in stdenv'.mkDerivation (extraAttrs // {
@ -164,8 +169,10 @@ let
meta = { platforms = stdenv.lib.platforms.genode; } // meta; meta = { platforms = stdenv.lib.platforms.genode; } // meta;
}); });
buildDepot = { name, apiOnly ? false, portInputs ? [ ] buildDepot =
, nativeBuildInputs ? [ ], meta ? { }, ... }@extraAttrs: # Build a Depot target from the Genode sources
{ name, apiOnly ? false, portInputs ? [ ], nativeBuildInputs ? [ ]
, meta ? { }, ... }@extraAttrs:
stdenv'.mkDerivation (extraAttrs // { stdenv'.mkDerivation (extraAttrs // {
pname = name; pname = name;
@ -239,31 +246,33 @@ let
++ lib.optional isx86_64 "x86_64"; ++ lib.optional isx86_64 "x86_64";
genodeBase = buildUpstream { genodeBase =
name = "base"; # A package containing the Genode C++ headers, a stub ld.lib.so and libvfs.lib.so
targets = [ "LIB=vfs" ]; buildUpstream {
postInstall = name = "base";
# The actual ld.lib.so is kernel specific targets = [ "LIB=vfs" ];
# so ship the stubbed library for linking postInstall =
'' # The actual ld.lib.so is kernel specific
cp $BUILD_DIR/var/libcache/ld/ld.abi.so $out/ld.lib.so # so ship the stubbed library for linking
mkdir -p $out/include ''
cp -r --no-preserve=mode \ cp $BUILD_DIR/var/libcache/ld/ld.abi.so $out/ld.lib.so
$GENODE_DIR/repos/base/include/* \ mkdir -p $out/include
$GENODE_DIR/repos/os/include/* \ cp -r --no-preserve=mode \
$GENODE_DIR/repos/demo/include/* \ $GENODE_DIR/repos/base/include/* \
$GENODE_DIR/repos/gems/include/* \ $GENODE_DIR/repos/os/include/* \
$out/include/ $GENODE_DIR/repos/demo/include/* \
for spec in ${toString specs}; do $GENODE_DIR/repos/gems/include/* \
dir=$out/include/spec/$spec $out/include/
if [ -d $dir ]; then for spec in ${toString specs}; do
cp -r $dir/* $out/include/ dir=$out/include/spec/$spec
fi if [ -d $dir ]; then
done cp -r $dir/* $out/include/
rm -rf $out/include/spec fi
cp -r $GENODE_DIR/repos/base/src/ld $out/ld done
''; rm -rf $out/include/spec
}; cp -r $GENODE_DIR/repos/base/src/ld $out/ld
'';
};
in genodeSources // { in genodeSources // {
inherit buildUpstream buildDepot ports specs toolchain genodeBase; inherit buildUpstream buildDepot ports specs toolchain genodeBase;

View File

@ -1,3 +1,6 @@
# This file specifies the output hashes of "Ports".
# Ports not listed here can still be prepared, but will result in a hash mismatch.
{ buildPackages }: { buildPackages }:
with buildPackages; { with buildPackages; {
dde_bsd.hash = "sha256-2ilZs6JkcQAvU/sQYnHunGtGRZDt7qLTpKZxQxSOf2I="; dde_bsd.hash = "sha256-2ilZs6JkcQAvU/sQYnHunGtGRZDt7qLTpKZxQxSOf2I=";

View File

@ -1,3 +1,6 @@
# This file contains overrides necesarry to build some Make and Depot targets.
# Many targets can be built with the default attributes, and are not listed here.
{ buildPackages, ports }: { buildPackages, ports }:
with ports; with ports;
let let
@ -58,8 +61,7 @@ in {
stdcxx.portInputs = [ libc stdcxx ]; stdcxx.portInputs = [ libc stdcxx ];
# The following are tests that never exit # The following are tests are patched to exit at completion
# and have no conventions on log output.
"test-log".patches = [ ./test-log.patch ]; "test-log".patches = [ ./test-log.patch ];

View File

@ -1,5 +0,0 @@
#!/usr/bin/env expect
eval $env(baseSetup)
eval $env(testScript)

View File

@ -1,5 +0,0 @@
#!/usr/bin/env expect
eval $env(baseSetup)
eval $env(testScript)

View File

@ -1,32 +0,0 @@
#! /usr/bin/env expect
##
# Wait for a specific output of a already running spawned process
#
proc wait_for_output { wait_for_re timeout_value running_spawn_id } {
global output
if {$wait_for_re == "forever"} {
set timeout -1
interact {
\003 {
send_user "Expect: 'interact' received 'strg+c' and was cancelled\n";
exit
}
-i $running_spawn_id
}
} else {
set timeout $timeout_value
}
expect {
-i $running_spawn_id -re $wait_for_re { }
eof { puts stderr "Error: Spawned process died unexpectedly"; exit -1 }
timeout { puts stderr "Error: Test execution timed out"; exit -1 }
}
set output $expect_out(buffer)
}
eval $env(baseSetup)
eval $env(testScript)