From 033d6283cf0ee02734b20a77c2c80a25744c62db Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Sat, 20 Jun 2020 22:11:52 +0530 Subject: [PATCH] WiP NixOS host test --- flake.nix | 2 +- nixos-modules/default.nix | 2 + nixos-modules/nixos-host.nix | 92 ++++++++++++++++++++++++++++++++++++ tests/default.nix | 8 +++- tests/nixos-host.nix | 48 +++++++++++++++++++ 5 files changed, 149 insertions(+), 3 deletions(-) create mode 100644 nixos-modules/nixos-host.nix create mode 100644 tests/nixos-host.nix diff --git a/flake.nix b/flake.nix index 0da83b8..850ef18 100644 --- a/flake.nix +++ b/flake.nix @@ -157,7 +157,7 @@ ]; }; in import ./tests { - inherit self; + inherit self localSystem; apps = self.apps.${system}; localPackages = nixpkgsFor.${localSystem}; genodepkgs = self.packages.${system}; diff --git a/nixos-modules/default.nix b/nixos-modules/default.nix index 871bafb..c7a5946 100644 --- a/nixos-modules/default.nix +++ b/nixos-modules/default.nix @@ -278,6 +278,8 @@ }; + genodeGuests = import ./nixos-host.nix { inherit self; }; + workman-layout.genode.inputFilter.extraChargen = "${./dhall/workman.chargen.dhall}"; diff --git a/nixos-modules/nixos-host.nix b/nixos-modules/nixos-host.nix new file mode 100644 index 0000000..5bca725 --- /dev/null +++ b/nixos-modules/nixos-host.nix @@ -0,0 +1,92 @@ +# SPDX-License-Identifier: CC0-1.0 + +{ self }: + +{ config, pkgs, lib, ... }: + +{ + options.genodeGuests = with lib; + let + genodeOpts = { ... }: { + options = { + + name = mkOption { + example = "webserver"; + type = types.str; + description = "Name of the Genode subsystem."; + }; + + config = mkOption { + type = types.str; + default = ""; + description = '' + Configuration of the Genode subsystem. + Must be rendered in the Genode XML format. + ''; + }; + + rom = mkOption { + default = pkgs: { }; + description = '' + Function taking a package set and returning an attrset of name to store + path mappings. Note that this set is the Nixpkgs collection, the native + Genode packages are found within this set at "genodePackages". + ''; + example = literalExample '' + pkgs: { + nic_drv = "${pkgs.genodePackages.linux_nic_drv}/bin/linux_nic_drv"; + } + ''; + }; + + }; + }; + + in mkOption { + type = with lib.types; loaOf (submodule genodeOpts); + default = { }; + example = { + foobar = { + config = ""; + rom = pkgs: { }; + }; + }; + description = "Configurations of Genode subsystems."; + }; + + config = let + crossSystem = config.nixpkgs.localSystem.system + "-" + + pkgs.targetPlatform.platform.kernelArch + "-genode"; + crossPkgs = builtins.trace crossSystem self.legacyPackages.${crossSystem}; + in { + + systemd.services = let + inherit (crossPkgs.genodePackages) base-linux; + toService = name: cfg: { + description = "Genode subsystem"; + wantedBy = [ "multi-user.target" ]; + + preStart = let + rom' = with crossPkgs.genodePackages; + { + core = "${base-linux}/bin/core-linux"; + init = "${init}/bin/init"; + "ld.lib.so" = "${base-linux}/bin/ld.lib.so"; + timer = "${base-linux}/bin/linux_timer_drv"; + config = builtins.toFile "${name}.config.xml" cfg.config; + } // (cfg.rom crossPkgs); + in builtins.concatStringsSep "\n" + (lib.mapAttrsToList (name: value: "ln -s ${value} ${name}") rom'); + + serviceConfig = { + DynamicUser = true; + RuntimeDirectory = "genode/" + name; + WorkingDirectory = "/run/genode/" + name; + ExecStart = "${base-linux}/bin/core-linux"; + }; + }; + in lib.mapAttrs toService config.genodeGuests; + + }; + +} diff --git a/tests/default.nix b/tests/default.nix index eda496f..fae971c 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -1,6 +1,7 @@ # SPDX-License-Identifier: CC0-1.0 -{ self, apps, localPackages, genodepkgs, lib, nixpkgs, legacyPackages }: +{ self, localSystem, apps, localPackages, genodepkgs, lib, nixpkgs +, legacyPackages }: let @@ -282,7 +283,10 @@ let in lib.lists.crossLists f [ cores' testFiles ]; -in builtins.listToAttrs (builtins.filter (_: _ != null) testList) +in builtins.listToAttrs (builtins.filter (_: _ != null) testList) // { + nixos-host = + import ./nixos-host.nix { inherit self localSystem legacyPackages; }; +} /* sotest = let hwTests = with hw; [ multi posix x86 ]; diff --git a/tests/nixos-host.nix b/tests/nixos-host.nix new file mode 100644 index 0000000..a4f8370 --- /dev/null +++ b/tests/nixos-host.nix @@ -0,0 +1,48 @@ +{ self, localSystem, legacyPackages }: + +import "${self.inputs.nixpkgs}/nixos/tests/make-test-python.nix" +({ pkgs, ... }: { + name = "genode-guest"; + # meta.maintainers = [ pkgs.lib.maintainers.ehmry ]; + + machine = { + imports = [ self.nixosModules.genodeGuests ]; + genodeGuests.signal-test = { + config = '' + + + + + + + + + + + + + + + + + + + + + ''; + rom = pkgs: { + "test-signal" = + "${pkgs.genodeSources.depot "test-signal"}/bin/test-signal"; + }; + }; + }; + + testScript = '' + start_all() + machine.wait_for_unit("genode") + machine.wait_for_open_port("1965") + ''; +}) { + system = localSystem; + pkgs = legacyPackages.buildPackages; +}