2019-10-28 20:19:52 +01:00
|
|
|
{
|
2021-03-28 15:20:19 +02:00
|
|
|
description = "Nix flavored Genode distribution";
|
2019-10-28 20:19:52 +01:00
|
|
|
|
2021-02-18 19:42:23 +01:00
|
|
|
inputs.nixpkgs.url = "github:ehmry/nixpkgs/genodepkgs";
|
|
|
|
|
2021-02-08 11:37:04 +01:00
|
|
|
outputs = { self, nixpkgs, nimble }:
|
2019-11-05 17:38:47 +01:00
|
|
|
let
|
2021-01-30 11:16:14 +01:00
|
|
|
systems = {
|
2021-03-09 21:43:23 +01:00
|
|
|
localSystem = [ "x86_64-linux" ]; # build platforms
|
|
|
|
crossSystem = [ "aarch64-genode" "x86_64-genode" ]; # target platforms
|
2021-01-30 11:16:14 +01:00
|
|
|
};
|
2019-12-20 08:38:34 +01:00
|
|
|
|
2021-03-09 21:43:23 +01:00
|
|
|
systemSpace =
|
|
|
|
# All combinations of build and target systems
|
|
|
|
nixpkgs.lib.cartesianProductOfSets systems;
|
|
|
|
|
|
|
|
forAllLocalSystems =
|
|
|
|
# Apply a function over all self-hosting (Linux) systems.
|
|
|
|
f:
|
2021-01-30 11:16:14 +01:00
|
|
|
nixpkgs.lib.genAttrs systems.localSystem (system: f system);
|
2020-03-21 17:08:37 +01:00
|
|
|
|
2021-03-09 21:43:23 +01:00
|
|
|
forAllCrossSystems =
|
|
|
|
# Apply a function over all cross-compiled systems (Genode).
|
|
|
|
f:
|
2019-12-20 08:38:34 +01:00
|
|
|
with builtins;
|
|
|
|
let
|
2021-01-30 11:16:14 +01:00
|
|
|
f' = { localSystem, crossSystem }:
|
2019-12-20 08:38:34 +01:00
|
|
|
let system = localSystem + "-" + crossSystem;
|
|
|
|
in {
|
|
|
|
name = system;
|
|
|
|
value = f { inherit system localSystem crossSystem; };
|
|
|
|
};
|
2021-01-30 11:16:14 +01:00
|
|
|
list = map f' systemSpace;
|
2019-12-20 08:38:34 +01:00
|
|
|
attrSet = listToAttrs list;
|
|
|
|
in attrSet;
|
|
|
|
|
2021-03-09 21:43:23 +01:00
|
|
|
forAllSystems =
|
|
|
|
# Apply a function over all Linux and Genode systems.
|
|
|
|
f:
|
2020-03-21 17:08:37 +01:00
|
|
|
(forAllCrossSystems f) // (forAllLocalSystems (system:
|
|
|
|
f {
|
|
|
|
inherit system;
|
|
|
|
localSystem = system;
|
|
|
|
crossSystem = system;
|
|
|
|
}));
|
|
|
|
|
|
|
|
in rec {
|
|
|
|
|
2020-08-02 16:46:34 +02:00
|
|
|
overlay =
|
2021-03-09 21:43:23 +01:00
|
|
|
# Overlay of adjustments applied to Nixpkgs as well as
|
|
|
|
# the "genodePackages" set which the "packages"
|
|
|
|
# output of this flake is taken.
|
2020-10-22 19:58:10 +02:00
|
|
|
import ./overlay { flake = self; };
|
2020-03-21 17:08:37 +01:00
|
|
|
|
2020-08-02 16:46:34 +02:00
|
|
|
lib =
|
|
|
|
# Local utilities merged with the Nixpkgs lib
|
2021-01-05 15:11:42 +01:00
|
|
|
nixpkgs.lib.extend (final: prev: {
|
|
|
|
inherit forAllSystems forAllLocalSystems forAllCrossSystems;
|
|
|
|
|
2021-03-09 21:43:23 +01:00
|
|
|
getEris =
|
|
|
|
# For a the name of a derivation output and a derivation,
|
|
|
|
# generate a set of { cap, closure, and path } for a singular
|
|
|
|
# file found within the subdirectory of the output with the
|
|
|
|
# same name as that output. In the case that the derivation
|
|
|
|
# does not have this named output, the subdirectory will be
|
|
|
|
# taken from the default output. This subdirectory must
|
|
|
|
# contain a single file, and the output must contain an
|
|
|
|
# ERIS manifest file.
|
|
|
|
output: pkg:
|
2021-02-08 11:37:04 +01:00
|
|
|
with builtins;
|
|
|
|
let
|
|
|
|
pkg' = prev.getOutput output pkg;
|
|
|
|
erisInfo =
|
|
|
|
fromJSON (readFile "${pkg'}/nix-support/eris-manifest.json");
|
|
|
|
caps = filter
|
|
|
|
({ path, ... }: prev.strings.hasPrefix "${pkg'}/${output}" path)
|
|
|
|
(prev.attrsets.mapAttrsToList (path:
|
|
|
|
{ cap, closure }: {
|
|
|
|
path = "${pkg'}${
|
|
|
|
substring (stringLength pkg') (stringLength path) path
|
|
|
|
}"; # hack to build a string with context
|
|
|
|
inherit cap closure;
|
|
|
|
}) erisInfo);
|
|
|
|
in assert length caps == 1; head caps;
|
|
|
|
|
2021-03-04 15:02:39 +01:00
|
|
|
getEris' = output: pkg: file:
|
|
|
|
# A variant of the getEris function with file selection.
|
|
|
|
with builtins;
|
|
|
|
let
|
|
|
|
pkg' = prev.getOutput output pkg;
|
|
|
|
path' = "${pkg'}/${output}/${file}";
|
|
|
|
erisInfo =
|
|
|
|
fromJSON (readFile "${pkg'}/nix-support/eris-manifest.json");
|
|
|
|
caps = filter ({ path, ... }: path == path')
|
|
|
|
(prev.attrsets.mapAttrsToList (path:
|
|
|
|
{ cap, closure }: {
|
|
|
|
path = "${pkg'}${
|
|
|
|
substring (stringLength pkg') (stringLength path') path'
|
|
|
|
}"; # hack to build a string with context
|
|
|
|
inherit cap closure;
|
|
|
|
}) erisInfo);
|
|
|
|
in assert length caps == 1; head caps;
|
|
|
|
|
2021-03-24 11:33:07 +01:00
|
|
|
generators = prev.generators // rec {
|
|
|
|
toDhall = x:
|
|
|
|
with builtins;
|
|
|
|
let concatItems = final.strings.concatStringsSep ", ";
|
|
|
|
in if isAttrs x then
|
|
|
|
"{ ${
|
|
|
|
concatItems (prev.attrsets.mapAttrsToList
|
|
|
|
(key: value: "${key} = ${toDhall value}") x)
|
|
|
|
} }"
|
|
|
|
else if isList x then
|
|
|
|
"[ ${concatItems (map toDhall x)} ]"
|
|
|
|
else if isString x || isPath x then
|
|
|
|
''"${x}"''
|
|
|
|
else if isInt x then
|
|
|
|
"${if x < 0 then "" else "+"}${toString}"
|
|
|
|
else if isFloat x then
|
|
|
|
toString x
|
|
|
|
else if isBool x then
|
|
|
|
(if x then "True" else "False")
|
|
|
|
else
|
|
|
|
"abort generators.toDhall: unhandled value (${x})";
|
|
|
|
};
|
|
|
|
|
2021-04-02 11:15:15 +02:00
|
|
|
uuidFrom = seed:
|
|
|
|
let digest = builtins.hashString "sha256" seed;
|
|
|
|
in (lib.lists.foldl ({ str, off }:
|
|
|
|
n:
|
|
|
|
let chunk = builtins.substring off n digest;
|
|
|
|
in {
|
|
|
|
str = if off == 0 then chunk else "${str}-${chunk}";
|
|
|
|
off = off + n;
|
|
|
|
}) {
|
|
|
|
str = "";
|
|
|
|
off = 0;
|
|
|
|
} [ 8 4 4 4 12 ]).str;
|
|
|
|
|
2021-03-09 21:43:23 +01:00
|
|
|
nixosSystem =
|
|
|
|
# A derivative of the function for generating Linux NixOS systems.
|
|
|
|
# This one is not so well tested…
|
|
|
|
{ modules, ... }@args:
|
2021-01-05 15:11:42 +01:00
|
|
|
import "${nixpkgs}/nixos/lib/eval-config.nix" (args // {
|
2021-02-08 11:37:04 +01:00
|
|
|
lib = final;
|
2021-01-05 15:11:42 +01:00
|
|
|
|
|
|
|
baseModules =
|
|
|
|
# TODO: do not blacklist modules for the Linux guests
|
|
|
|
with builtins;
|
|
|
|
let
|
|
|
|
isNotModule = suffix:
|
|
|
|
let x = "${nixpkgs}/nixos/modules/${suffix}";
|
|
|
|
in y: x != y;
|
|
|
|
|
|
|
|
filters = map isNotModule
|
|
|
|
(import ./nixos-modules/base-modules-blacklist.nix);
|
|
|
|
|
|
|
|
isCompatible = p:
|
|
|
|
let p' = toString p;
|
|
|
|
in all (f: f p') filters;
|
|
|
|
|
|
|
|
in filter isCompatible
|
|
|
|
(import "${nixpkgs}/nixos/modules/module-list.nix");
|
|
|
|
|
|
|
|
modules = modules ++ [
|
|
|
|
({ config, lib, ... }: {
|
|
|
|
options = with lib; {
|
|
|
|
|
|
|
|
system.boot.loader.id = mkOption {
|
|
|
|
internal = true;
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
|
|
|
|
system.boot.loader.kernelFile = mkOption {
|
|
|
|
internal = true;
|
|
|
|
default = pkgs.stdenv.hostPlatform.platform.kernelTarget;
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
system.boot.loader.initrdFile = mkOption {
|
|
|
|
internal = true;
|
|
|
|
default = "initrd";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.defaultUnit = mkOption {
|
|
|
|
default = "multi-user.target";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
config = {
|
|
|
|
|
|
|
|
boot.loader.grub.enable = lib.mkDefault false;
|
|
|
|
|
|
|
|
fileSystems."/" = { };
|
|
|
|
|
|
|
|
networking.enableIPv6 = lib.mkForce false;
|
|
|
|
systemd.network.enable = lib.mkForce false;
|
|
|
|
|
|
|
|
system.nixos.versionSuffix = ".${
|
|
|
|
final.substring 0 8
|
|
|
|
(self.lastModifiedDate or self.lastModified or "19700101")
|
|
|
|
}.${self.shortRev or "dirty"}";
|
|
|
|
|
|
|
|
system.nixos.revision = final.mkIf (self ? rev) self.rev;
|
|
|
|
|
|
|
|
system.build.toplevel = config.system.build.initXml;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
})
|
|
|
|
];
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2020-03-21 17:08:37 +01:00
|
|
|
|
2021-03-09 21:43:23 +01:00
|
|
|
legacyPackages =
|
|
|
|
# The nixpkgs.legacyPackages set after overlaying.
|
|
|
|
let f = import nixpkgs;
|
|
|
|
in forAllSystems ({ system, localSystem, crossSystem }:
|
|
|
|
if localSystem == crossSystem then
|
2021-03-26 10:19:54 +01:00
|
|
|
nixpkgs.legacyPackages.${system}.extend self.overlay
|
2021-03-09 21:43:23 +01:00
|
|
|
else
|
|
|
|
f {
|
|
|
|
inherit localSystem;
|
|
|
|
crossSystem = {
|
|
|
|
system = crossSystem;
|
|
|
|
useLLVM = true;
|
|
|
|
};
|
|
|
|
config.allowUnsupportedSystem = true;
|
2021-03-15 11:52:57 +01:00
|
|
|
overlays = [ self.overlay ];
|
2021-03-09 21:43:23 +01:00
|
|
|
});
|
2020-03-21 17:08:37 +01:00
|
|
|
|
2020-08-02 16:46:34 +02:00
|
|
|
packages =
|
|
|
|
# Genode native packages, not packages in the traditional
|
2021-03-09 21:43:23 +01:00
|
|
|
# sense in that these cannot be installed within a profile.
|
2020-08-02 16:46:34 +02:00
|
|
|
forAllCrossSystems ({ system, localSystem, crossSystem }:
|
|
|
|
nixpkgs.lib.filterAttrs (n: v: v != null)
|
2021-03-02 23:35:55 +01:00
|
|
|
self.legacyPackages.${system}.genodePackages);
|
2020-03-21 17:08:37 +01:00
|
|
|
|
2020-08-02 16:46:34 +02:00
|
|
|
devShell =
|
|
|
|
# Development shell for working with the
|
2021-03-09 21:43:23 +01:00
|
|
|
# upstream Genode source repositories. Some
|
|
|
|
# things are missing but everything referred
|
|
|
|
# to by way of #!/usr/bin/ should be here.
|
2020-08-02 16:46:34 +02:00
|
|
|
forAllLocalSystems (system:
|
|
|
|
let
|
2021-02-06 15:11:53 +01:00
|
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
2020-08-02 16:46:34 +02:00
|
|
|
fhs = pkgs.buildFHSUserEnv {
|
|
|
|
name = "genode-env";
|
|
|
|
targetPkgs = pkgs:
|
|
|
|
(with pkgs; [
|
|
|
|
binutils
|
|
|
|
bison
|
|
|
|
expect
|
|
|
|
flex
|
|
|
|
git
|
|
|
|
glibc.dev
|
|
|
|
gnumake
|
|
|
|
libxml2
|
|
|
|
qemu
|
2021-02-06 15:11:53 +01:00
|
|
|
rpcsvc-proto
|
|
|
|
subversion
|
2020-08-02 16:46:34 +02:00
|
|
|
tcl
|
2021-02-06 15:11:53 +01:00
|
|
|
wget
|
2020-08-02 16:46:34 +02:00
|
|
|
which
|
|
|
|
xorriso
|
|
|
|
]);
|
|
|
|
runScript = "bash";
|
|
|
|
extraBuildCommands = let
|
|
|
|
toolchain = pkgs.fetchzip {
|
|
|
|
url =
|
|
|
|
"file://${packages.x86_64-linux-x86_64-genode.genodeSources.toolchain.src}";
|
|
|
|
hash = "sha256-26rPvLUPEJm40zLSqTquwuFTJ1idTB0T4VXgaHRN+4o=";
|
|
|
|
};
|
|
|
|
in "ln -s ${toolchain}/local usr/local";
|
2020-06-08 14:18:40 +02:00
|
|
|
};
|
2020-08-02 16:46:34 +02:00
|
|
|
in pkgs.stdenv.mkDerivation {
|
|
|
|
name = "genode-fhs-shell";
|
|
|
|
nativeBuildInputs = [ fhs ];
|
|
|
|
shellHook = "exec genode-env";
|
2020-03-24 13:47:30 +01:00
|
|
|
});
|
2020-06-08 14:18:40 +02:00
|
|
|
|
2020-12-10 20:23:53 +01:00
|
|
|
nixosModules =
|
2021-03-09 21:43:23 +01:00
|
|
|
# Modules for composing Genode and NixOS.
|
2020-12-10 20:23:53 +01:00
|
|
|
import ./nixos-modules { flake = self; };
|
|
|
|
|
2020-08-02 16:46:34 +02:00
|
|
|
checks =
|
2021-03-09 21:43:23 +01:00
|
|
|
# Checks for continous testing.
|
2020-11-01 20:21:27 +01:00
|
|
|
let tests = import ./tests;
|
|
|
|
in with (forAllCrossSystems ({ system, localSystem, crossSystem }:
|
|
|
|
tests {
|
|
|
|
flake = self;
|
|
|
|
inherit system localSystem crossSystem;
|
|
|
|
pkgs = self.legacyPackages.${system};
|
2020-08-15 19:54:01 +02:00
|
|
|
} // {
|
2021-03-02 23:35:55 +01:00
|
|
|
ports = self.legacyPackages.${localSystem}.symlinkJoin {
|
2020-08-15 19:54:01 +02:00
|
|
|
name = "ports";
|
|
|
|
paths = (builtins.attrValues
|
|
|
|
self.packages.${system}.genodeSources.ports);
|
|
|
|
};
|
2020-09-18 00:56:24 +02:00
|
|
|
})); {
|
|
|
|
x86_64-linux = x86_64-linux-aarch64-genode
|
|
|
|
// x86_64-linux-x86_64-genode;
|
|
|
|
};
|
2020-06-08 14:18:40 +02:00
|
|
|
|
2020-12-02 13:06:00 +01:00
|
|
|
hydraJobs = self.checks;
|
|
|
|
|
2020-03-21 17:08:37 +01:00
|
|
|
};
|
2019-10-28 20:19:52 +01:00
|
|
|
}
|