Move Nix expressions to genodepkgs

This commit is contained in:
Ehmry - 2020-01-17 15:17:19 +01:00
parent 59caa85840
commit 42f93ce3da
8 changed files with 0 additions and 571 deletions

View File

@ -1,46 +0,0 @@
# SPDX-FileCopyrightText: Emery Hemingway
#
# SPDX-License-Identifier: LicenseRef-Hippocratic-1.1
{ stdenv, buildPackages, fetchFromGitHub }:
let
ARCH = if stdenv.isx86_32 then
"x86_32"
else if stdenv.isx86_64 then
"x86_64"
else
null;
in if ARCH == null then
null
else
buildPackages.stdenv.mkDerivation rec {
# Borrow the build host compiler,
pname = "NOVA";
version = "r10";
inherit ARCH;
src = fetchFromGitHub {
owner = "alex-ab";
repo = "NOVA";
rev = "68c2fb1671e75d811a4787e35b0d0c6cc85815c0";
sha256 = "06zxz8hvzqgp8vrh6kv65j0z1m3xfm2ac8ppkv6ql0rivm1rv07s";
};
enableParallelBuilding = true;
makeFlags = [ "--directory build" ];
preInstall = "export INS_DIR=$out";
meta = with stdenv.lib;
src.meta // {
description =
"The NOVA OS Virtualization Architecture is a project aimed at constructing a secure virtualization environment with a small trusted computing base.";
homepage = "http://hypervisor.org/";
license = licenses.gpl2;
maintainers = [ maintainers.ehmry ];
};
}

View File

