186 lines
5.3 KiB
Nix
186 lines
5.3 KiB
Nix
# SPDX-FileCopyrightText: Emery Hemingway
|
|
#
|
|
# SPDX-License-Identifier: LicenseRef-Hippocratic-1.1
|
|
|
|
{ stdenv, buildPackages, fetchgit, llvmPackages }:
|
|
|
|
let
|
|
version = "19.08-64-g69eb762e4a";
|
|
|
|
inherit (stdenv) 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, srcHash }:
|
|
let
|
|
|
|
src = stdenv.mkDerivation {
|
|
name = "genode-" + repo + "-src";
|
|
inherit repo;
|
|
preferLocalBuild = true;
|
|
|
|
outputHashMode = "recursive";
|
|
outputHashAlgo = "sha256";
|
|
outputHash = srcHash;
|
|
|
|
src = fetchgit {
|
|
url = "https://git.sr.ht/~ehmry/genode";
|
|
rev = "1dc25293b84fb3aed880bb4315adc7ce321c6343";
|
|
sha256 = "1jqbc1i4hwi6aai728mz8wmbcpm864v2mlkyg36lm118b7cpp493";
|
|
fetchSubmodules = false;
|
|
};
|
|
|
|
phases = [ "unpackPhase" "patchPhase" "installPhase" ];
|
|
|
|
postPatch = ''
|
|
# Disable other repos
|
|
for R in repos/*; do
|
|
if [ -d "$R" ] ; then
|
|
case $R in
|
|
repos/$repo) ;;
|
|
repos/base)
|
|
find $R -name Tupfile -delete ;;
|
|
*)
|
|
rm -r $R ;;
|
|
esac
|
|
fi
|
|
done
|
|
'';
|
|
|
|
installPhase = "cp -r . $out";
|
|
};
|
|
|
|
tupArch = with stdenv.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:
|
|
with builtins;
|
|
let op = config: name: "${config}CONFIG_${name}=${getAttr name attrs} ";
|
|
in foldl' op "" (attrNames attrs);
|
|
|
|
in stdenv.mkDerivation {
|
|
name = "genode-${repo}-${version}";
|
|
outputs = [ "out" "dev" ];
|
|
|
|
inherit src repo specs version;
|
|
|
|
setupHook = ./../tool/setup-hooks.sh;
|
|
|
|
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
|
|
echo $tupConfig | tr ' CONFIG_' '\nCONFIG_' > tup.config
|
|
echo CONFIG_NIX_OUTPUTS_OUT=$out >> tup.config
|
|
echo CONFIG_NIX_OUTPUTS_DEV=$dev >> tup.config
|
|
|
|
# Scan repository and generate script
|
|
tup init
|
|
tup generate buildPhase.sh
|
|
|
|
# Redirect artifacts to Nix store
|
|
mkdir -p $out $dev/include
|
|
ln -s $out out
|
|
ln -s $dev dev
|
|
'';
|
|
|
|
buildPhase = ''
|
|
test -d repos/$repo/src/ld && cp -rv repos/$repo/src/ld $dev/
|
|
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/* $dev/include
|
|
rm -r $DIR/spec/$SPEC
|
|
fi
|
|
done
|
|
rm -rf $DIR/spec
|
|
cp -r $DIR $dev/
|
|
done
|
|
fi
|
|
|
|
touch $dev/.genode
|
|
for pc in $dev/lib/pkgconfig/*.pc; do
|
|
sed -i "s|-l:|$dev/lib/|g" $pc
|
|
done
|
|
'';
|
|
|
|
meta = with stdenv.lib; {
|
|
description =
|
|
"The Genode operation system framework (${repo} repository).";
|
|
homepage = "https://genode.org/";
|
|
license = licenses.agpl3;
|
|
maintainers = [ maintainers.ehmry ];
|
|
};
|
|
|
|
shellHook = ''
|
|
export PROMPT_DIRTRIM=2
|
|
export PS1="\[\033[1;30m\]Genode-dev [\[\033[1;37m\]\w\[\033[1;30m\]] $\[\033[0m\] "
|
|
export PS2="\[\033[1;30m\]>\[\033[0m\] "
|
|
if [ -e "configs/.gitignore" ]; then
|
|
local CFG_PATH=configs/${targetPlatform.config}.config
|
|
echo $tupConfig | tr ' CONFIG_' '\nCONFIG_' > $CFG_PATH
|
|
echo "Tup configuration placed at $CFG_PATH, to activate run the following command:"
|
|
echo " tup variant $CFG_PATH"
|
|
fi
|
|
'';
|
|
};
|
|
|
|
in rec {
|
|
|
|
# reset hashes to 0000000000000000000000000000000000000000000000000000
|
|
# when updating git revision
|
|
|
|
base = buildRepo {
|
|
repo = "base";
|
|
srcHash = "1wb0jif4v9cgrwsjbg16c5fnpg4d1pa0ikbrl6c25axsrqx77pkp";
|
|
};
|
|
|
|
base-linux = (buildRepo {
|
|
repo = "base-linux";
|
|
srcHash = "0brdiaxgf37cjv34irhybckgwhz7a6lkj8ymya1aba3nrkb12zv6";
|
|
}).overrideAttrs (attrs: { nativeBuildInputs = [ base ]; });
|
|
|
|
base-nova = (buildRepo {
|
|
repo = "base-nova";
|
|
srcHash = "02zhv0j77ikdagslk2nbjiiabl6885kngqlh89jc8i51ksksyljd";
|
|
}).overrideAttrs (attrs: { nativeBuildInputs = [ base ]; });
|
|
|
|
os = (buildRepo {
|
|
repo = "os";
|
|
srcHash = "0ld71jw3d1bs0afad3zm1p8kacj8f1xbncx0jfi89an639b0qgis";
|
|
}).overrideAttrs (attrs: { nativeBuildInputs = [ base ]; });
|
|
}
|