2
0
Fork 0
genodepkgs/nixos-modules/shell.nix

68 lines
1.9 KiB
Nix

{ config, pkgs, lib, ... }:
with lib;
{
options.genode.shells = mkOption {
default = { };
type = with types;
attrsOf (submodule {
options = {
environmentVariables = mkOption {
type = with types; attrsOf (either str (listOf str));
apply =
mapAttrs (n: v: if isList v then concatStringsSep ":" v else v);
};
inputs = mkOption {
description = "List of packages to add to the shell environment";
default = [ ];
type = types.listOf types.package;
};
nic = lib.mkOption {
type = with types; nullOr str;
default = null;
example = "eth0";
description = ''
Grant access to an IP stack for this interface.
Only UDP and TCP are supported. No raw device access.
'';
};
script = mkOption {
type = types.lines;
description = "Shell script to execute";
};
};
});
};
config.genode.init.children = mapAttrs' (name: shell: {
name = name + ".shell";
value = {
inputs = with pkgs;
with genodePackages;
[ bash cached_fs_rom libc posix vfs vfs_pipe ] ++ shell.inputs;
configFile = let
nic =
if shell.nic == null then "None Text" else ''Some "${shell.nic}"'';
env = mapAttrsToList (mapKey: mapValue:
'', { mapKey = "${mapKey}", mapValue = "${mapValue}" }'')
shell.environmentVariables;
in pkgs.writeText "${name}.shell.dhall" ''
let Genode = env:DHALL_GENODE in
${./shell.dhall}
{ name = "${name}"
, coreutils = "${pkgs.coreutils}"
, env = [${toString env} ] : Genode.Prelude.Map.Type Text Text
, nic = ${nic}
, script = "${pkgs.writeText "${name}.shell.script" shell.script}"
}
'';
};
}) config.genode.shells;
}