@ -1,344 +0,0 @@
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 ? { }, dhall-haskell ? null }:
let
nixpkgs' = if builtins.isAttrs nixpkgs then
nixpkgs
else
nixpkgs { inherit localSystem crossSystem; };
inherit (nixpkgs') buildPackages llvmPackages;
sourceForgeToolchain = nixpkgs'.buildPackages.callPackage ./toolchain.nix { };
stdenvLlvm = let inherit (nixpkgs') stdenv;
in assert stdenv.cc.isClang; stdenv;
stdenvGcc = let
env =
nixpkgs'.stdenvAdapters.overrideCC nixpkgs'.stdenv sourceForgeToolchain;
in assert env.cc.isGNU; env;
inherit (stdenvLlvm) 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";
toTupConfig = env: attrs:
let
tupArch = with env.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";
attrs' = with env; { TUP_ARCH = tupArch; } // attrs;
in with builtins;
env.mkDerivation {
name = "tup.config";
nativeBuildInputs = with nixpkgs'.buildPackages; [
binutils
pkgconfig
which
];
text = let
op = config: name: ''
${config}CONFIG_${name}=${getAttr name attrs}
'';
in foldl' op "" (attrNames attrs);
passAsFile = [ "text" ];
preferLocalBuild = true;
buildCommand = let
subst = let
vars = [ "AR" "NM" ];
f = other: var:
other + ''
echo CONFIG_${var}=`which ''$${var}` >> $out
'';
in foldl' f "" vars;
utils = let
vars = [ "pkg-config" "objcopy" ];
f = other: var:
other + ''
echo CONFIG_${var}=`which ${var}` >> $out
'';
in foldl' f "" vars;
in ''
cp $textPath $out
${subst}
${utils}
'';
};
tupConfigGcc = let
f = env:
let prefix = bin: env.cc.targetPrefix + bin;
in {
CC = prefix "gcc";
CXX = prefix "g++";
LD = prefix "ld";
OBJCOPY = prefix "objcopy";
RANLIB = prefix "ranlib";
READELF = prefix "readelf";
STRIP = prefix "strip";
PKGCONFIG = "${nixpkgs'.buildPackages.pkgconfig}/bin/pkg-config";
IS_GCC = "";
LINUX_HEADERS = buildPackages.glibc.dev;
};
in toTupConfig stdenvGcc (f stdenvGcc);
tupConfigLlvm = let
f = env:
let prefix = bin: "${env.cc}/bin/${env.cc.targetPrefix}${bin}";
in {
CC = prefix "cc";
CXX = prefix "c++";
LD = prefix "ld";
OBJCOPY = prefix "objcopy";
OBJDUMP = prefix "objdump";
RANLIB = prefix "ranlib";
READELF = prefix "readelf";
STRIP = prefix "strip";
PKGCONFIG = "${nixpkgs'.buildPackages.pkgconfig}/bin/pkg-config";
IS_LLVM = "";
LIBCXXABI = llvmPackages.libcxxabi;
LIBCXX = llvmPackages.libcxx;
LIBUNWIND_BAREMETAL =
llvmPackages.libunwind.override { isBaremetal = true; };
LIBUNWIND = llvmPackages.libunwind;
LINUX_HEADERS = buildPackages.glibc.dev;
};
in toTupConfig stdenvLlvm (f stdenvLlvm);
buildRepo = { env, repo, repoInputs, filter }:
let
in env.mkDerivation {
name = "genode-" + repo;
inherit repo specs;
src = builtins.filterSource filter ./.;
nativeBuildInputs = repoInputs;
# This is wrong, why does pkg-config not collect buildInputs?
propagatedNativeBuildInputs = repoInputs;
depsBuildBuild = with buildPackages; [ llvm pkgconfig tup ];
tupConfig = if env.cc.isGNU then
tupConfigGcc
else if env.cc.isClang then
tupConfigLlvm
else
throw "no Tup config for this stdenv";
configurePhase = ''
# Configure Tup
set -v
install -m666 $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 env.lib; {
description =
"The Genode operation system framework (${repo} repository).";
homepage = "https://genode.org/";
license = licenses.agpl3;
maintainers = [ maintainers.ehmry ];
};
};
buildRepo' = { ... }@args: buildRepo ({ env = stdenvGcc; } // args);
#builtins.throw "create the tup config file in the stdenv environment, replacing CC/CXX with environmental variables"
in rec {
packages = let
hasPrefix = pre:
with builtins;
let
pre' = "${toString ./.}/${pre}";
preLen = stringLength pre';
in path:
let pathLen = stringLength path;
in substring 0 preLen path == substring 0 pathLen pre';
hasSuffix = suf:
with builtins;
let sufLen = stringLength suf;
in path:
let pathLen = stringLength path;
in substring (pathLen - sufLen) pathLen path == suf;
filterBaseRepo = name:
with builtins;
let
match = [
(hasPrefix "Tup")
(hasPrefix "repos/Tup")
(hasPrefix "repos/base/")
(hasPrefix "repos/base-${name}")
];
skip = [
(hasSuffix "/run")
(hasSuffix "/recipes")
(hasSuffix ".gitignore")
(path: hasPrefix "repos/base/" path && hasSuffix "Tupfile" path)
];
in path: type: let f = f': f' path; in any f match && !any f skip;
filterRepo = repo:
with builtins;
let
reposDir = toString ./repos;
skip = [
(hasSuffix "/run")
(hasSuffix "/recipes")
(hasSuffix ".gitignore")
];
match = [
(hasPrefix "Tup")
(hasPrefix "repos/Tup")
(hasPrefix "repos/${repo}")
(hasPrefix "repos/base/src/ld")
];
in path: type: let f = f': f' path; in any f match && !any f skip;
in rec {
NOVA = nixpkgs.callPackage ./NOVA { };
base = buildRepo' {
repo = "base";
repoInputs = [ ];
filter = with builtins;
let
match = [
(hasPrefix "Tup")
(hasPrefix "repos/Tup")
(hasPrefix "repos/base/")
];
skip = [
(hasSuffix "/run")
(hasSuffix "/recipes")
(hasSuffix ".gitignore")
];
in path: type: let f = f': f' path; in any f match && !any f skip;
};
base-linux = buildRepo' {
repo = "base-linux";
repoInputs = [ base ];
filter = filterBaseRepo "linux";
};
base-nova = buildRepo' {
repo = "base-nova";
repoInputs = [ base ];
filter = filterBaseRepo "nova";
};
os = buildRepo' {
repo = "os";
repoInputs = [ base ];
filter = filterRepo "os";
};
gems = buildRepo' {
repo = "gems";
repoInputs = [ base os ];
filter = filterRepo "gems";
};
inherit stdenvGcc stdenvLlvm tupConfigGcc tupConfigLlvm;
};
defaultPackage = packages.base-linux;
devShell = packages.base;
checks = packages;
}

View File

@ -1,6 +0,0 @@
#! /bin/sh
set -e
nix build .#packages.x86_64-linux-x86_64-genode.tupConfigGcc -o build-gcc/tup.config
export SHELL=bash
exec nix dev-shell

View File

