2020-10-22 19:58:10 +02:00
|
|
|
{ flake, buildPackages, targetPackages }:
|
2020-03-27 08:33:50 +01:00
|
|
|
|
|
|
|
let
|
2020-05-30 20:50:44 +02:00
|
|
|
platform = targetPackages.targetPlatform;
|
|
|
|
|
|
|
|
arch = with platform;
|
|
|
|
if isx86_64 then
|
|
|
|
"x86_64"
|
|
|
|
else if isAarch64 then
|
|
|
|
"arm_v8a"
|
|
|
|
else
|
|
|
|
throw "unknown Genode arch for platform ${platform.system}";
|
|
|
|
|
2020-08-15 17:44:06 +02:00
|
|
|
inherit (buildPackages) callPackage fetchurl lib;
|
|
|
|
|
2020-10-22 19:58:10 +02:00
|
|
|
upstreamSources = flake.inputs.genode;
|
|
|
|
|
2020-08-02 16:46:34 +02:00
|
|
|
genodeSources =
|
|
|
|
# The Genode source repository
|
|
|
|
let
|
|
|
|
toolPrefix = if platform.isx86 then
|
|
|
|
"genode-x86-"
|
|
|
|
else if platform.isAarch64 then
|
|
|
|
"genode-aarch64-"
|
|
|
|
else
|
|
|
|
throw "unknown tool prefix for Genode arch ${arch}";
|
2020-08-15 17:44:06 +02:00
|
|
|
in with buildPackages;
|
|
|
|
stdenvNoCC.mkDerivation {
|
2020-08-02 16:46:34 +02:00
|
|
|
pname = "genode-sources";
|
2020-10-19 23:04:41 +02:00
|
|
|
version = upstreamSources.lastModifiedDate;
|
|
|
|
src = upstreamSources;
|
2020-08-02 16:46:34 +02:00
|
|
|
nativeBuildInputs = [ expect gnumake tcl ];
|
2020-11-01 20:12:04 +01:00
|
|
|
patches = [ ./binary-labels.patch ];
|
2020-08-02 16:46:34 +02:00
|
|
|
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";
|
2020-03-27 08:33:50 +01:00
|
|
|
};
|
|
|
|
|
2020-10-19 23:04:41 +02:00
|
|
|
portVersions = import "${genodeSources}/ports.nix";
|
|
|
|
|
2020-08-02 16:46:34 +02:00
|
|
|
preparePort =
|
|
|
|
# Prepare a "port" of source code declared in the Genode sources
|
|
|
|
name:
|
2020-04-08 15:50:54 +02:00
|
|
|
{ hash ? "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
|
|
|
|
, patches ? [ ], ... }@args:
|
2020-06-08 12:43:37 +02:00
|
|
|
let
|
|
|
|
havePatches = patches != [ ];
|
2020-10-19 23:04:41 +02:00
|
|
|
version = portVersions.${name};
|
2020-08-15 17:44:06 +02:00
|
|
|
in with buildPackages;
|
|
|
|
stdenvNoCC.mkDerivation (args // {
|
2020-05-23 09:56:20 +02:00
|
|
|
name = name + "-port-" + version;
|
|
|
|
inherit version patches;
|
|
|
|
preferLocalBuild = true;
|
2020-03-27 08:33:50 +01:00
|
|
|
outputHashMode = "recursive";
|
|
|
|
outputHash = hash;
|
|
|
|
|
|
|
|
GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt";
|
|
|
|
VERBOSE = "";
|
|
|
|
# need to build in verbose mode because errors are hidden
|
|
|
|
|
2020-08-15 17:44:06 +02:00
|
|
|
impureEnvVars = lib.fetchers.proxyImpureEnvVars
|
2020-03-27 08:33:50 +01:00
|
|
|
++ [ "GIT_PROXY_COMMAND" "SOCKS_SERVER" ];
|
|
|
|
|
2020-04-08 15:50:54 +02:00
|
|
|
src = if havePatches then genodeSources else null;
|
|
|
|
dontUnpack = !havePatches;
|
|
|
|
|
2020-03-27 08:33:50 +01:00
|
|
|
dontConfigure = true;
|
|
|
|
|
|
|
|
nativeBuildInputs =
|
2020-04-03 19:01:19 +02:00
|
|
|
[ bison flex gitMinimal glibc glibcLocales wget which ]
|
2020-03-27 08:33:50 +01:00
|
|
|
++ (args.nativeBuildInputs or [ ]);
|
|
|
|
|
2020-04-03 19:01:19 +02:00
|
|
|
buildPhase =
|
|
|
|
# ignore the port hash, its only for the inputs
|
|
|
|
''
|
|
|
|
runHook preBuild
|
|
|
|
export CONTRIB_DIR=$NIX_BUILD_TOP/contrib
|
2020-04-08 15:50:54 +02:00
|
|
|
export GENODE_DIR=${if havePatches then "$(pwd)" else genodeSources}
|
2020-04-03 19:01:19 +02:00
|
|
|
mkdir $CONTRIB_DIR
|
2020-05-23 09:56:20 +02:00
|
|
|
$GENODE_DIR/tool/ports/prepare_port ${name} CHECK_HASH=no
|
2020-04-03 19:01:19 +02:00
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase =
|
2020-04-08 15:05:26 +02:00
|
|
|
# strip non-deterministic and extra artifacts
|
2020-04-03 19:01:19 +02:00
|
|
|
''
|
|
|
|
runHook preInstall
|
|
|
|
chmod -R +w $CONTRIB_DIR/*
|
|
|
|
find $CONTRIB_DIR/* -name .git -exec rm -rf {} \; || true
|
|
|
|
find $CONTRIB_DIR/* -name .svn -exec rm -rf {} \; || true
|
|
|
|
find $CONTRIB_DIR/* -name '*.t?z' -exec rm -rf {} \; || true
|
|
|
|
find $CONTRIB_DIR/* -name '*.tar.*' -exec rm -rf {} \; || true
|
2020-05-23 09:56:20 +02:00
|
|
|
find $CONTRIB_DIR/* -name '*.zip' -exec rm -rf {} \; || true
|
2020-04-03 19:01:19 +02:00
|
|
|
|
|
|
|
mkdir $out
|
|
|
|
cp -a $CONTRIB_DIR/* $out/
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
2020-08-15 17:44:06 +02:00
|
|
|
|
|
|
|
dontFixup = true;
|
2020-03-27 08:33:50 +01:00
|
|
|
});
|
|
|
|
|
2020-10-22 19:58:10 +02:00
|
|
|
ports = lib.mapAttrs preparePort (import ./ports.nix {
|
|
|
|
pkgs = flake.inputs.nixpkgs.legacyPackages.x86_64-linux;
|
|
|
|
});
|
|
|
|
# The "ports" mechanism is hardly deterministic, so prepare with
|
|
|
|
# a pinned nixpkgs revision for a pinned platform.
|
2020-08-15 17:44:06 +02:00
|
|
|
|
|
|
|
toolchain = callPackage ./toolchain.nix { };
|
|
|
|
|
|
|
|
stdenv' =
|
|
|
|
targetPackages.stdenvAdapters.overrideCC targetPackages.stdenv toolchain;
|
2020-03-27 08:33:50 +01:00
|
|
|
|
2020-08-02 16:46:34 +02:00
|
|
|
buildUpstream =
|
|
|
|
# Build from the Genode sources
|
|
|
|
{ name, targets, portInputs ? [ ], nativeBuildInputs ? [ ], patches ? [ ]
|
|
|
|
, enableParallelBuilding ? true, meta ? { }, ... }@extraAttrs:
|
2020-04-08 15:50:54 +02:00
|
|
|
let havePatches = patches != [ ];
|
2020-03-27 08:33:50 +01:00
|
|
|
|
2020-04-08 15:50:54 +02:00
|
|
|
in stdenv'.mkDerivation (extraAttrs // {
|
2020-04-08 15:05:26 +02:00
|
|
|
pname = name;
|
|
|
|
inherit (genodeSources) version;
|
2020-04-08 15:50:54 +02:00
|
|
|
inherit targets patches enableParallelBuilding;
|
2020-03-27 08:33:50 +01:00
|
|
|
|
2020-04-08 15:50:54 +02:00
|
|
|
src = if havePatches then genodeSources else null;
|
|
|
|
dontUnpack = !havePatches;
|
2020-03-27 08:33:50 +01:00
|
|
|
|
2020-08-15 17:44:06 +02:00
|
|
|
nativeBuildInputs = with buildPackages;
|
|
|
|
[ binutils bison flex stdenv.cc tcl which ] ++ nativeBuildInputs;
|
2020-04-08 15:05:26 +02:00
|
|
|
|
|
|
|
configurePhase = let
|
|
|
|
linkPorts = toString
|
|
|
|
(builtins.map (drv: " ln -sv ${drv}/* $CONTRIB_DIR/;") portInputs);
|
|
|
|
in ''
|
|
|
|
runHook preConfigure
|
|
|
|
export CONTRIB_DIR=$NIX_BUILD_TOP/contrib
|
2020-04-08 15:50:54 +02:00
|
|
|
export BUILD_DIR=$(pwd)/build
|
|
|
|
export GENODE_DIR=${if havePatches then "$(pwd)" else genodeSources}
|
|
|
|
|
2020-04-08 15:05:26 +02:00
|
|
|
$GENODE_DIR/tool/create_builddir ${arch}
|
2020-04-08 15:50:54 +02:00
|
|
|
substituteInPlace $BUILD_DIR/etc/build.conf \
|
2020-04-08 15:05:26 +02:00
|
|
|
--replace "#REPOSITORIES" "REPOSITORIES"
|
|
|
|
mkdir $CONTRIB_DIR; ${linkPorts}
|
|
|
|
runHook postConfigure
|
|
|
|
'';
|
2020-03-27 08:33:50 +01:00
|
|
|
|
2020-04-19 07:28:05 +02:00
|
|
|
STRIP_TARGET_CMD = "cp $< $@";
|
|
|
|
|
2020-04-08 15:50:54 +02:00
|
|
|
makeFlags = [ "-C build" "VERBOSE=" ] ++ targets;
|
2020-03-27 08:33:50 +01:00
|
|
|
|
2020-04-08 15:05:26 +02:00
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
|
|
|
find build/bin -name '*.xsd' -delete
|
2020-11-01 20:12:04 +01:00
|
|
|
find build/bin -follow -type f -name '*.lib.so' \
|
|
|
|
-exec install -Dt "''${!outputLib}/lib" {} \; -delete
|
|
|
|
find build/bin -follow -type f -executable \
|
|
|
|
-exec install -Dt "''${!outputBin}/bin" {} \;
|
2020-04-08 15:05:26 +02:00
|
|
|
runHook postInstall
|
|
|
|
'';
|
2020-05-30 20:50:44 +02:00
|
|
|
|
2020-08-15 17:44:06 +02:00
|
|
|
meta = { platforms = lib.platforms.genode; } // meta;
|
2020-04-08 15:05:26 +02:00
|
|
|
});
|
2020-03-27 08:33:50 +01:00
|
|
|
|
2020-08-02 16:46:34 +02:00
|
|
|
buildDepot =
|
|
|
|
# Build a Depot target from the Genode sources
|
|
|
|
{ name, apiOnly ? false, portInputs ? [ ], nativeBuildInputs ? [ ]
|
|
|
|
, meta ? { }, ... }@extraAttrs:
|
2020-03-27 08:33:50 +01:00
|
|
|
|
2020-04-08 15:05:26 +02:00
|
|
|
stdenv'.mkDerivation (extraAttrs // {
|
|
|
|
pname = name;
|
|
|
|
inherit (genodeSources) version;
|
2020-05-07 21:33:26 +02:00
|
|
|
enableParallelBuilding = true;
|
2020-04-08 15:05:26 +02:00
|
|
|
|
2020-08-15 17:44:06 +02:00
|
|
|
nativeBuildInputs = with buildPackages;
|
|
|
|
[ binutils bison flex stdenv.cc tcl which ] ++ nativeBuildInputs;
|
2020-04-08 15:05:26 +02:00
|
|
|
|
|
|
|
src = genodeSources;
|
|
|
|
# The genode source tree must be copied to the build directory
|
|
|
|
# because the depot tool must modify the source tree as it runs.
|
|
|
|
|
|
|
|
configurePhase = let
|
|
|
|
copyPorts = # wasteful copy
|
|
|
|
toString
|
|
|
|
(builtins.map (drv: " cp -r ${drv}/* $CONTRIB_DIR/;") portInputs);
|
|
|
|
in ''
|
|
|
|
runHook preConfigure
|
|
|
|
export GENODE_DIR=$(pwd)
|
|
|
|
export CONTRIB_DIR=$GENODE_DIR/contrib
|
|
|
|
export DEPOT_DIR=$GENODE_DIR/depot
|
|
|
|
mkdir -p $CONTRIB_DIR; ${copyPorts}
|
|
|
|
chmod +rwX -R .
|
|
|
|
runHook postConfigure
|
|
|
|
'';
|
|
|
|
|
2020-04-19 07:28:05 +02:00
|
|
|
STRIP_TARGET_CMD = "cp $< $@";
|
2020-05-07 21:33:26 +02:00
|
|
|
# defer strip until fixup phase
|
2020-04-19 07:28:05 +02:00
|
|
|
|
2020-04-08 15:05:26 +02:00
|
|
|
makefile = "tool/depot/create";
|
|
|
|
makeFlags = [
|
|
|
|
"genodelabs/bin/${arch}/${name}"
|
|
|
|
|
|
|
|
# by default the build system will refuse to be useful
|
|
|
|
"FORCE=1"
|
2020-05-07 21:33:26 +02:00
|
|
|
"KEEP_BUILD_DIR=1"
|
2020-04-08 15:05:26 +02:00
|
|
|
"UPDATE_VERSIONS=1"
|
|
|
|
"VERBOSE="
|
|
|
|
];
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
2020-05-07 21:33:26 +02:00
|
|
|
rm -r depot/genodelabs/bin/${arch}/${name}/*\.build
|
2020-11-01 20:12:04 +01:00
|
|
|
find depot/genodelabs/bin/${arch}/${name} -name '*.lib.so' \
|
|
|
|
-exec install -Dt "''${!outputLib}/lib" {} \; -delete
|
|
|
|
find depot/genodelabs/bin/${arch}/${name} -executable \
|
|
|
|
-exec install -Dt "''${!outputBin}/bin" {} \;
|
2020-04-08 15:05:26 +02:00
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
2020-08-15 17:44:06 +02:00
|
|
|
meta = { platforms = lib.platforms.genode; } // meta;
|
2020-04-08 15:05:26 +02:00
|
|
|
});
|
2020-03-27 08:33:50 +01:00
|
|
|
|
|
|
|
buildOverrides = callPackage ./targets.nix { inherit ports; };
|
|
|
|
|
2020-03-27 10:08:22 +01:00
|
|
|
specs = with platform;
|
|
|
|
[ ]
|
|
|
|
|
|
|
|
++ lib.optional is32bit "32bit"
|
|
|
|
|
|
|
|
++ lib.optional is64bit "64bit"
|
|
|
|
|
|
|
|
++ lib.optional isAarch32 "arm"
|
|
|
|
|
|
|
|
++ lib.optional isAarch64 "arm_64"
|
|
|
|
|
|
|
|
++ lib.optional isRiscV "riscv"
|
|
|
|
|
|
|
|
++ lib.optional isx86 "x86"
|
|
|
|
|
|
|
|
++ lib.optional isx86_32 "x86_32"
|
|
|
|
|
|
|
|
++ lib.optional isx86_64 "x86_64";
|
|
|
|
|
2020-08-02 16:46:34 +02:00
|
|
|
genodeBase =
|
2020-11-01 20:12:04 +01:00
|
|
|
# A package containing the Genode C++ headers, a stub ld.lib.so and vfs.lib.so
|
2020-08-02 16:46:34 +02:00
|
|
|
buildUpstream {
|
|
|
|
name = "base";
|
|
|
|
targets = [ "LIB=vfs" ];
|
|
|
|
postInstall =
|
|
|
|
# The actual ld.lib.so is kernel specific
|
|
|
|
# so ship the stubbed library for linking
|
|
|
|
''
|
|
|
|
cp $BUILD_DIR/var/libcache/ld/ld.abi.so $out/ld.lib.so
|
|
|
|
mkdir -p $out/include
|
|
|
|
cp -r --no-preserve=mode \
|
|
|
|
$GENODE_DIR/repos/base/include/* \
|
|
|
|
$GENODE_DIR/repos/os/include/* \
|
|
|
|
$GENODE_DIR/repos/demo/include/* \
|
|
|
|
$GENODE_DIR/repos/gems/include/* \
|
|
|
|
$out/include/
|
|
|
|
for spec in ${toString specs}; do
|
|
|
|
dir=$out/include/spec/$spec
|
|
|
|
if [ -d $dir ]; then
|
|
|
|
cp -r $dir/* $out/include/
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
rm -rf $out/include/spec
|
|
|
|
cp -r $GENODE_DIR/repos/base/src/ld $out/ld
|
|
|
|
'';
|
|
|
|
};
|
2020-03-27 10:08:22 +01:00
|
|
|
|
2020-03-27 08:33:50 +01:00
|
|
|
in genodeSources // {
|
2020-04-08 15:05:26 +02:00
|
|
|
inherit buildUpstream buildDepot ports specs toolchain genodeBase;
|
2020-03-27 10:08:22 +01:00
|
|
|
|
2020-03-27 08:33:50 +01:00
|
|
|
make = target:
|
2020-04-26 07:15:21 +02:00
|
|
|
let
|
2020-04-08 15:05:26 +02:00
|
|
|
name = builtins.replaceStrings [ "/" ] [ "-" ] target;
|
2020-04-26 07:15:21 +02:00
|
|
|
attrs = buildOverrides.${name} or { };
|
|
|
|
in buildUpstream ({
|
|
|
|
inherit name;
|
2020-03-27 08:33:50 +01:00
|
|
|
targets = [ target ];
|
2020-04-26 07:15:21 +02:00
|
|
|
} // attrs);
|
2020-04-08 15:05:26 +02:00
|
|
|
|
|
|
|
depot = name:
|
|
|
|
let attrs = buildOverrides.${name} or { };
|
|
|
|
in buildDepot ({ inherit name; } // attrs);
|
2020-03-27 10:08:22 +01:00
|
|
|
|
2020-03-27 08:33:50 +01:00
|
|
|
}
|