anchor.diff:  
   
   # Keep extra attributes from `attrs`, e.g., `patchPhase', etc.
  -if disabled
  -then throw "${name} not supported for interpreter ${lua}"
  -else
   
   let
  -
  -  deps_dirs= lib.concatStringsSep ", " (
  -    map (x: "\"${builtins.toString x}\"") external_deps
  -  );
  -
  -  # TODO
  -  # - add rocktrees (look at torch-distro.nix/https://github.com/luarocks/luarocks/wiki/Config-file-format)
  -  # - silence warnings
  -  luarocks_config = "luarocksConfig";
  +  # TODO fix warnings "Couldn't load rockspec for ..." during manifest
  +  # construction -- from initial investigation, appears it will require
  +  # upstream luarocks changes to fix cleanly (during manifest construction,
  +  # luarocks only looks for rockspecs in the default/system tree instead of all
  +  # configured trees)
  +  luarocks_config = "luarocks-config.lua";
     luarocks_content = ''
       local_cache = ""
  -    -- array of strings
  +    -- To prevent collisions when creating environments, we install the rock
  +    -- files into per-package subdirectories
  +    rocks_subdir = '${rocksSubdir}'
  +    -- Then we need to tell luarocks where to find the rock files per
  +    -- dependency
  +    rocks_trees = {
  +      ${lib.concatStringsSep "\n, " rocksTrees}
  +    }
  +  '' + lib.optionalString lua.pkgs.isLuaJIT ''
  +    -- Luajit provides some additional functionality built-in; this exposes
  +    -- that to luarock's dependency system
  +    rocks_provided = {
  +      jit='${lua.luaversion}-1';
  +      ffi='${lua.luaversion}-1';
  +      luaffi='${lua.luaversion}-1';
  +      bit='${lua.luaversion}-1';
  +    }
  +  '' + ''
  +    -- For single-output external dependencies
       external_deps_dirs = {
  -    ${deps_dirs}
  -    }
  -    rocks_trees = {
  +      ${lib.concatStringsSep "\n, " externalDepsDirs}
  +    }
  +    variables = {
  +      -- Some needed machinery to handle multiple-output external dependencies,
  +      -- as per https://github.com/luarocks/luarocks/issues/766
  +      ${lib.optionalString (lib.length depVariables > 0) ''
  +      ${lib.concatStringsSep "\n  " depVariables}''}
  +      ${extraVariables}
       }
       ${extraConfig}
     '';
  +
  +  rocksSubdir = "${attrs.pname}-${version}-rocks";
  +
  +  externalDepsDirs = map
  +    (x: "'${builtins.toString x}'")
  +    (lib.filter (lib.isDerivation) externalDeps);
  +
  +  rocksTrees = lib.imap0
  +    (i: dep: "{ name = [[dep-${toString i}]], root = '${dep}', rocks_dir = '${dep}/${dep.rocksSubdir}' }")
  +    requiredLuaRocks;
  +
  +  # Filter out the lua derivation itself from the Lua module dependency
  +  # closure, as it doesn't have a rock tree :)
  +  requiredLuaRocks = lib.filter (d: d ? luaModule)
  +    (lua.pkgs.requiredLuaModules propagatedBuildInputs);
  +
  +  # Explicitly point luarocks to the relevant locations for multiple-output
  +  # derivations that are external dependencies, to work around an issue it has
  +  # (https://github.com/luarocks/luarocks/issues/766)
  +  depVariables = lib.concatMap ({name, dep}: [
  +    "${name}_INCDIR='${lib.getDev dep}/include';"
  +    "${name}_LIBDIR='${lib.getLib dep}/lib';"
  +    "${name}_BINDIR='${lib.getBin dep}/bin';"
  +  ]) externalDeps';
  +
  +  # example externalDeps': [ { name = "CRYPTO"; dep = pkgs.openssl; } ]
  +  externalDeps' = lib.filter (dep: !lib.isDerivation dep) externalDeps;
   in
   toLuaModule ( lua.stdenv.mkDerivation (
  -builtins.removeAttrs attrs ["disabled" "checkInputs"] // {
  +builtins.removeAttrs attrs ["disabled" "checkInputs" "externalDeps"] // {
   
     name = namePrefix + name;
   
     buildInputs = [ wrapLua lua.pkgs.luarocks ]
       ++ buildInputs
       ++ lib.optionals doCheck checkInputs
  +    ++ (map (d: d.dep) externalDeps')
       ;
   
     # propagate lua to active setup-hook in nix-shell
     propagatedBuildInputs = propagatedBuildInputs ++ [ lua ];
  -  doCheck = false;
  +  inherit doCheck;
  +
  +  # @-patterns do not capture formal argument default values, so we need to
  +  # explicitly inherit this for it to be available as a shell variable in the
  +  # builder
  +  inherit rockspecFilename;
  +  inherit rocksSubdir;
   
     # enabled only for src.rock
     setSourceRoot= let
  
positive.code: , passthru ? {}
  , doCheck ? false
  
  # appended to the luarocks generated config
  # in peculiar variables like { EVENT_INCDIR } can be useful to work around
  # luarocks limitations, ie, luarocks consider include/lib folders to be subfolders of the same package in external_deps_dirs
  # as explained in https://github.com/luarocks/luarocks/issues/766
  , extraConfig ? ""
  
  # relative to srcRoot, path to the rockspec to use when using rocks
  , rockspecFilename ?  "../*.rockspec"
  
negative.code: , propagatedNativeBuildInputs ? []
  
  # used to disable derivation, useful for specific lua versions
  # TODO move from this setting meta.broken to a 'disabled' attribute on the
  # package, then use that to skip/include in each lua${ver}Packages set?
  , disabled ? false
  
  # Additional arguments to pass to the makeWrapper function, which wraps
  # generated binaries.
  , makeWrapperArgs ? []
  
  # Skip wrapping of lua programs altogether
  , dontWrapLuaPrograms ? false
  