WiP! Use binary patched toolchain from Genode Labs

- Fetch and patch GCC distribution
 - Pass Tup config as a file
 - Fold out and dev outputs
 - Remove shellHook code for compatibility with dev-shell
This commit is contained in:
Ehmry - 2019-12-31 09:14:17 +01:00
parent bab7a572fe
commit 0ea06cc2a1
3 changed files with 106 additions and 34 deletions

View File

@ -1,21 +1,28 @@
{ localSystem ? "x86_64-linux", crossSystem ? "x86_64-genode", self ? { }, ...
}@args:
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 ? { } }:
nixpkgs =
args.nixpkgs or (pinnedNixpkgs { inherit localSystem crossSystem; });
let
nixpkgs' = if builtins.isAttrs nixpkgs then
nixpkgs
else
nixpkgs { inherit localSystem crossSystem; };
inherit (nixpkgs) stdenv buildPackages llvmPackages;
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 (stdenv) lib targetPlatform;
inherit (stdenvGenodeLabs) lib targetPlatform;
specs = with targetPlatform;
[ ]
@ -37,7 +44,7 @@ let
buildRepo = { repo, repoInputs }:
let
tupArch = with stdenv.targetPlatform;
tupArch = with stdenvGenodeLabs.targetPlatform;
if isAarch32 then
"arm"
@ -58,13 +65,18 @@ let
abort "unhandled targetPlatform";
toTupConfig = attrs:
with builtins;
let op = config: name: "${config}CONFIG_${name}=${getAttr name attrs} ";
in foldl' op "" (attrNames 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 stdenv.mkDerivation {
name = "genode-${repo}-${version}";
outputs = [ "out" "dev" ];
in stdenvGenodeLabs.mkDerivation {
pname = "genode-" + repo;
inherit src repo specs version;
setupHook = ./setup-hooks.sh;
@ -90,9 +102,9 @@ let
configurePhase = ''
# Configure Tup
echo $tupConfig | tr ' CONFIG_' '\nCONFIG_' > tup.config
cp $tupConfig tup.config
echo CONFIG_NIX_OUTPUTS_OUT=$out >> tup.config
echo CONFIG_NIX_OUTPUTS_DEV=$dev >> tup.config
echo CONFIG_NIX_OUTPUTS_DEV=$out >> tup.config
# Disable other repos
for R in repos/*; do
@ -104,13 +116,13 @@ let
tup generate buildPhase.sh
# Redirect artifacts to Nix store
mkdir -p $out/lib $dev/include
mkdir -p $out/lib $out/include
ln -s $out out
ln -s $dev dev
ln -s $out dev
'';
buildPhase = ''
test -d repos/$repo/src/ld && cp -rv repos/$repo/src/ld $dev/
test -d repos/$repo/src/ld && cp -rv repos/$repo/src/ld $out/
pushd .
set -v
source buildPhase.sh
@ -124,18 +136,18 @@ let
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
cp -r $DIR/spec/$SPEC/* $out/include
rm -r $DIR/spec/$SPEC
fi
done
rm -rf $DIR/spec
cp -r $DIR $dev/
cp -r $DIR $out/
done
fi
touch $dev/.genode
for pc in $dev/lib/pkgconfig/*.pc; do
sed -e "s|^Libs: |Libs: -L$dev/lib |" -i $pc
touch $out/.genode
for pc in $out/lib/pkgconfig/*.pc; do
sed -e "s|^Libs: |Libs: -L$out/lib |" -i $pc
done
'';
@ -147,16 +159,6 @@ let
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=configs/${targetPlatform.config}.config
echo $tupConfig | tr ' CONFIG_' '\nCONFIG_' > $CFG
tup variant $CFG
fi
'';
};
in rec {
@ -184,4 +186,7 @@ in rec {
repo = "gems";
repoInputs = [ os ];
};
inherit (nixpkgs') stdenv;
inherit stdenvGenodeLabs;
}

View File

@ -13,6 +13,7 @@
nixpkgs = builtins.getAttr system nixpkgs.legacyPackages;
};
defaultPackage = packages.base-linux;
devShell = packages.base;
};
localSystems = [ "x86_64-linux" ];

66
toolchain.nix Normal file
View File

@ -0,0 +1,66 @@
# Shameless plagiarism of Blitz's toolchain expression:
# https://github.com/blitz/genode-nix
#
# WARNING: these binaries are from sourceforge and
# have not been publicly verified by Genode Labs.
#
{ stdenv, fetchurl, ncurses5, expat, makeWrapper, wrapCC }:
let
cc = stdenv.mkDerivation rec {
pname = "genode-toolchain";
version = "19.05";
src = fetchurl ({
x86_64-linux = {
url =
"mirror://sourceforge/project/genode/${pname}/${version}/${pname}-${version}-x86_64.tar.xz";
sha256 = "036czy21zk7fvz1y1p67q3d5hgg8rb8grwabgrvzgdsqcv2ls6l9";
};
}.${stdenv.buildPlatform.system} or (throw
"cannot install Genode toolchain on this platform"));
nativeBuildInputs = [ makeWrapper ];
phases = [ "unpackPhase" "fixupPhase" ];
dontStrip = true;
dontPatchELF = true;
libPath = stdenv.lib.makeLibraryPath [ "$out" stdenv.cc.cc expat ncurses5 ];
unpackPhase = ''
mkdir $out
tar xf $src --strip-components=5 -C $out
'';
preFixup = ''
for p in $(find "$out" -type f -executable); do
if isELF "$p"; then
echo "Patchelfing $p"
patchelf "$p"
patchelf --set-interpreter $(cat ${stdenv.cc}/nix-support/dynamic-linker) "$p" || true
patchelf --set-rpath ${libPath} "$p" || true
fi
done
pushd $out/bin
for BIN in genode-aarch64-*; do
makeWrapper ''${BIN} aarch64-unknown-genode-''${BIN#genode-aarch64-}
done
for BIN in genode-arm-*; do
makeWrapper ''${BIN} arm-unknown-genode-''${BIN#genode-arm-}
done
for BIN in genode-riscv-*; do
makeWrapper ''${BIN} riscv-unknown-genode-''${BIN#genode-riscv-}
done
for BIN in genode-x86-*; do
makeWrapper ''${BIN} i686-unknown-genode-''${BIN#genode-x86-}
makeWrapper ''${BIN} x86_64-unknown-genode-''${BIN#genode-x86-}
done
popd
'';
};
in wrapCC (cc // { isGNU = true; })