gnu: linux-libre: Update to 5.1.4.
[guix.git] / nix / libstore / builtins.cc
blobf7c7d4248471f99cc60fe843a49c7abfa4ccee50
1 /* GNU Guix --- Functional package management for GNU
2 Copyright (C) 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
4 This file is part of GNU Guix.
6 GNU Guix is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or (at
9 your option) any later version.
11 GNU Guix is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. */
19 #include <builtins.hh>
20 #include <util.hh>
21 #include <globals.hh>
23 #include <unistd.h>
24 #include <cstdlib>
26 namespace nix {
28 static void builtinDownload(const Derivation &drv,
29 const std::string &drvPath,
30 const std::string &output)
32 /* Invoke 'guix perform-download'. */
33 Strings args;
34 args.push_back("perform-download");
35 args.push_back(drvPath);
37 /* Close all other file descriptors. */
38 closeMostFDs(set<int>());
40 const char *const argv[] =
42 "download", drvPath.c_str(), output.c_str(), NULL
45 /* Tell the script what the store file name is, so that
46 'strip-store-file-name' (used for instance to determine the URL of
47 content-addressed mirrors) works correctly. */
48 setenv("NIX_STORE", settings.nixStore.c_str(), 1);
50 /* Tell it about options such as "print-extended-build-trace". */
51 setenv("_NIX_OPTIONS", settings.pack().c_str(), 1);
53 const string program = settings.nixLibexecDir + "/download";
54 execv(program.c_str(), (char *const *) argv);
56 throw SysError(format("failed to run download program '%1%'") % program);
59 static const std::map<std::string, derivationBuilder> builtins =
61 { "download", builtinDownload }
64 derivationBuilder lookupBuiltinBuilder(const std::string & name)
66 if (name.substr(0, 8) == "builtin:")
68 auto realName = name.substr(8);
69 auto builder = builtins.find(realName);
70 return builder == builtins.end() ? NULL : builder->second;
72 else
73 return NULL;
76 std::list<std::string> builtinBuilderNames()
78 std::list<std::string> result;
79 for(auto&& iter: builtins)
81 result.push_back(iter.first);
83 return result;