193 lines
4.5 KiB
Nix
193 lines
4.5 KiB
Nix
let
|
|
pinnedNixpkgs = import (builtins.fetchGit {
|
|
url = "https://gitea.c3d2.de/ehmry/nixpkgs.git";
|
|
ref = "genode";
|
|
});
|
|
in { localSystem ? "x86_64-linux", crossSystem ? "x86_64-genode"
|
|
, nixpkgs ? pinnedNixpkgs, self ? { } }:
|
|
|
|
let
|
|
nixpkgs' = if builtins.isAttrs nixpkgs then
|
|
nixpkgs
|
|
else
|
|
nixpkgs { inherit localSystem crossSystem; };
|
|
|
|
inherit (nixpkgs') buildPackages llvmPackages;
|
|
|
|
sourceForgeToolchain = nixpkgs'.buildPackages.callPackage ./toolchain.nix { };
|
|
|
|
stdenvGenodeLabs =
|
|
nixpkgs'.stdenvAdapters.overrideCC nixpkgs'.stdenv sourceForgeToolchain;
|
|
|
|
src = self.outPath or (builtins.fetchGit ./.);
|
|
version = self.lastModified or "unstable";
|
|
|
|
inherit (stdenvGenodeLabs) lib targetPlatform;
|
|
specs = with targetPlatform;
|
|
[ ]
|
|
|
|
++ 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";
|
|
|
|
buildRepo = { repo, repoInputs }:
|
|
let
|
|
tupArch = with stdenvGenodeLabs.targetPlatform;
|
|
|
|
if isAarch32 then
|
|
"arm"
|
|
else
|
|
|
|
if isAarch64 then
|
|
"arm64"
|
|
else
|
|
|
|
if isx86_32 then
|
|
"i386"
|
|
else
|
|
|
|
if isx86_64 then
|
|
"x86_64"
|
|
else
|
|
|
|
abort "unhandled targetPlatform";
|
|
|
|
toTupConfig = attrs:
|
|
nixpkgs'.writeTextFile {
|
|
name = "tup.config";
|
|
text = with builtins;
|
|
let
|
|
op = config: name: ''
|
|
${config}CONFIG_${name}=${getAttr name attrs}
|
|
'';
|
|
in foldl' op "" (attrNames attrs);
|
|
};
|
|
|
|
in stdenvGenodeLabs.mkDerivation {
|
|
pname = "genode-" + repo;
|
|
inherit src repo specs version;
|
|
|
|
setupHook = ./setup-hooks.sh;
|
|
|
|
nativeBuildInputs = repoInputs;
|
|
# This is wrong, why does pkg-config not collect buildInputs?
|
|
|
|
propagatedNativeBuildInputs = repoInputs;
|
|
|
|
depsBuildBuild = with buildPackages; [ llvm pkgconfig tup ];
|
|
|
|
tupConfig = toTupConfig {
|
|
LIBCXX = llvmPackages.libcxx;
|
|
LIBCXXABI = llvmPackages.libcxxabi;
|
|
LIBUNWIND = llvmPackages.libunwind;
|
|
LIBUNWIND_BAREMETAL =
|
|
llvmPackages.libunwind.override { isBaremetal = true; };
|
|
LINUX_HEADERS = buildPackages.glibc.dev;
|
|
OLEVEL = "-O2";
|
|
TUP_ARCH = tupArch;
|
|
VERSION = version;
|
|
};
|
|
|
|
configurePhase = ''
|
|
# Configure Tup
|
|
cp $tupConfig tup.config
|
|
echo CONFIG_NIX_OUTPUTS_OUT=$out >> tup.config
|
|
echo CONFIG_NIX_OUTPUTS_DEV=$out >> tup.config
|
|
|
|
# Disable other repos
|
|
for R in repos/*; do
|
|
[ "$R" != "repos/$repo" ] && find $R -name Tupfile -delete
|
|
done
|
|
|
|
# Scan repository and generate script
|
|
tup init
|
|
tup generate buildPhase.sh
|
|
|
|
# Redirect artifacts to Nix store
|
|
mkdir -p $out/lib $out/include
|
|
ln -s $out out
|
|
ln -s $out dev
|
|
'';
|
|
|
|
buildPhase = ''
|
|
test -d repos/$repo/src/ld && cp -rv repos/$repo/src/ld $out/
|
|
pushd .
|
|
set -v
|
|
source buildPhase.sh
|
|
set +v
|
|
popd
|
|
'';
|
|
|
|
installPhase = ''
|
|
# Populate the "dev" headers
|
|
if [ -d "repos/$repo/include" ]; then
|
|
for DIR in repos/$repo/include; do
|
|
for SPEC in $specs; do
|
|
if [ -d $DIR/spec/$SPEC ]; then
|
|
cp -r $DIR/spec/$SPEC/* $out/include
|
|
rm -r $DIR/spec/$SPEC
|
|
fi
|
|
done
|
|
rm -rf $DIR/spec
|
|
cp -r $DIR $out/
|
|
done
|
|
fi
|
|
|
|
touch $out/.genode
|
|
for pc in $out/lib/pkgconfig/*.pc; do
|
|
sed -e "s|^Libs: |Libs: -L$out/lib |" -i $pc
|
|
done
|
|
'';
|
|
|
|
meta = with stdenv.lib; {
|
|
description =
|
|
"The Genode operation system framework (${repo} repository).";
|
|
homepage = "https://genode.org/";
|
|
license = licenses.agpl3;
|
|
maintainers = [ maintainers.ehmry ];
|
|
};
|
|
|
|
};
|
|
|
|
in rec {
|
|
base = buildRepo {
|
|
repo = "base";
|
|
repoInputs = [ ];
|
|
};
|
|
|
|
base-linux = buildRepo {
|
|
repo = "base-linux";
|
|
repoInputs = [ base ];
|
|
};
|
|
|
|
base-nova = buildRepo {
|
|
repo = "base-nova";
|
|
repoInputs = [ base ];
|
|
};
|
|
|
|
os = buildRepo {
|
|
repo = "os";
|
|
repoInputs = [ base ];
|
|
};
|
|
|
|
gems = buildRepo {
|
|
repo = "gems";
|
|
repoInputs = [ os ];
|
|
};
|
|
|
|
inherit (nixpkgs') stdenv;
|
|
inherit stdenvGenodeLabs;
|
|
}
|