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