Add inline documentation

This commit is contained in:
Ehmry - 2021-03-09 21:43:23 +01:00
parent 707ec1828c
commit 4c0a6e94f4
5 changed files with 260 additions and 186 deletions

View File

@ -6,15 +6,22 @@
outputs = { self, nixpkgs, nimble }: outputs = { self, nixpkgs, nimble }:
let let
systems = { systems = {
localSystem = [ "x86_64-linux" ]; localSystem = [ "x86_64-linux" ]; # build platforms
crossSystem = [ "aarch64-genode" "x86_64-genode" ]; crossSystem = [ "aarch64-genode" "x86_64-genode" ]; # target platforms
}; };
systemSpace = nixpkgs.lib.cartesianProductOfSets systems;
forAllLocalSystems = f: systemSpace =
# All combinations of build and target systems
nixpkgs.lib.cartesianProductOfSets systems;
forAllLocalSystems =
# Apply a function over all self-hosting (Linux) systems.
f:
nixpkgs.lib.genAttrs systems.localSystem (system: f system); nixpkgs.lib.genAttrs systems.localSystem (system: f system);
forAllCrossSystems = f: forAllCrossSystems =
# Apply a function over all cross-compiled systems (Genode).
f:
with builtins; with builtins;
let let
f' = { localSystem, crossSystem }: f' = { localSystem, crossSystem }:
@ -27,7 +34,9 @@
attrSet = listToAttrs list; attrSet = listToAttrs list;
in attrSet; in attrSet;
forAllSystems = f: forAllSystems =
# Apply a function over all Linux and Genode systems.
f:
(forAllCrossSystems f) // (forAllLocalSystems (system: (forAllCrossSystems f) // (forAllLocalSystems (system:
f { f {
inherit system; inherit system;
@ -38,7 +47,9 @@
in rec { in rec {
overlay = overlay =
# Overlay of fixes applied to Nixpkgs # Overlay of adjustments applied to Nixpkgs as well as
# the "genodePackages" set which the "packages"
# output of this flake is taken.
import ./overlay { flake = self; }; import ./overlay { flake = self; };
lib = lib =
@ -46,16 +57,16 @@
nixpkgs.lib.extend (final: prev: { nixpkgs.lib.extend (final: prev: {
inherit forAllSystems forAllLocalSystems forAllCrossSystems; inherit forAllSystems forAllLocalSystems forAllCrossSystems;
/* For a the name of a derivation output and a derivation, getEris =
generate a set of { cap, closure, and path } for a singular # For a the name of a derivation output and a derivation,
file found within the subdirectory of the output with the # generate a set of { cap, closure, and path } for a singular
same name as that output. In the case that the derivation # file found within the subdirectory of the output with the
does not have this named output, the subdirectory will be # same name as that output. In the case that the derivation
taken from the default output. This subdirectory must # does not have this named output, the subdirectory will be
contain a single file, and the output must contain an # taken from the default output. This subdirectory must
ERIS manifest file. # contain a single file, and the output must contain an
*/ # ERIS manifest file.
getEris = output: pkg: output: pkg:
with builtins; with builtins;
let let
pkg' = prev.getOutput output pkg; pkg' = prev.getOutput output pkg;
@ -72,7 +83,10 @@
}) erisInfo); }) erisInfo);
in assert length caps == 1; head caps; in assert length caps == 1; head caps;
nixosSystem = { modules, ... }@args: nixosSystem =
# A derivative of the function for generating Linux NixOS systems.
# This one is not so well tested…
{ modules, ... }@args:
import "${nixpkgs}/nixos/lib/eval-config.nix" (args // { import "${nixpkgs}/nixos/lib/eval-config.nix" (args // {
lib = final; lib = final;
@ -147,37 +161,38 @@
}); });
/* The nixpkgs.legacyPackages after overlaying legacyPackages =
and with some additional Genode packages. # The nixpkgs.legacyPackages set after overlaying.
*/ let f = import nixpkgs;
legacyPackages = let f = import nixpkgs; in forAllSystems ({ system, localSystem, crossSystem }:
in forAllSystems ({ system, localSystem, crossSystem }: if localSystem == crossSystem then
if localSystem == crossSystem then f {
f { inherit system;
inherit system; overlays = [ self.overlay nimble.overlay ];
overlays = [ self.overlay nimble.overlay ]; }
} else
else f {
f { inherit localSystem;
inherit localSystem; crossSystem = {
crossSystem = { system = crossSystem;
system = crossSystem; useLLVM = true;
useLLVM = true; };
}; config.allowUnsupportedSystem = true;
config.allowUnsupportedSystem = true; overlays = [ self.overlay nimble.overlay ];
overlays = [ self.overlay nimble.overlay ]; });
});
packages = packages =
# Genode native packages, not packages in the traditional # Genode native packages, not packages in the traditional
# sense in that these cannot be installed within a profile # sense in that these cannot be installed within a profile.
forAllCrossSystems ({ system, localSystem, crossSystem }: forAllCrossSystems ({ system, localSystem, crossSystem }:
nixpkgs.lib.filterAttrs (n: v: v != null) nixpkgs.lib.filterAttrs (n: v: v != null)
self.legacyPackages.${system}.genodePackages); self.legacyPackages.${system}.genodePackages);
devShell = devShell =
# Development shell for working with the # Development shell for working with the
# upstream Genode source repositories # upstream Genode source repositories. Some
# things are missing but everything referred
# to by way of #!/usr/bin/ should be here.
forAllLocalSystems (system: forAllLocalSystems (system:
let let
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
@ -217,11 +232,11 @@
}); });
nixosModules = nixosModules =
# Modules for composing Genode and NixOS # Modules for composing Genode and NixOS.
import ./nixos-modules { flake = self; }; import ./nixos-modules { flake = self; };
checks = checks =
# Checks for continous testing # Checks for continous testing.
let tests = import ./tests; let tests = import ./tests;
in with (forAllCrossSystems ({ system, localSystem, crossSystem }: in with (forAllCrossSystems ({ system, localSystem, crossSystem }:
tests { tests {

View File

@ -28,7 +28,7 @@ let
(attrs: { nativeBuildInputs = [ final.autoreconfHook ]; }); (attrs: { nativeBuildInputs = [ final.autoreconfHook ]; });
nullPkgs = nullPkgs =
# Nullify this packages to find problems early # Nullify these packages to find problems early.
if hostPlatform.isGenode then if hostPlatform.isGenode then
builtins.listToAttrs (map (name: { builtins.listToAttrs (map (name: {
inherit name; inherit name;
@ -46,23 +46,28 @@ in nullPkgs // {
}) bash; }) bash;
binutils-unwrapped = overrideAttrsTarget (attrs: { binutils-unwrapped = overrideAttrsTarget (attrs: {
patches = attrs.patches ++ [ ./binutils/support-genode.patch ]; patches = attrs.patches ++ [
./binutils/support-genode.patch
# Upstreamed, remove at next release.
];
nativeBuildInputs = attrs.nativeBuildInputs nativeBuildInputs = attrs.nativeBuildInputs
++ [ final.updateAutotoolsGnuConfigScriptsHook ]; ++ [ final.updateAutotoolsGnuConfigScriptsHook ];
}) binutils-unwrapped; }) binutils-unwrapped;
cmake = overrideAttrsTarget (attrs: { cmake =
postInstall = with stdenv; '' # TODO: upstream
local MODULE="$out/share/cmake-${ overrideAttrsTarget (attrs: {
lib.versions.majorMinor attrs.version postInstall = with stdenv; ''
}/Modules/Platform/Genode.cmake" local MODULE="$out/share/cmake-${
if [ -e "$MODULE" ]; then lib.versions.majorMinor attrs.version
echo "Upstream provides $MODULE!" }/Modules/Platform/Genode.cmake"
exit 1 if [ -e "$MODULE" ]; then
fi echo "Upstream provides $MODULE!"
cp ${./cmake/Genode.cmake} $MODULE exit 1
''; fi
}) cmake; cp ${./cmake/Genode.cmake} $MODULE
'';
}) cmake;
coreutils = overrideHost { coreutils = overrideHost {
gmp = null; gmp = null;
@ -85,24 +90,26 @@ in nullPkgs // {
}); });
}; };
gccForLibs = if targetPlatform.isGenode then gdb = addPatchesTarget [
final.genodePackages.genodeSources.toolchain.cc ./gdb/genode.patch
else # Upstreamed, remove at next release.
prev.gccForLibs; ] gdb;
gdb = addPatchesTarget [ ./gdb/genode.patch ] gdb;
genodeLibcCross = callPackage ./libc { }; genodeLibcCross = callPackage ./libc { };
genodePackages = import ../packages { genodePackages =
inherit flake; # The Genode-only packages.
pkgs = final; import ../packages {
}; inherit flake;
pkgs = final;
};
grub2 = if stdenv.targetPlatform.isGenode then grub2 =
prev.buildPackages.grub2 # No need for a Genode build of GRUB.
else if stdenv.targetPlatform.isGenode then
prev.grub2; prev.buildPackages.grub2
else
prev.grub2;
libcCrossChooser = name: libcCrossChooser = name:
if stdenv.targetPlatform.isGenode then if stdenv.targetPlatform.isGenode then
@ -111,52 +118,73 @@ in nullPkgs // {
prev.libcCrossChooser name; prev.libcCrossChooser name;
libsodium = overrideAttrsHost (attrs: { libsodium = overrideAttrsHost (attrs: {
patches = (attrs.patches or [ ]) ++ [ ./libsodium/genode.patch ]; patches = (attrs.patches or [ ]) ++ [
./libsodium/genode.patch
# https://github.com/jedisct1/libsodium/pull/1006
];
}) libsodium; }) libsodium;
libkrb5 = autoreconfHost libkrb5; libkrb5 =
# Do not want.
autoreconfHost libkrb5;
libtool = overrideAttrsTarget (attrs: { libtool =
nativeBuildInputs = with final; # Autotools related nonesense. Better to compile
attrs.nativeBuildInputs ++ [ autoconf automake115x ]; # everything static than to deal with this one.
patches = ./libtool/genode.patch; overrideAttrsTarget (attrs: {
}) libtool; nativeBuildInputs = with final;
attrs.nativeBuildInputs ++ [ autoconf automake115x ];
patches = ./libtool/genode.patch;
}) libtool;
libtoxcore = overrideHost { libtoxcore = overrideHost {
libopus = null; libopus = null;
libvpx = null; libvpx = null;
} libtoxcore; } libtoxcore;
linuxPackages = if hostPlatform.isGenode then { linuxPackages =
extend = _: final.linuxPackages; # Dummy package.
features = { }; if hostPlatform.isGenode then {
kernel.config = { extend = _: final.linuxPackages;
isEnabled = _: false; features = { };
isYes = _: false; kernel.config = {
}; isEnabled = _: false;
} else isYes = _: false;
linuxPackages; };
} else
linuxPackages;
llvmPackages_11 = callPackage ./llvm-11 ({ llvmPackages_11 =
inherit (stdenvAdapters) overrideCC; # A copy of the LLVM expressions from Nixpkgs.
buildLlvmTools = buildPackages.llvmPackages_11.tools; # Nothing here is upstreamed.
targetLlvmLibraries = targetPackages.llvmPackages_11.libraries; callPackage ./llvm-11 ({
} // lib.optionalAttrs inherit (stdenvAdapters) overrideCC;
(stdenv.hostPlatform.isi686 && buildPackages.stdenv.cc.isGNU) { buildLlvmTools = buildPackages.llvmPackages_11.tools;
stdenv = gcc7Stdenv; targetLlvmLibraries = targetPackages.llvmPackages_11.libraries;
}); } // lib.optionalAttrs
(stdenv.hostPlatform.isi686 && buildPackages.stdenv.cc.isGNU) {
stdenv = gcc7Stdenv;
});
ncurses = addPatchesHost [ ./ncurses/genode.patch ] ncurses; ncurses =
# https://invisible-island.net/autoconf/
# Stay clear of upstream on this one.
addPatchesHost [ ./ncurses/genode.patch ] ncurses;
nim = overrideAttrsTarget (attrs: { nim =
postInstall = '' # Nim is configured to build Genode with GCC.
sed \ overrideAttrsTarget (attrs: {
-e '/cc = gcc/d' \ postInstall = ''
-i $out/etc/nim/nim.cfg sed \
''; -e '/cc = gcc/d' \
}) prev.nim; -i $out/etc/nim/nim.cfg
'';
}) prev.nim;
nim-unwrapped = addPatchesTarget [ ./nim/genode.patch ] prev.nim-unwrapped; nim-unwrapped = addPatchesTarget [
./nim/genode.patch
# Fixes to the compiler and standard libary.
] prev.nim-unwrapped;
openssl = openssl =
overrideHost { static = true; } # shared library comes out stupid big overrideHost { static = true; } # shared library comes out stupid big
@ -173,7 +201,10 @@ in nullPkgs // {
"rm $out/bin/c_rehash"; # eliminate the perl runtime dependency "rm $out/bin/c_rehash"; # eliminate the perl runtime dependency
}) openssl); }) openssl);
patchelf = addPatchesTarget [ ./patchelf/dynstr.patch ] prev.patchelf; patchelf = addPatchesTarget [
./patchelf/dynstr.patch
# Patch to fix a bug in rewriting the .dynstr section.
] prev.patchelf;
rsync = overrideHost { rsync = overrideHost {
enableACLs = false; enableACLs = false;
@ -190,7 +221,10 @@ in nullPkgs // {
tor = overrideAttrsHost (attrs: { tor = overrideAttrsHost (attrs: {
configureFlags = attrs.configureFlags or [ ] configureFlags = attrs.configureFlags or [ ]
++ [ "--disable-tool-name-check" ]; ++ [ "--disable-tool-name-check" ];
patches = attrs.patches or [ ] ++ [ ./tor/genode.patch ]; patches = attrs.patches or [ ] ++ [
./tor/genode.patch
# We don't do users and groups here.
];
postPatch = null; # Avoid torsocks patching postPatch = null; # Avoid torsocks patching
}) tor; }) tor;

View File

@ -13,15 +13,18 @@ let
else else
throw "unknown Genode arch for platform ${platform.system}"; throw "unknown Genode arch for platform ${platform.system}";
upstreamSources = pkgs.fetchFromGitHub { upstreamSources =
owner = "genodelabs"; # This is where the Genode source tree is defined.
repo = "genode"; # Must be updated with ./patches/sources.patch.
rev = "3fac8b106d83721914797c202793ec1d8ea02d2f"; pkgs.fetchFromGitHub {
hash = "sha256-XgN1fBUsmX8oKk4ZBvROwEWlpILRlJz+UuK4kMDSI1Y="; owner = "genodelabs";
}; repo = "genode";
rev = "3fac8b106d83721914797c202793ec1d8ea02d2f";
hash = "sha256-XgN1fBUsmX8oKk4ZBvROwEWlpILRlJz+UuK4kMDSI1Y=";
};
genodeSources = genodeSources =
# The Genode source repository # The Genode source repository after patching.
let let
toolPrefix = if platform.isx86 then toolPrefix = if platform.isx86 then
"genode-x86-" "genode-x86-"
@ -56,10 +59,16 @@ let
installPhase = "cp -a . $out"; installPhase = "cp -a . $out";
}; };
portVersions = import "${genodeSources}/ports.nix"; portVersions =
# Port versions are taken from the sources to force
# updates of the port fixed-output derivations.
import "${genodeSources}/ports.nix";
preparePort = preparePort =
# Prepare a "port" of source code declared in the Genode sources # Prepare a "port" of source code declared in the Genode sources.
# This is fragile because breakage can appear when the packages
# used in preparation are updated, but previously successful
# builds will cache.
name: name:
{ hash ? "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" { hash ? "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
, patches ? [ ], extraRepos ? [ ], ... }@args: , patches ? [ ], extraRepos ? [ ], ... }@args:
@ -122,20 +131,26 @@ let
dontFixup = true; dontFixup = true;
}); });
ports = lib.mapAttrs preparePort (import ./ports.nix { ports =
pkgs = flake.inputs.nixpkgs.legacyPackages.x86_64-linux // { # The "ports" mechanism is hardly deterministic, so prepare with
inherit (pkgs) genodePackages; # a pinned nixpkgs revision for a pinned platform for consistency.
}; lib.mapAttrs preparePort (import ./ports.nix {
}); pkgs = flake.inputs.nixpkgs.legacyPackages.x86_64-linux // {
# The "ports" mechanism is hardly deterministic, so prepare with inherit (pkgs) genodePackages;
# a pinned nixpkgs revision for a pinned platform. };
});
toolchain = buildPackages.buildPackages.callPackage ./toolchain.nix { }; toolchain =
# Patched GCC build from upstream.
buildPackages.buildPackages.callPackage ./toolchain.nix { };
stdenv' = pkgs.stdenvAdapters.overrideCC pkgs.stdenv toolchain; stdenv' =
# Special stdenv for use within the upstream sources.
# TODO: build with Clang.
pkgs.stdenvAdapters.overrideCC pkgs.stdenv toolchain;
buildUpstream = buildUpstream =
# Build from the Genode sources # Build from the Genode sources using the least recursive make.
{ name, targets, portInputs ? [ ], nativeBuildInputs ? [ ], patches ? [ ] { name, targets, portInputs ? [ ], nativeBuildInputs ? [ ], patches ? [ ]
, enableParallelBuilding ? true, meta ? { }, ... }@extraAttrs: , enableParallelBuilding ? true, meta ? { }, ... }@extraAttrs:
let havePatches = patches != [ ]; let havePatches = patches != [ ];
@ -185,7 +200,7 @@ let
}); });
buildDepot = buildDepot =
# Build a Depot target from the Genode sources # Build from the Genode sources using the depot build system.
# WARNING: buildDepot can produce artifacts with broken linkage # WARNING: buildDepot can produce artifacts with broken linkage
# to their inputs. The Genode depot mechanism links programs and # to their inputs. The Genode depot mechanism links programs and
# libraries to facsimilie stub libraries which are not guaranteed # libraries to facsimilie stub libraries which are not guaranteed
@ -209,8 +224,7 @@ let
enableParallelBuilding = true; enableParallelBuilding = true;
nativeBuildInputs = with buildPackages.buildPackages; nativeBuildInputs = with buildPackages.buildPackages;
[ binutils bison flex stdenv.cc tcl which ] [ binutils bison flex stdenv.cc tcl which ] ++ nativeBuildInputs
++ nativeBuildInputs
++ lib.optional (!stdenv.hostPlatform.isGenode) erisPatchHook; ++ lib.optional (!stdenv.hostPlatform.isGenode) erisPatchHook;
buildInputs = buildInputs ++ depotInputs'; buildInputs = buildInputs ++ depotInputs';
@ -277,15 +291,18 @@ let
}); });
in self; in self;
makePackages = let makePackages =
overrides = import ./make-targets.nix { # Build everything in ./make-targets.nix.
inherit (pkgs) buildPackages genodePackages; let
inherit ports; overrides = import ./make-targets.nix {
}; inherit (pkgs) buildPackages genodePackages;
in lib.attrsets.mapAttrs inherit ports;
(name: value: (buildUpstream ({ inherit name; } // value))) overrides; };
in lib.attrsets.mapAttrs
(name: value: (buildUpstream ({ inherit name; } // value))) overrides;
depotPackages = lib.attrsets.mapAttrs depotPackages = lib.attrsets.mapAttrs
# Build everything in ./depot-targets.nix.
(name: value: (buildDepot ({ inherit name; } // value))) (name: value: (buildDepot ({ inherit name; } // value)))
(import ./depot-targets.nix { (import ./depot-targets.nix {
inherit (pkgs) genodePackages; inherit (pkgs) genodePackages;
@ -313,7 +330,8 @@ let
++ lib.optional isx86_64 "x86_64"; ++ lib.optional isx86_64 "x86_64";
genodeBase = genodeBase =
# A package containing the Genode C++ headers, a stub ld.lib.so and vfs.lib.so # A package containing the Genode C++ headers
# and a stub ld.lib.so and vfs.lib.so.
buildUpstream { buildUpstream {
name = "base"; name = "base";
targets = [ "LIB=vfs" ]; targets = [ "LIB=vfs" ];
@ -342,9 +360,15 @@ let
in makePackages // depotPackages // { in makePackages // depotPackages // {
genodeSources = genodeSources // { genodeSources =
inherit arch buildUpstream buildDepot genodeBase ports specs toolchain; # Expose genodeSources and tuck some extras in with it.
}; genodeSources // {
inherit arch buildUpstream buildDepot genodeBase ports specs toolchain;
};
# Builds of the Genode base-systems follow.
# These contain the hardware and kernel specific core program,
# the loader and base-library, and a timer driver.
base-hw-pc = buildUpstream { base-hw-pc = buildUpstream {
name = "base-hw-pc"; name = "base-hw-pc";

View File

@ -1,11 +1,6 @@
# Shameless plagiarism of Blitz's toolchain expression: # Shameless plagiarism of Blitz's toolchain expression:
# https://github.com/blitz/genode-nix # https://github.com/blitz/genode-nix
#
# WARNING: these binaries are from sourceforge and
# have not been publicly verified by Genode Labs.
#
{ lib, stdenv, fetchurl, ncurses5, expat, makeWrapper, wrapCC }: { lib, stdenv, fetchurl, ncurses5, expat, makeWrapper, wrapCC }:
let let

View File

@ -5,53 +5,59 @@ let
nixpkgs = flake.legacyPackages.${system}; nixpkgs = flake.legacyPackages.${system};
legacyPackages = flake.legacyPackages.${system}; legacyPackages = flake.legacyPackages.${system};
testingPython = import ./lib/testing-python.nix; testingPython =
# Mostly lifted from Nixpkgs.
import ./lib/testing-python.nix;
testSpace = lib.cartesianProductOfSets { testSpace =
# Run all tests on all defined Genode platforms
lib.cartesianProductOfSets {
test = map (p: import p) [ test = map (p: import p) [
./ahci.nix ./ahci.nix
./bash.nix ./bash.nix
./hello.nix ./hello.nix
./log.nix ./log.nix
./nim.nix ./nim.nix
./vmm_x86.nix ./vmm_x86.nix
];
core = builtins.filter (core:
builtins.any (x: x == pkgs.stdenv.hostPlatform.system) core.platforms) [
/* {
prefix = "hw-pc-";
testingPython = testingPython {
inherit flake system localSystem crossSystem pkgs;
extraConfigurations = [ ../nixos-modules/base-hw-pc.nix ];
};
specs = [ "x86" "hw" ];
platforms = [ "x86_64-genode" ];
}
*/
/* {
prefix = "hw-virt_qemu-";
testingPython = testingPython {
inherit flake system localSystem crossSystem pkgs;
extraConfigurations = [ ../nixos-modules/base-hw-virt_qemu.nix ];
};
specs = [ "aarch64" "hw" ];
platforms = [ "aarch64-genode" ];
}
*/
{
prefix = "nova-";
testingPython = testingPython {
inherit flake system localSystem crossSystem pkgs;
extraConfigurations = [ ../nixos-modules/nova.nix ];
};
specs = [ "x86" "nova" ];
platforms = [ "x86_64-genode" ];
}
]; ];
}; core = builtins.filter (core:
builtins.any (x: x == pkgs.stdenv.hostPlatform.system) core.platforms) [
/* # Need to fix the QEMU boot parameters?
{
prefix = "hw-pc-";
testingPython = testingPython {
inherit flake system localSystem crossSystem pkgs;
extraConfigurations = [ ../nixos-modules/base-hw-pc.nix ];
};
specs = [ "x86" "hw" ];
platforms = [ "x86_64-genode" ];
}
*/
/* # Need to fix the QEMU boot parameters?
{
prefix = "hw-virt_qemu-";
testingPython = testingPython {
inherit flake system localSystem crossSystem pkgs;
extraConfigurations = [ ../nixos-modules/base-hw-virt_qemu.nix ];
};
specs = [ "aarch64" "hw" ];
platforms = [ "aarch64-genode" ];
}
*/
{
prefix = "nova-";
testingPython = testingPython {
inherit flake system localSystem crossSystem pkgs;
extraConfigurations = [ ../nixos-modules/nova.nix ];
};
specs = [ "x86" "nova" ];
platforms = [ "x86_64-genode" ];
}
];
};
testList = let testList = let
f = { core, test }: f = { core, test }: