| 1 | |
| 2 | Copyright (C) 2016-2019, 2023 Ludovic Courtès <[email protected]>
|
| 3 |
|
| 4 | This file is part of GNU Guix.
|
| 5 |
|
| 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.
|
| 10 |
|
| 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.
|
| 15 |
|
| 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/>.
|
| 18 |
|
| 19 | #include <builtins.hh>
|
| 20 | #include <util.hh>
|
| 21 | #include <globals.hh>
|
| 22 |
|
| 23 | #include <unistd.h>
|
| 24 | #include <cstdlib>
|
| 25 | #include <format>
|
| 26 |
|
| 27 | namespace nix {
|
| 28 |
|
| 29 | static void builtinDownload(const Derivation &drv,
|
| 30 | const std::string &drvPath,
|
| 31 | const std::string &output)
|
| 32 | {
|
| 33 |
|
| 34 | Strings args;
|
| 35 | args.push_back("perform-download");
|
| 36 | args.push_back(drvPath);
|
| 37 |
|
| 38 |
|
| 39 | closeMostFDs(set<int>());
|
| 40 |
|
| 41 | const char *const argv[] =
|
| 42 | {
|
| 43 | "guix", "perform-download", drvPath.c_str(), output.c_str(), NULL
|
| 44 | };
|
| 45 |
|
| 46 | |
| 47 | 'strip-store-file-name' (used for instance to determine the URL of
|
| 48 | content-addressed mirrors) works correctly.
|
| 49 | setenv("NIX_STORE", settings.nixStore.c_str(), 1);
|
| 50 |
|
| 51 |
|
| 52 | setenv("_NIX_OPTIONS", settings.pack().c_str(), 1);
|
| 53 |
|
| 54 | const string program = settings.guixProgram;
|
| 55 | execv(program.c_str(), (char *const *) argv);
|
| 56 |
|
| 57 | throw SysError(std::format("failed to run download program '{}'", program));
|
| 58 | }
|
| 59 |
|
| 60 | static const std::map<std::string, derivationBuilder> builtins =
|
| 61 | {
|
| 62 | { "download", builtinDownload },
|
| 63 | { "git-download", builtinDownload }
|
| 64 | };
|
| 65 |
|
| 66 | derivationBuilder lookupBuiltinBuilder(const std::string & name)
|
| 67 | {
|
| 68 | if (name.starts_with("builtin:"))
|
| 69 | {
|
| 70 | auto realName = name.substr(8);
|
| 71 | auto builder = builtins.find(realName);
|
| 72 | return builder == builtins.end() ? NULL : builder->second;
|
| 73 | }
|
| 74 | else
|
| 75 | return NULL;
|
| 76 | }
|
| 77 |
|
| 78 | std::list<std::string> builtinBuilderNames()
|
| 79 | {
|
| 80 | std::list<std::string> result;
|
| 81 | for(auto&& iter: builtins)
|
| 82 | {
|
| 83 | result.push_back(iter.first);
|
| 84 | }
|
| 85 | return result;
|
| 86 | }
|
| 87 |
|
| 88 | }
|