You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

70 lines
2.0 KiB

  1. /* GNU Guix --- Functional package management for GNU
  2. Copyright (C) 2016 Ludovic Courtès <ludo@gnu.org>
  3. This file is part of GNU Guix.
  4. GNU Guix is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or (at
  7. your option) any later version.
  8. GNU Guix is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. */
  14. #include <builtins.hh>
  15. #include <util.hh>
  16. #include <globals.hh>
  17. #include <unistd.h>
  18. namespace nix {
  19. static void builtinDownload(const Derivation &drv,
  20. const std::string &drvPath)
  21. {
  22. /* Invoke 'guix perform-download'. */
  23. Strings args;
  24. args.push_back("perform-download");
  25. args.push_back(drvPath);
  26. /* Close all other file descriptors. */
  27. closeMostFDs(set<int>());
  28. const char *const argv[] = { "download", drvPath.c_str(), NULL };
  29. /* XXX: Hack our way to use the 'download' script from 'LIBEXECDIR/guix'
  30. or just 'LIBEXECDIR', depending on whether we're running uninstalled or
  31. not. */
  32. const string subdir = getenv("GUIX_UNINSTALLED") != NULL
  33. ? "" : "/guix";
  34. const string program = settings.nixLibexecDir + subdir + "/download";
  35. execv(program.c_str(), (char *const *) argv);
  36. throw SysError(format("failed to run download program '%1%'") % program);
  37. }
  38. static const std::map<std::string, derivationBuilder> builtins =
  39. {
  40. { "download", builtinDownload }
  41. };
  42. derivationBuilder lookupBuiltinBuilder(const std::string & name)
  43. {
  44. if (name.substr(0, 8) == "builtin:")
  45. {
  46. auto realName = name.substr(8);
  47. auto builder = builtins.find(realName);
  48. return builder == builtins.end() ? NULL : builder->second;
  49. }
  50. else
  51. return NULL;
  52. }
  53. }