@ -1,30 +0,0 @@
{
"inputs": {
"dhall-haskell": {
"inputs": {
"nixpkgs": {
"inputs": {},
"narHash": "sha256-wJg4DA700SoQbEz61448sR6BgxRa1R92K3vvCV1g+HY=",
"originalUrl": "git+https://github.com/nixos/nixpkgs.git?ref=18.09-beta&rev=1d4de0d552ae9aa66a5b8dee5fb0650a4372d148",
"url": "git+https://github.com/nixos/nixpkgs.git?ref=18.09-beta&rev=1d4de0d552ae9aa66a5b8dee5fb0650a4372d148"
},
"nixpkgsStaticLinux": {
"inputs": {},
"narHash": "sha256-famU3pJZ4vkElV9qc71HmyRVSvcrAhfMZ0UJKpmmKP8=",
"originalUrl": "git+https://github.com/nh2/nixpkgs.git?ref=static-haskell-nix-stack-dhall-working",
"url": "git+https://github.com/nh2/nixpkgs.git?ref=static-haskell-nix-stack-dhall-working&rev=925aac04f4ca58aceb83beef18cb7dae0715421b"
}
},
"narHash": "sha256-KJl9ZLcMcEsLSPcwcWoc0Ac74/6HKC9LkVMeLwhyhlg=",
"originalUrl": "git+https://github.com/dhall-lang/dhall-haskell?ref=flake",
"url": "git+https://github.com/dhall-lang/dhall-haskell?ref=flake&rev=aea28adf3d10ff1982aa4ddd176d1476251b932f"
},
"nixpkgs": {
"inputs": {},
"narHash": "sha256-EqxCk6ORqq4fkewWttpvks0VycBec9X9spAZ+Pq/CEI=",
"originalUrl": "github:ehmry/nixpkgs",
"url": "github:ehmry/nixpkgs/cf50f3b8bdc28832249afab6bca68acad832e011"
}
},
"version": 3
}

View File

@ -1,60 +0,0 @@
{
edition = 201909;
description = "Genode system flake";
inputs = {
nixpkgs.uri = "github:ehmry/nixpkgs";
dhall-haskell.uri =
"git+https://github.com/dhall-lang/dhall-haskell?ref=flake";
};
outputs = { self, nixpkgs, dhall-haskell }:
let
mkOutput = { system, localSystem, crossSystem }:
import ./default.nix {
inherit localSystem crossSystem self;
nixpkgs = builtins.getAttr system nixpkgs.legacyPackages;
inherit dhall-haskell;
};
localSystems = [ "x86_64-linux" ];
crossSystems = [ "x86_64-genode" ];
forAllCrossSystems = f:
with builtins;
let
f' = localSystem: crossSystem:
let system = localSystem + "-" + crossSystem;
in {
name = system;
value = f { inherit system localSystem crossSystem; };
};
list = nixpkgs.lib.lists.crossLists f' [ localSystems crossSystems ];
attrSet = listToAttrs list;
in attrSet;
finalize = outputs:
with builtins;
let
outputs' = outputs // {
x86_64-linux = getAttr "x86_64-linux-x86_64-genode" outputs;
};
systems = attrNames outputs';
outputAttrs = attrNames (head (attrValues outputs'));
list = map (attr: {
name = attr;
value = listToAttrs (map (system: {
name = system;
value = getAttr attr (getAttr system outputs');
}) systems);
}) outputAttrs;
in listToAttrs list;
final = finalize (forAllCrossSystems mkOutput);
in final;
}

View File

@ -1,2 +0,0 @@
let pkgs = import ./default.nix { }; in pkgs.base
# Use the "base" repository build for our shell environment.

View File

@ -1,75 +0,0 @@
# 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"));
preferLocalBuild = true;
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 $out/bin/genode-aarch64-*; do
makeWrapper ''${BIN} aarch64-unknown-genode-''${BIN#$out/bin/genode-aarch64-}
done
for BIN in $out/bin/genode-arm-*; do
makeWrapper ''${BIN} arm-unknown-genode-''${BIN#$out/bin/genode-arm-}
done
for BIN in $out/bin/genode-riscv-*; do
makeWrapper ''${BIN} riscv-unknown-genode-''${BIN#$out/bin/genode-riscv-}
done
for BIN in $out/bin/genode-x86-*; do
makeWrapper ''${BIN} i686-unknown-genode-''${BIN#$out/bin/genode-x86-}
makeWrapper ''${BIN} x86_64-unknown-genode-''${BIN#$out/bin/genode-x86-}
done
popd
'';
} // {
isGNU = true;
targetPrefix = "genode-x86-";
};
wrapped = wrapCC cc;
wrapped' = wrapped.overrideAttrs (attrs: { inherit (cc) targetPrefix; });
in wrapped'

View File

@ -1,8 +0,0 @@
#! /bin/sh
set -e
mkdir -p configs
nix build .#packages.x86_64-linux-x86_64-genode.tupConfigGcc -o configs/x86_64-gcc.config
nix build .#packages.x86_64-linux-x86_64-genode.tupConfigLlvm -o configs/x86_64-llvm.config
nix run nixpkgs#tup -c tup variant configs/x86_64-gcc.config || true
nix run nixpkgs#tup -c tup variant configs/x86_64-llvm.config || true