naersk/builtins/default.nix
Bas van Dijk 8d59785ca6 Pass cargolock/cargotoml via file instead of via env var
Apparently the cargolock env var can become too big so we replace it
with a file. This fixes the following error:

  building
  '/nix/store/s8bv90acizsyvh1s9gk7yvpiyw2gcpnx-dfinity-application-and-others-deps.drv'...
  while setting up the build environment: executing
  '/nix/store/cinw572b38aln37glr0zb8lxwrgaffl4-bash-4.4-p23/bin/bash':
  Argument list too long

See the following on the background of why env vars can become too big:
https://stackoverflow.com/questions/28865473/setting-environment-variable-to-a-large-value-argument-list-too-long
2019-08-26 11:05:41 +02:00

60 lines
1.7 KiB
Nix

# some extra "builtins"
{ lib
, writeText
, runCommand
, remarshal
}:
rec
{
toTOML = import ./to-toml.nix { inherit lib; };
writeTOML = name: attrs: writeText name (toTOML attrs);
readTOML = usePure: f:
if usePure then
builtins.fromTOML (builtins.readFile f)
else
builtins.fromJSON (builtins.readFile (
runCommand "from-toml"
{ buildInputs = [ remarshal ];
allowSubstitutes = false;
preferLocalBuild = true;
}
''
echo "$from_toml_in" > in.toml
remarshal \
-if toml \
-i ${f} \
-of json \
-o $out
''));
writeJSON = name: attrs: writeText name
(builtins.toJSON attrs);
# Returns `true` if `path` exists.
# TODO: use `builtins.pathExists` once
# https://github.com/NixOS/nix/pull/3012 has landed and is generally
# available
pathExists = path:
let
all = lib.all (x: x);
isOk = part:
let
dir = builtins.dirOf part;
basename = builtins.unsafeDiscardStringContext (builtins.baseNameOf part);
dirContent = builtins.readDir dir;
in
builtins.hasAttr basename dirContent &&
# XXX: this may not work if the directory is a symlink
(part == path || dirContent.${basename} == "directory");
parts =
let
# [ "" "nix" "store" "123123" "foo" "bar" ]
parts = lib.splitString "/" path;
len = lib.length parts;
in
map (n: lib.concatStringsSep "/" (lib.take n parts)) (lib.range 3 len);
in
all (map isOk parts);
}