2
0
Fork 0
genodepkgs/flake.nix

259 lines
8.9 KiB
Nix
Raw Normal View History

2020-01-17 01:24:34 +01:00
# SPDX-License-Identifier: CC0-1.0
2019-10-28 20:19:52 +01:00
{
edition = 201909;
2019-11-05 17:38:47 +01:00
description = "Genode packages";
2019-10-28 20:19:52 +01:00
inputs.nixpkgs.url = "github:ehmry/nixpkgs/genode";
outputs = { self, nixpkgs }:
2019-11-05 17:38:47 +01:00
let
2020-08-05 10:41:57 +02:00
localSystems = [ "aarch64-linux" "x86_64-linux" ];
crossSystems = [ "aarch64-genode" "x86_64-genode" ];
forAllLocalSystems = f:
nixpkgs.lib.genAttrs localSystems (system: f system);
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;
forAllSystems = f:
(forAllCrossSystems f) // (forAllLocalSystems (system:
f {
inherit system;
localSystem = system;
crossSystem = system;
}));
nixpkgsFor = forAllSystems ({ system, localSystem, crossSystem }:
if localSystem == crossSystem then
2020-03-24 13:47:30 +01:00
import nixpkgs {
inherit system;
overlays = [ self.overlay ];
}
else
import nixpkgs {
2020-03-24 13:47:30 +01:00
inherit localSystem;
crossSystem = {
system = crossSystem;
useLLVM = true;
};
config.allowUnsupportedSystem = true;
overlays = [ self.overlay ];
});
in rec {
2020-08-02 16:46:34 +02:00
overlay =
# Overlay of fixes applied to Nixpkgs
import ./overlay;
2020-08-02 16:46:34 +02:00
lib =
# Local utilities merged with the Nixpkgs lib
forAllCrossSystems ({ system, localSystem, crossSystem }:
nixpkgs.lib // (import ./lib {
inherit system localSystem crossSystem;
apps = self.apps.${system};
genodepkgs = self;
nixpkgs = nixpkgsFor.${system};
}));
2020-08-02 16:46:34 +02:00
legacyPackages =
# The nixpkgs.legacyPackages after overlaying
# and with some additional Genode packages
forAllSystems
({ system, localSystem, crossSystem }: nixpkgsFor.${system});
# pass thru Nixpkgs
2020-08-02 16:46:34 +02:00
packages =
# Genode native packages, not packages in the traditional
# sense in that these cannot be installed within a profile
forAllCrossSystems ({ system, localSystem, crossSystem }:
nixpkgs.lib.filterAttrs (n: v: v != null)
nixpkgsFor.${system}.genodePackages);
2020-08-02 16:46:34 +02:00
devShell =
# Development shell for working with the
# upstream Genode source repositories
forAllLocalSystems (system:
let
pkgs = nixpkgsFor.${system};
fhs = pkgs.buildFHSUserEnv {
name = "genode-env";
targetPkgs = pkgs:
(with pkgs; [
binutils
bison
expect
flex
git
glibc.dev
gnumake
libxml2
qemu
tcl
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-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-08-02 16:46:34 +02:00
apps =
# Utilities accessible via "nix run"
let
apps' = forAllCrossSystems ({ system, localSystem, crossSystem }:
import ./apps {
inherit system;
self = self.apps.${system};
nixpkgs = nixpkgsFor.${system};
nixpkgsLocal = nixpkgsFor.${localSystem};
packages = self.packages.${system};
} // {
nixosModule = {
type = "app";
program =
"${self.checks.${localSystem}.nixosGuest}/bin/run-nixos-vm";
};
});
in apps' // { x86_64-linux = apps'.x86_64-linux-x86_64-genode; };
2020-08-02 16:46:34 +02:00
nixosModules =
# Modules for composing Genode and NixOS
import ./nixos-modules { inherit self; };
2020-08-02 16:46:34 +02:00
checks =
# Checks for continous testing
let
2020-08-02 16:46:34 +02:00
checks' = forAllCrossSystems ({ system, localSystem, crossSystem }:
let
nixos = nixpkgs.lib.nixosSystem {
system = localSystem;
modules = [
self.nixosModules.genodeHost
({ modulesPath, ... }: {
imports = [ "${modulesPath}/virtualisation/qemu-vm.nix" ];
boot.loader.grub.extraEntriesBeforeNixOS = true;
virtualisation = {
cores = 2;
memorySize = 1024;
useBootLoader = true;
qemu = {
options =
[ "-machine q35" "-cpu phenom" "-serial mon:stdio" ];
networkingOptions = [
"-net nic,netdev=user.0,model=e1000"
"-netdev user,id=user.0\${QEMU_NET_OPTS:+,$QEMU_NET_OPTS}"
];
};
};
2020-08-02 16:46:34 +02:00
})
];
};
in import ./tests {
inherit self;
apps = self.apps.${system};
localPackages = nixpkgsFor.${localSystem};
genodepkgs = self.packages.${system};
lib = self.lib.${system};
nixpkgs = nixpkgsFor.${system};
legacyPackages = self.legacyPackages.${system};
} // {
ports = nixpkgsFor.${localSystem}.symlinkJoin {
name = "ports";
paths = (builtins.attrValues
self.packages.${system}.genodeSources.ports);
};
nixosModule = nixos.config.system.build.vm;
nixosXML = nixos.config.system.build.genode.xml;
nixosGuest = let
nixos = nixpkgs.lib.nixosSystem {
system = localSystem;
modules = [
self.nixosModules.genodeHost
({ modulesPath, ... }: {
imports = [ "${modulesPath}/virtualisation/qemu-vm.nix" ];
boot.loader.grub.extraEntriesBeforeNixOS = true;
virtualisation = {
cores = 2;
memorySize = 1024;
useBootLoader = true;
qemu = {
options = [
"-machine q35"
"-cpu phenom"
"-serial mon:stdio"
];
networkingOptions = [
"-net nic,netdev=user.0,model=e1000"
"-netdev user,id=user.0\${QEMU_NET_OPTS:+,$QEMU_NET_OPTS}"
];
2020-06-09 08:25:55 +02:00
};
};
2020-08-02 16:46:34 +02:00
genode.guests = {
flakeCheck = {
config = { config, lib, pkgs, ... }: {
networking.firewall.allowedTCPPorts = [ 80 ];
services.mingetty.autologinUser =
lib.mkDefault "root";
services.nginx.enable = true;
services.openssh.permitRootLogin =
lib.mkDefault "yes";
services.sshd.enable = true;
users.users.root.password = "nixos";
virtualbox.memorySize = 128;
};
};
azimuth = {
bootFormat = "vdi";
config = { config, lib, pkgs, ... }: {
services.cage = {
enable = true;
program = "${pkgs.azimuth}/bin/tor-azimuth";
};
users.users.demo.isNormalUser = true;
virtualbox.memorySize = 1024;
2020-06-09 08:25:55 +02:00
};
};
};
2020-06-09 08:25:55 +02:00
2020-08-02 16:46:34 +02:00
})
];
};
in nixos.config.system.build.vm;
2020-08-02 16:46:34 +02:00
});
in {
aarch64-linux = checks'.aarch64-linux-aarch64-genode;
x86_64-linux = checks'.x86_64-linux-x86_64-genode;
};
};
2019-10-28 20:19:52 +01:00
}