Mirror of GNU Guix
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.

163 lines
4.6 KiB

  1. /* Guix --- Nix package management from Guile. -*- coding: utf-8 -*-
  2. Copyright (C) 2012 Ludovic Courtès <ludo@gnu.org>
  3. This file is part of Guix.
  4. 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. 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 Guix. If not, see <http://www.gnu.org/licenses/>. */
  14. #include <config.h>
  15. #include <types.hh>
  16. #include "shared.hh"
  17. #include <globals.hh>
  18. #include <stdlib.h>
  19. #include <argp.h>
  20. /* Variables used by `nix-daemon.cc'. */
  21. volatile ::sig_atomic_t blockInt;
  22. char **argvSaved;
  23. using namespace nix;
  24. /* Entry point in `nix-daemon.cc'. */
  25. extern void run (Strings args);
  26. /* Command-line options. */
  27. const char *argp_program_version =
  28. "guix-daemon (" PACKAGE_NAME ") " PACKAGE_VERSION;
  29. const char *argp_program_bug_address = PACKAGE_BUGREPORT;
  30. static char doc[] =
  31. "guix-daemon -- perform derivation builds and store accesses\
  32. \v\
  33. This program is a daemon meant to run in the background. It serves \
  34. requests sent over a Unix-domain socket. It accesses the store, and \
  35. builds derivations on behalf of its clients.";
  36. #define GUIX_OPT_SYSTEM 1
  37. #define GUIX_OPT_DISABLE_CHROOT 2
  38. #define GUIX_OPT_BUILD_USERS_GROUP 3
  39. #define GUIX_OPT_CACHE_FAILURES 4
  40. #define GUIX_OPT_LOSE_LOGS 5
  41. #define GUIX_OPT_DISABLE_LOG_COMPRESSION 6
  42. #define GUIX_OPT_DISABLE_STORE_OPTIMIZATION 7
  43. #define GUIX_OPT_IMPERSONATE_LINUX_26 8
  44. static const struct argp_option options[] =
  45. {
  46. { "system", GUIX_OPT_SYSTEM, "SYSTEM", 0,
  47. "Assume SYSTEM as the current system type" },
  48. { "build-cores", 'C', "N", 0,
  49. "Use N CPU cores to build each derivation; 0 means as many as available" },
  50. { "max-jobs", 'M', "N", 0,
  51. "Allow at most N build jobs" },
  52. { "disable-chroot", GUIX_OPT_DISABLE_CHROOT, 0, 0,
  53. "Disable chroot builds"
  54. #ifndef HAVE_CHROOT
  55. " (chroots are not supported in this configuration, so "
  56. "this option has no effect)"
  57. #endif
  58. },
  59. { "build-users-group", GUIX_OPT_BUILD_USERS_GROUP, "GROUP", 0,
  60. "Perform builds as a user of GROUP" },
  61. { "cache-failures", GUIX_OPT_CACHE_FAILURES, 0, 0,
  62. "Cache build failures" },
  63. { "lose-logs", GUIX_OPT_LOSE_LOGS, 0, 0,
  64. "Do not keep build logs" },
  65. { "disable-log-compression", GUIX_OPT_DISABLE_LOG_COMPRESSION, 0, 0,
  66. "Disable compression of the build logs" },
  67. { "disable-store-optimization", GUIX_OPT_DISABLE_STORE_OPTIMIZATION, 0, 0,
  68. "Disable automatic file \"deduplication\" in the store" },
  69. { "impersonate-linux-2.6", GUIX_OPT_IMPERSONATE_LINUX_26, 0, 0,
  70. "Impersonate Linux 2.6"
  71. #ifndef HAVE_SYS_PERSONALITY_H
  72. " (this option has no effect in this configuration)"
  73. #endif
  74. },
  75. { 0, 0, 0, 0, 0 }
  76. };
  77. /* Parse a single option. */
  78. static error_t
  79. parse_opt (int key, char *arg, struct argp_state *state)
  80. {
  81. switch (key)
  82. {
  83. case GUIX_OPT_DISABLE_CHROOT:
  84. settings.useChroot = false;
  85. break;
  86. case GUIX_OPT_DISABLE_LOG_COMPRESSION:
  87. settings.compressLog = false;
  88. break;
  89. case GUIX_OPT_BUILD_USERS_GROUP:
  90. settings.buildUsersGroup = arg;
  91. break;
  92. case GUIX_OPT_DISABLE_STORE_OPTIMIZATION:
  93. settings.autoOptimiseStore = false;
  94. break;
  95. case GUIX_OPT_CACHE_FAILURES:
  96. settings.cacheFailure = true;
  97. break;
  98. case GUIX_OPT_IMPERSONATE_LINUX_26:
  99. settings.impersonateLinux26 = true;
  100. break;
  101. case GUIX_OPT_LOSE_LOGS:
  102. settings.keepLog = false;
  103. break;
  104. case 'C':
  105. settings.buildCores = atoi (arg);
  106. break;
  107. case 'M':
  108. settings.maxBuildJobs = atoi (arg);
  109. break;
  110. case GUIX_OPT_SYSTEM:
  111. settings.thisSystem = arg;
  112. break;
  113. default:
  114. return ARGP_ERR_UNKNOWN;
  115. }
  116. return 0;
  117. }
  118. /* Argument parsing. */
  119. static struct argp argp = { options, parse_opt, 0, doc };
  120. int
  121. main (int argc, char *argv[])
  122. {
  123. Strings nothing;
  124. #ifdef HAVE_CHROOT
  125. settings.useChroot = true;
  126. #else
  127. settings.useChroot = false;
  128. #endif
  129. settings.processEnvironment ();
  130. /* FIXME: Disable substitutes until we have something that works. */
  131. settings.useSubstitutes = false;
  132. settings.substituters.clear ();
  133. argp_parse (&argp, argc, argv, 0, 0, 0);
  134. argvSaved = argv;
  135. run (nothing);
  136. }