2
0
Fork 0

Initial NixOS module

A NixOS module for creating base-linux Genode subsystems.
20.02
Emery Hemingway 3 years ago
parent e092f8cc86
commit 1a33ea2f3a
  1. 10
      flake.lock
  2. 25
      flake.nix
  3. 91
      nixos/default.nix
  4. 45
      nixos/test.nix

@ -41,15 +41,15 @@
"url": "git+https://gitea.c3d2.de/ehmry/nixpkgs.git?ref=genode&rev=d63ee96d86672a9cb23d83d50ee02687eded2818"
}
},
"narHash": "sha256-uTHTwa05KzSmRETVBhpHw2CD+cMicqunaaknYsrxAfY=",
"narHash": "sha256-oPigZTib2kL1FVllm4xkf1l8eS9peXi1PFSdvrbYRK0=",
"originalUrl": "git+https://gitea.c3d2.de/ehmry/genode-depot.git",
"url": "git+https://gitea.c3d2.de/ehmry/genode-depot.git?ref=master&rev=ac11a14f9ba10685ae68ab5a050baf546ae702d2"
"url": "git+https://gitea.c3d2.de/ehmry/genode-depot.git?ref=master&rev=a951bb013b0c053e858ccaf3672b7ab85580695d"
},
"nixpkgs": {
"inputs": {},
"narHash": "sha256-/9hMb9pgV8awDYYchUueplyKF6bz23b7z5gqQ999nro=",
"originalUrl": "git+https://gitea.c3d2.de/ehmry/nixpkgs.git?ref=genode",
"url": "git+https://gitea.c3d2.de/ehmry/nixpkgs.git?ref=genode&rev=d63ee96d86672a9cb23d83d50ee02687eded2818"
"narHash": "sha256-aLJ6PHTU1VbWBdyZbI/lLoj2JelUCGgovUsHlnAFIOE=",
"originalUrl": "git+https://github.com/ehmry/nixpkgs?ref=genode-19.09",
"url": "git+https://github.com/ehmry/nixpkgs?ref=genode-19.09&rev=cc2b10a7ed78f62dc2b3afa50d34d613c36e619e"
}
},
"version": 3

@ -8,7 +8,7 @@
"git+https://github.com/dhall-lang/dhall-haskell?ref=flake";
genode-depot.uri = "git+https://gitea.c3d2.de/ehmry/genode-depot.git";
genode.uri = "git+https://gitea.c3d2.de/ehmry/genode.git";
nixpkgs.uri = "git+https://gitea.c3d2.de/ehmry/nixpkgs.git?ref=genode";
nixpkgs.uri = "git+https://github.com/ehmry/nixpkgs?ref=genode-19.09";
};
outputs = { self, dhall-haskell, genode-depot, genode, nixpkgs }:
@ -34,18 +34,29 @@
inherit system nixpkgs;
depot = thisSystem genode-depot.packages;
genode = thisSystem genode.packages;
} // builtins.getAttr system genode.packages);
} // thisSystem genode.packages);
defaultPackage.x86_64-linux =
self.packages.x86_64-linux-x86_64-genode.base-linux;
checks = nixpkgs.lib.forAllCrossSystems
({ system, localSystem, crossSystem }:
import ./tests {
let thisSystem = builtins.getAttr system;
in import ./tests {
inherit self system localSystem crossSystem nixpkgs dhall-haskell
genode-depot;
genodepkgs = builtins.getAttr system self.packages;
lib = builtins.getAttr system self.lib;
genodepkgs = thisSystem self.packages;
lib = thisSystem self.lib;
}) // {
x86_64-linux = self.checks.x86_64-linux-x86_64-genode;
x86_64-linux.nixos =
let pkgs' = nixpkgs.legacyPackages.x86_64-linux // { };
in import ./nixos/test.nix {
nixpkgs = nixpkgs.outPath;
genodepkgs = self.packages.x86_64-linux-x86_64-genode;
depot = genode-depot.packages.x86_64-linux-x86_64-genode;
} { system = "x86_64-linux"; };
};
nixosModule = import ./nixos;
};
}

@ -0,0 +1,91 @@
{ config, pkgs, lib, ... }:
{
options.genode = with lib;
let
genodeOpts = { ... }: {
options = {
name = mkOption {
example = "webserver";
type = types.str;
description = "Name of the Genode subsystem.";
};
depot = mkOption {
type = with types; attrsOf package;
description = ''
Attribute set of Genode depot binaries.
'';
};
pkgs = mkOption {
type = with types; attrsOf package;
description = ''
Attribute set of Genode packages.
'';
};
config = mkOption {
type = types.str;
default = "<config/>";
description = ''
Configuration of the Genode subsystem.
Must be rendering in the Genode XML format.
'';
};
rom = mkOption {
type = with types; attrs;
example = literalExample {
nic_drv = "${depot.ipxe_nic_drv}/bin/ipxe_nic_drv";
};
};
};
};
in mkOption {
type = with lib.types; loaOf (submodule genodeOpts);
default = { };
example = {
foobar = {
config = "<empty/>";
rom = { };
};
};
description = ''
Configurations of Genode subsystems
'';
};
config = {
systemd.services = let
toService = name: cfg: {
description = "Genode subsystem";
wantedBy = [ "multi-user.target" ];
preStart = let
rom' = with cfg.pkgs;
{
core = "${base-linux}/bin/core-linux";
init = "${os}/bin/init";
"ld.lib.so" = "${cfg.depot.base-linux}/lib/ld.lib.so";
timer = "${base-linux}/bin/linux_timer_drv";
config = builtins.toFile "${name}.config.xml" cfg.config;
} // cfg.rom;
in builtins.concatStringsSep "\n"
(lib.mapAttrsToList (name: value: "ln -s ${value} ${name}") rom');
serviceConfig = {
DynamicUser = true;
RuntimeDirectory = "genode/" + name;
WorkingDirectory = "/run/genode/" + name;
ExecStart = "${cfg.pkgs.base-linux}/bin/core-linux";
};
};
in lib.mapAttrs toService config.genode;
};
}

@ -0,0 +1,45 @@
{ nixpkgs, genodepkgs, depot }:
import (nixpkgs + "/nixos/tests/make-test.nix") ({ pkgs, ... }:
rec {
name = "genode-base-linux";
machine = { pkgs, ... }:
{
imports = [ ./. ];
genode.signal-test = {
config = ''
<config>
<parent-provides>
<service name="ROM"/>
<service name="CPU"/>
<service name="RM"/>
<service name="PD"/>
<service name="LOG"/>
</parent-provides>
<default-route>
<any-service> <parent/> <any-child/> </any-service>
</default-route>
<default caps="100"/>
<start name="timer" caps="96">
<resource name="RAM" quantum="1M"/>
<provides><service name="Timer"/></provides>
</start>
<start name="test-signal" caps="500">
<resource name="RAM" quantum="10M"/>
</start>
</config>
'';
depot = depot;
pkgs = genodepkgs;
rom = { "test-signal" = "${genodepkgs.os}/bin/test-signal"; };
};
};
testScript = ''
$machine->waitUntilSucceeds("journalctl -u signal-test | grep -q -i -- '--- Signalling test finished ---'");
'';
})
Loading…
Cancel
Save