From ea0cb3a36499ef498b5e36d8fa95e95f4cee99ed Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Tue, 24 May 2022 23:10:38 -0500 Subject: [PATCH] New getEris functions --- flake.nix | 61 +++++++++++------------------- nixos-modules/eris/default.nix | 2 +- nixos-modules/genode-core.nix | 2 +- nixos-modules/gui/default.nix | 12 +++--- nixos-modules/hardware/default.nix | 6 +-- nixos-modules/lib/children.nix | 2 +- nixos-modules/services/tor.nix | 6 +-- tests/bash.nix | 9 +++-- 8 files changed, 42 insertions(+), 58 deletions(-) diff --git a/flake.nix b/flake.nix index 8d79153..d428ede 100644 --- a/flake.nix +++ b/flake.nix @@ -62,49 +62,32 @@ nixpkgs.lib.extend (final: prev: { inherit forAllSystems forAllLocalSystems forAllCrossSystems; - 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: + getMainProgram = pkg: with builtins; - let - pkg' = prev.getOutput output pkg; - erisInfo = fromJSON (builtins.unsafeDiscardStringContext - (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; + if hasAttr "mainProgram" pkg.meta then + pkg.meta.mainProgram + else + trace "${pkg.name} is missing meta.mainProgram" pkg.pname; - getEris' = output: pkg: file: - # A variant of the getEris function with file selection. + getEris = filename: pkg: with builtins; let - pkg' = prev.getOutput output pkg; - path' = "${pkg'}/${output}/${file}"; - erisInfo = fromJSON (builtins.unsafeDiscardStringContext - (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; + manifest = fromJSON (unsafeDiscardStringContext + (readFile "${pkg}/nix-support/eris-manifest.json")); + entry = manifest.${filename}; + in entry // { + cap = "(${pkg}/nix-support/eris-manifest.dhall).${filename}.cap"; + path = "${pkg}${ + substring (stringLength pkg) (stringLength entry.path) + entry.path + }"; # hack to build a string with context + }; + + getErisMainProgram = pkg: + final.getEris (final.getMainProgram pkg) (prev.getOutput "bin" pkg); + + getErisLib = filename: pkg: + final.getEris filename (prev.getOutput "lib" pkg); uuidFrom = seed: let digest = builtins.hashString "sha256" seed; diff --git a/nixos-modules/eris/default.nix b/nixos-modules/eris/default.nix index 1ca028b..53901e2 100644 --- a/nixos-modules/eris/default.nix +++ b/nixos-modules/eris/default.nix @@ -8,7 +8,7 @@ genode.core.children.eris_vfs = { fs = let - vfsRump = lib.getEris' "lib" pkgs.genodePackages.rump "vfs_rump.lib.so"; + vfsRump = lib.getErisLib "vfs_rump.lib.so" pkgs.genodePackages.rump; in { package = pkgs.genodePackages.vfs; extraErisInputs = [ vfsRump ]; diff --git a/nixos-modules/genode-core.nix b/nixos-modules/genode-core.nix index 9e7b298..a20d1e1 100644 --- a/nixos-modules/genode-core.nix +++ b/nixos-modules/genode-core.nix @@ -13,7 +13,7 @@ let let pkg = pkgs.genodePackages.${name}; in { inherit name; - value = lib.getEris "bin" pkg; + value = lib.getErisMainProgram pkg; }) pkgNames); tarball = diff --git a/nixos-modules/gui/default.nix b/nixos-modules/gui/default.nix index ddcc684..1f3d321 100644 --- a/nixos-modules/gui/default.nix +++ b/nixos-modules/gui/default.nix @@ -73,9 +73,9 @@ in { genode.core.children.gui = lib.mkIf cfg.enable (let eris = with pkgs.genodePackages; - lib.attrsets.mapAttrs (_: lib.getEris "bin") { + lib.attrsets.mapAttrs (_: lib.getErisMainProgram) { inherit decorator window_layouter wm; - } // (let nitpick = lib.getEris' "bin" nitpicker; + } // (let nitpick = lib.getErisMainProgram nitpicker; in { nitpicker = nitpick "nitpicker"; pointer = nitpick "pointer"; @@ -97,11 +97,11 @@ in { }; genode.core.children.consoleLog = lib.mkIf cfg.consoleLog.enable (let - erisInputs = (lib.attrsets.mapAttrs (_: lib.getEris "bin") { + erisInputs = (lib.attrsets.mapAttrs (_: lib.getErisMainProgram) { inherit (pkgs.genodePackages) log_core terminal terminal_log; - }) // (lib.attrsets.mapAttrs (_: lib.getEris "lib") { - inherit (pkgs.genodePackages) vfs_ttf; - }); + }) // { + vfs_ttf = lib.getErisLib "vfs_ttf.lib.so" pkgs.genodePackages.vfs_ttf; + }; in { package = pkgs.genodePackages.init; coreROMs = [ "core_log" "kernel_log" ]; diff --git a/nixos-modules/hardware/default.nix b/nixos-modules/hardware/default.nix index 5dee78b..a6879ad 100644 --- a/nixos-modules/hardware/default.nix +++ b/nixos-modules/hardware/default.nix @@ -22,10 +22,10 @@ in { config = let deviceManagerEnable = cfg.ahci.enable || cfg.usb.enable; - ahciEris = lib.getEris "bin" pkgs.genodePackages.ahci_drv; - partBlockEris = lib.getEris "bin" pkgs.genodePackages.part_block; + ahciEris = lib.getErisMainProgram pkgs.genodePackages.ahci_drv; + partBlockEris = lib.getErisMainProgram pkgs.genodePackages.part_block; - usbEris = lib.attrsets.mapAttrs (_: lib.getEris "bin") { + usbEris = lib.attrsets.mapAttrs (_: lib.getErisMainProgram) { usb_block_drv = cfg.usb.storage.package; usb_host_drv = cfg.usb.host.package; }; diff --git a/nixos-modules/lib/children.nix b/nixos-modules/lib/children.nix index 9f03f60..eacdcb7 100644 --- a/nixos-modules/lib/children.nix +++ b/nixos-modules/lib/children.nix @@ -84,7 +84,7 @@ config = ''${configFile} "${binary}"''; roms = extraRoms; } else - let bin = lib.getEris "bin" package; + let bin = lib.getErisMainProgram package; in { config = ''${configFile} "${bin.cap}"''; roms = toRoms bin ++ extraRoms; diff --git a/nixos-modules/services/tor.nix b/nixos-modules/services/tor.nix index 0c679b1..9195199 100644 --- a/nixos-modules/services/tor.nix +++ b/nixos-modules/services/tor.nix @@ -7,9 +7,9 @@ in { genode.init.children.tor = let args = lib.strings.splitString " " config.systemd.services.tor.serviceConfig.ExecStart; - tor' = lib.getEris' "bin" pkgs.tor "tor"; - lwip' = lib.getEris "lib" pkgs.genodePackages.vfs_lwip; - pipe' = lib.getEris "lib" pkgs.genodePackages.vfs_pipe; + tor' = lib.getErisMainProgram pkgs.tor; + lwip' = lib.getErisLib "vfs_lwip.lib.so" pkgs.genodePackages.vfs_lwip; + pipe' = lib.getErisLib "vfs_pipe.lib.so" pkgs.genodePackages.vfs_pipe; in { binary = builtins.head args; package = pkgs.tor; diff --git a/tests/bash.nix b/tests/bash.nix index 92a95dd..f5d994c 100644 --- a/tests/bash.nix +++ b/tests/bash.nix @@ -5,10 +5,11 @@ in { genode.init.children.bash = let extraErisInputs' = with pkgs.genodePackages; { - bash = lib.getEris "bin" pkgs.bash; - cached_fs_rom = lib.getEris "bin" cached_fs_rom; - vfs = lib.getEris "bin" vfs; - vfs_pipe = lib.getEris "lib" vfs_pipe; + bash = + lib.getErisMainProgram "bash" (pkgs.bash // { pname = "bash"; }); + cached_fs_rom = lib.getErisMainProgram cached_fs_rom; + vfs = lib.getErisMainProgram vfs; + vfs_pipe = lib.getErisLib "vfs_pipe.lib.so" vfs_pipe; }; params = { bash = "${pkgs.bash}";