Commit | Line | Data |
---|---|---|
033adfe7 | 1 | ;;; GNU Guix --- Functional package management for GNU |
6ce206cb | 2 | ;;; Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org> |
033adfe7 LC |
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 | (define-module (gnu system) | |
20 | #:use-module (guix store) | |
21 | #:use-module (guix monads) | |
02100028 | 22 | #:use-module (guix gexp) |
033adfe7 LC |
23 | #:use-module (guix records) |
24 | #:use-module (guix packages) | |
25 | #:use-module (guix derivations) | |
29fce8b6 | 26 | #:use-module (guix profiles) |
033adfe7 LC |
27 | #:use-module (gnu packages base) |
28 | #:use-module (gnu packages bash) | |
bdb36958 | 29 | #:use-module (gnu packages guile) |
89a0d00a | 30 | #:use-module (gnu packages which) |
9de46ffb | 31 | #:use-module (gnu packages admin) |
8a07c289 | 32 | #:use-module (gnu packages linux) |
a96a82d7 | 33 | #:use-module (gnu packages pciutils) |
033adfe7 | 34 | #:use-module (gnu packages package-management) |
6f436c54 LC |
35 | #:use-module (gnu packages which) |
36 | #:use-module (gnu packages less) | |
37 | #:use-module (gnu packages zile) | |
55e70e65 LC |
38 | #:use-module (gnu packages nano) |
39 | #:use-module (gnu packages lsof) | |
a68c6967 LC |
40 | #:use-module (gnu packages gawk) |
41 | #:use-module (gnu packages compression) | |
f34c56be | 42 | #:use-module (gnu packages firmware) |
a68c6967 | 43 | #:autoload (gnu packages cryptsetup) (cryptsetup) |
db4fdc04 LC |
44 | #:use-module (gnu services) |
45 | #:use-module (gnu services dmd) | |
46 | #:use-module (gnu services base) | |
033adfe7 LC |
47 | #:use-module (gnu system grub) |
48 | #:use-module (gnu system shadow) | |
598e19dc | 49 | #:use-module (gnu system locale) |
033adfe7 | 50 | #:use-module (gnu system linux) |
735c6dd7 | 51 | #:use-module (gnu system linux-initrd) |
c5df1839 | 52 | #:use-module (gnu system file-systems) |
033adfe7 LC |
53 | #:use-module (ice-9 match) |
54 | #:use-module (srfi srfi-1) | |
55 | #:use-module (srfi srfi-26) | |
598e19dc LC |
56 | #:use-module (srfi srfi-34) |
57 | #:use-module (srfi srfi-35) | |
033adfe7 LC |
58 | #:export (operating-system |
59 | operating-system? | |
d5b429ab LC |
60 | |
61 | operating-system-bootloader | |
033adfe7 | 62 | operating-system-services |
217a5b85 | 63 | operating-system-user-services |
033adfe7 | 64 | operating-system-packages |
fd3bfc44 | 65 | operating-system-host-name |
c65e1834 | 66 | operating-system-hosts-file |
fd3bfc44 LC |
67 | operating-system-kernel |
68 | operating-system-initrd | |
69 | operating-system-users | |
70 | operating-system-groups | |
548d4c13 | 71 | operating-system-issue |
fd3bfc44 LC |
72 | operating-system-packages |
73 | operating-system-timezone | |
74 | operating-system-locale | |
598e19dc | 75 | operating-system-locale-definitions |
5dae0186 | 76 | operating-system-mapped-devices |
83bcd0b8 | 77 | operating-system-file-systems |
b25937e3 | 78 | operating-system-activation-script |
033adfe7 | 79 | |
1aa0033b | 80 | operating-system-derivation |
83bcd0b8 | 81 | operating-system-profile |
6f436c54 LC |
82 | operating-system-grub.cfg |
83 | ||
568841d4 | 84 | local-host-aliases |
df5ce088 | 85 | %setuid-programs |
5dae0186 | 86 | %base-packages |
f34c56be | 87 | %base-firmware |
5dae0186 LC |
88 | |
89 | luks-device-mapping)) | |
033adfe7 LC |
90 | |
91 | ;;; Commentary: | |
92 | ;;; | |
93 | ;;; This module supports whole-system configuration. | |
94 | ;;; | |
95 | ;;; Code: | |
96 | ||
97 | ;; System-wide configuration. | |
98 | ;; TODO: Add per-field docstrings/stexi. | |
99 | (define-record-type* <operating-system> operating-system | |
100 | make-operating-system | |
101 | operating-system? | |
102 | (kernel operating-system-kernel ; package | |
103 | (default linux-libre)) | |
d5b429ab LC |
104 | (bootloader operating-system-bootloader) ; <grub-configuration> |
105 | ||
83bcd0b8 | 106 | (initrd operating-system-initrd ; (list fs) -> M derivation |
060238ae | 107 | (default base-initrd)) |
f34c56be LC |
108 | (firmware operating-system-firmware ; list of packages |
109 | (default %base-firmware)) | |
033adfe7 LC |
110 | |
111 | (host-name operating-system-host-name) ; string | |
c65e1834 LC |
112 | (hosts-file operating-system-hosts-file ; M item | #f |
113 | (default #f)) | |
033adfe7 | 114 | |
5dae0186 LC |
115 | (mapped-devices operating-system-mapped-devices ; list of <mapped-device> |
116 | (default '())) | |
8a6d2731 | 117 | (file-systems operating-system-file-systems) ; list of fs |
2a13d05e LC |
118 | (swap-devices operating-system-swap-devices ; list of strings |
119 | (default '())) | |
033adfe7 LC |
120 | |
121 | (users operating-system-users ; list of user accounts | |
122 | (default '())) | |
123 | (groups operating-system-groups ; list of user groups | |
773e956d | 124 | (default %base-groups)) |
033adfe7 | 125 | |
40281c54 LC |
126 | (skeletons operating-system-skeletons ; list of name/monadic value |
127 | (default (default-skeletons))) | |
548d4c13 LC |
128 | (issue operating-system-issue ; string |
129 | (default %default-issue)) | |
40281c54 | 130 | |
033adfe7 | 131 | (packages operating-system-packages ; list of (PACKAGE OUTPUT...) |
6f436c54 | 132 | (default %base-packages)) ; or just PACKAGE |
033adfe7 LC |
133 | |
134 | (timezone operating-system-timezone) ; string | |
8a6d2731 | 135 | (locale operating-system-locale ; string |
598e19dc LC |
136 | (default "en_US.utf8")) |
137 | (locale-definitions operating-system-locale-definitions ; list of <locale-definition> | |
138 | (default %default-locale-definitions)) | |
033adfe7 | 139 | |
217a5b85 | 140 | (services operating-system-user-services ; list of monadic services |
09e028f4 LC |
141 | (default %base-services)) |
142 | ||
143 | (pam-services operating-system-pam-services ; list of PAM services | |
144 | (default (base-pam-services))) | |
145 | (setuid-programs operating-system-setuid-programs | |
69689380 | 146 | (default %setuid-programs)) ; list of string-valued gexps |
033adfe7 | 147 | |
69689380 LC |
148 | (sudoers operating-system-sudoers ; /etc/sudoers contents |
149 | (default %sudoers-specification))) | |
033adfe7 | 150 | |
2717a89a | 151 | \f |
033adfe7 LC |
152 | ;;; |
153 | ;;; Derivation. | |
154 | ;;; | |
155 | ||
23f6056b | 156 | (define* (file-union name files) |
033adfe7 LC |
157 | "Return a derivation that builds a directory containing all of FILES. Each |
158 | item in FILES must be a list where the first element is the file name to use | |
23f6056b LC |
159 | in the new directory, and the second element is a gexp denoting the target |
160 | file." | |
161 | (define builder | |
162 | #~(begin | |
163 | (mkdir #$output) | |
164 | (chdir #$output) | |
165 | #$@(map (match-lambda | |
166 | ((target source) | |
167 | #~(symlink #$source #$target))) | |
168 | files))) | |
033adfe7 | 169 | |
23f6056b | 170 | (gexp->derivation name builder)) |
033adfe7 | 171 | |
f34c56be LC |
172 | (define (directory-union name things) |
173 | "Return a directory that is the union of THINGS." | |
174 | (match things | |
175 | ((one) | |
176 | ;; Only one thing; return it. | |
177 | (with-monad %store-monad (return one))) | |
178 | (_ | |
179 | (gexp->derivation name | |
180 | #~(begin | |
181 | (use-modules (guix build union)) | |
182 | (union-build #$output '#$things)) | |
183 | #:modules '((guix build union)) | |
184 | #:local-build? #t)))) | |
185 | ||
40281c54 LC |
186 | \f |
187 | ;;; | |
188 | ;;; Services. | |
189 | ;;; | |
190 | ||
722554a3 | 191 | (define (open-luks-device source target) |
5dae0186 LC |
192 | "Return a gexp that maps SOURCE to TARGET as a LUKS device, using |
193 | 'cryptsetup'." | |
194 | #~(zero? (system* (string-append #$cryptsetup "/sbin/cryptsetup") | |
195 | "open" "--type" "luks" | |
196 | #$source #$target))) | |
197 | ||
722554a3 LC |
198 | (define (close-luks-device source target) |
199 | "Return a gexp that closes TARGET, a LUKS device." | |
200 | #~(zero? (system* (string-append #$cryptsetup "/sbin/cryptsetup") | |
201 | "close" #$target))) | |
202 | ||
203 | (define luks-device-mapping | |
204 | ;; The type of LUKS mapped devices. | |
205 | (mapped-device-kind | |
206 | (open open-luks-device) | |
207 | (close close-luks-device))) | |
208 | ||
023f391c LC |
209 | (define (other-file-system-services os) |
210 | "Return file system services for the file systems of OS that are not marked | |
211 | as 'needed-for-boot'." | |
212 | (define file-systems | |
4d6b879c | 213 | (remove file-system-needed-for-boot? |
023f391c LC |
214 | (operating-system-file-systems os))) |
215 | ||
5dae0186 LC |
216 | (define (device-mappings fs) |
217 | (filter (lambda (md) | |
218 | (string=? (string-append "/dev/mapper/" | |
219 | (mapped-device-target md)) | |
220 | (file-system-device fs))) | |
221 | (operating-system-mapped-devices os))) | |
222 | ||
223 | (define (requirements fs) | |
224 | (map (lambda (md) | |
225 | (symbol-append 'device-mapping- | |
226 | (string->symbol (mapped-device-target md)))) | |
227 | (device-mappings fs))) | |
228 | ||
023f391c | 229 | (sequence %store-monad |
5dae0186 LC |
230 | (map (lambda (fs) |
231 | (match fs | |
232 | (($ <file-system> device title target type flags opts | |
233 | #f check? create?) | |
234 | (file-system-service device target type | |
235 | #:title title | |
236 | #:requirements (requirements fs) | |
237 | #:check? check? | |
238 | #:create-mount-point? create? | |
239 | #:options opts | |
240 | #:flags flags)))) | |
023f391c LC |
241 | file-systems))) |
242 | ||
de1c158f LC |
243 | (define (mapped-device-user device file-systems) |
244 | "Return a file system among FILE-SYSTEMS that uses DEVICE, or #f." | |
245 | (let ((target (string-append "/dev/mapper/" (mapped-device-target device)))) | |
246 | (find (lambda (fs) | |
247 | (string=? (file-system-device fs) target)) | |
248 | file-systems))) | |
249 | ||
250 | (define (operating-system-user-mapped-devices os) | |
251 | "Return the subset of mapped devices that can be installed in | |
252 | user-land--i.e., those not needed during boot." | |
253 | (let ((devices (operating-system-mapped-devices os)) | |
254 | (file-systems (operating-system-file-systems os))) | |
255 | (filter (lambda (md) | |
256 | (let ((user (mapped-device-user md file-systems))) | |
257 | (or (not user) | |
258 | (not (file-system-needed-for-boot? user))))) | |
259 | devices))) | |
260 | ||
261 | (define (operating-system-boot-mapped-devices os) | |
262 | "Return the subset of mapped devices that must be installed during boot, | |
263 | from the initrd." | |
264 | (let ((devices (operating-system-mapped-devices os)) | |
265 | (file-systems (operating-system-file-systems os))) | |
266 | (filter (lambda (md) | |
267 | (let ((user (mapped-device-user md file-systems))) | |
268 | (and user (file-system-needed-for-boot? user)))) | |
269 | devices))) | |
270 | ||
5dae0186 LC |
271 | (define (device-mapping-services os) |
272 | "Return the list of device-mapping services for OS as a monadic list." | |
273 | (sequence %store-monad | |
274 | (map (lambda (md) | |
722554a3 LC |
275 | (let* ((source (mapped-device-source md)) |
276 | (target (mapped-device-target md)) | |
277 | (type (mapped-device-type md)) | |
278 | (open (mapped-device-kind-open type)) | |
279 | (close (mapped-device-kind-close type))) | |
5dae0186 | 280 | (device-mapping-service target |
722554a3 LC |
281 | (open source target) |
282 | (close source target)))) | |
de1c158f | 283 | (operating-system-user-mapped-devices os)))) |
5dae0186 | 284 | |
2a13d05e LC |
285 | (define (swap-services os) |
286 | "Return the list of swap services for OS as a monadic list." | |
287 | (sequence %store-monad | |
288 | (map swap-service (operating-system-swap-devices os)))) | |
289 | ||
217a5b85 LC |
290 | (define (essential-services os) |
291 | "Return the list of essential services for OS. These are special services | |
292 | that implement part of what's declared in OS are responsible for low-level | |
293 | bookkeeping." | |
d6e2a622 LC |
294 | (define known-fs |
295 | (map file-system-mount-point (operating-system-file-systems os))) | |
296 | ||
5dae0186 LC |
297 | (mlet* %store-monad ((mappings (device-mapping-services os)) |
298 | (root-fs (root-file-system-service)) | |
023f391c | 299 | (other-fs (other-file-system-services os)) |
d6e2a622 | 300 | (unmount (user-unmount-service known-fs)) |
2a13d05e | 301 | (swaps (swap-services os)) |
023f391c LC |
302 | (procs (user-processes-service |
303 | (map (compose first service-provision) | |
304 | other-fs))) | |
305 | (host-name (host-name-service | |
306 | (operating-system-host-name os)))) | |
d6e2a622 | 307 | (return (cons* host-name procs root-fs unmount |
2a13d05e | 308 | (append other-fs mappings swaps))))) |
217a5b85 LC |
309 | |
310 | (define (operating-system-services os) | |
311 | "Return all the services of OS, including \"internal\" services that do not | |
312 | explicitly appear in OS." | |
313 | (mlet %store-monad | |
314 | ((user (sequence %store-monad (operating-system-user-services os))) | |
315 | (essential (essential-services os))) | |
316 | (return (append essential user)))) | |
317 | ||
40281c54 LC |
318 | \f |
319 | ;;; | |
320 | ;;; /etc. | |
321 | ;;; | |
322 | ||
f34c56be LC |
323 | (define %base-firmware |
324 | ;; Firmware usable by default. | |
325 | (list ath9k-htc-firmware)) | |
326 | ||
6f436c54 LC |
327 | (define %base-packages |
328 | ;; Default set of packages globally visible. It should include anything | |
329 | ;; required for basic administrator tasks. | |
55e70e65 | 330 | (cons* procps psmisc which less zile nano |
bdb36958 | 331 | (@ (gnu packages admin) dmd) guix |
55e70e65 | 332 | lsof ;for Guix's 'list-runtime-roots' |
a96a82d7 | 333 | pciutils usbutils |
a68c6967 | 334 | util-linux inetutils isc-dhcp wireless-tools |
9b762b8d | 335 | net-tools ; XXX: remove when Inetutils suffices |
03e9998f LC |
336 | |
337 | ;; Get 'insmod' & co. from kmod, not module-init-tools, since udev | |
338 | ;; already depends on it anyway. | |
8a7330fd | 339 | kmod eudev |
03e9998f | 340 | |
b63dbd44 | 341 | e2fsprogs kbd |
9b762b8d LC |
342 | |
343 | ;; The packages below are also in %FINAL-INPUTS, so take them from | |
344 | ;; there to avoid duplication. | |
345 | (map canonical-package | |
a68c6967 | 346 | (list guile-2.0 bash coreutils findutils grep sed |
4b164c45 | 347 | diffutils patch gawk tar gzip bzip2 xz lzip)))) |
6f436c54 | 348 | |
548d4c13 LC |
349 | (define %default-issue |
350 | ;; Default contents for /etc/issue. | |
351 | " | |
352 | This is the GNU system. Welcome.\n") | |
353 | ||
568841d4 LC |
354 | (define (local-host-aliases host-name) |
355 | "Return aliases for HOST-NAME, to be used in /etc/hosts." | |
356 | (string-append "127.0.0.1 localhost " host-name "\n" | |
357 | "::1 localhost " host-name "\n")) | |
358 | ||
c65e1834 LC |
359 | (define (default-/etc/hosts host-name) |
360 | "Return the default /etc/hosts file." | |
568841d4 | 361 | (text-file "hosts" (local-host-aliases host-name))) |
c65e1834 | 362 | |
033adfe7 | 363 | (define* (etc-directory #:key |
3141a8bd | 364 | (locale "C") (timezone "Europe/Paris") |
548d4c13 | 365 | (issue "Hello!\n") |
40281c54 | 366 | (skeletons '()) |
033adfe7 | 367 | (pam-services '()) |
b4140694 | 368 | (profile "/run/current-system/profile") |
c65e1834 | 369 | hosts-file |
69689380 | 370 | (sudoers "")) |
033adfe7 LC |
371 | "Return a derivation that builds the static part of the /etc directory." |
372 | (mlet* %store-monad | |
ab6a279a | 373 | ((pam.d (pam-services->directory pam-services)) |
69689380 | 374 | (sudoers (text-file "sudoers" sudoers)) |
033adfe7 | 375 | (login.defs (text-file "login.defs" "# Empty for now.\n")) |
9038298c LC |
376 | (shells (text-file "shells" ; used by xterm and others |
377 | "\ | |
378 | /bin/sh | |
b4140694 LC |
379 | /run/current-system/profile/bin/sh |
380 | /run/current-system/profile/bin/bash\n")) | |
548d4c13 | 381 | (issue (text-file "issue" issue)) |
033adfe7 | 382 | |
07b08343 LC |
383 | ;; For now, generate a basic config so that /etc/hosts is honored. |
384 | (nsswitch (text-file "nsswitch.conf" | |
385 | "hosts: files dns\n")) | |
386 | ||
033adfe7 | 387 | ;; TODO: Generate bashrc from packages' search-paths. |
7aec3683 | 388 | (bashrc (text-file* "bashrc" " |
c851400b | 389 | export PS1='\\u@\\h \\w\\$ ' |
3141a8bd LC |
390 | |
391 | export LC_ALL=\"" locale "\" | |
392 | export TZ=\"" timezone "\" | |
7aec3683 | 393 | export TZDIR=\"" tzdata "/share/zoneinfo\" |
3141a8bd | 394 | |
d3bbe992 | 395 | # Tell 'modprobe' & co. where to look for modules. |
62f0a479 | 396 | export LINUX_MODULE_DIRECTORY=/run/booted-system/kernel/lib/modules |
d3bbe992 | 397 | |
585c6519 LC |
398 | export PATH=$HOME/.guix-profile/bin:/run/current-system/profile/bin |
399 | export PATH=/run/setuid-programs:/run/current-system/profile/sbin:$PATH | |
033adfe7 LC |
400 | export CPATH=$HOME/.guix-profile/include:" profile "/include |
401 | export LIBRARY_PATH=$HOME/.guix-profile/lib:" profile "/lib | |
95f92d4e | 402 | export INFOPATH=$HOME/.guix-profile/share/info:/run/current-system/profile/share/info |
033adfe7 LC |
403 | alias ls='ls -p --color' |
404 | alias ll='ls -l' | |
40281c54 LC |
405 | ")) |
406 | (skel (skeleton-directory skeletons))) | |
23f6056b LC |
407 | (file-union "etc" |
408 | `(("services" ,#~(string-append #$net-base "/etc/services")) | |
409 | ("protocols" ,#~(string-append #$net-base "/etc/protocols")) | |
410 | ("rpc" ,#~(string-append #$net-base "/etc/rpc")) | |
411 | ("pam.d" ,#~#$pam.d) | |
412 | ("login.defs" ,#~#$login.defs) | |
413 | ("issue" ,#~#$issue) | |
07b08343 | 414 | ("nsswitch.conf" ,#~#$nsswitch) |
40281c54 | 415 | ("skel" ,#~#$skel) |
23f6056b LC |
416 | ("shells" ,#~#$shells) |
417 | ("profile" ,#~#$bashrc) | |
c65e1834 | 418 | ("hosts" ,#~#$hosts-file) |
23f6056b LC |
419 | ("localtime" ,#~(string-append #$tzdata "/share/zoneinfo/" |
420 | #$timezone)) | |
69689380 | 421 | ("sudoers" ,#~#$sudoers))))) |
033adfe7 | 422 | |
1aa0033b | 423 | (define (operating-system-profile os) |
29fce8b6 LC |
424 | "Return a derivation that builds the system profile of OS." |
425 | (profile-derivation (manifest (map package->manifest-entry | |
426 | (operating-system-packages os))))) | |
f6a9d048 | 427 | |
ab6a279a LC |
428 | (define %root-account |
429 | ;; Default root account. | |
430 | (user-account | |
431 | (name "root") | |
432 | (password "") | |
433 | (uid 0) (group "root") | |
434 | (comment "System administrator") | |
435 | (home-directory "/root"))) | |
436 | ||
0b6f49ef LC |
437 | (define (operating-system-accounts os) |
438 | "Return the user accounts for OS, including an obligatory 'root' account." | |
ab6a279a LC |
439 | (define users |
440 | ;; Make sure there's a root account. | |
441 | (if (find (lambda (user) | |
442 | (and=> (user-account-uid user) zero?)) | |
443 | (operating-system-users os)) | |
444 | (operating-system-users os) | |
445 | (cons %root-account (operating-system-users os)))) | |
446 | ||
217a5b85 | 447 | (mlet %store-monad ((services (operating-system-services os))) |
ab6a279a LC |
448 | (return (append users |
449 | (append-map service-user-accounts services))))) | |
0b6f49ef LC |
450 | |
451 | (define (operating-system-etc-directory os) | |
452 | "Return that static part of the /etc directory of OS." | |
033adfe7 | 453 | (mlet* %store-monad |
217a5b85 | 454 | ((services (operating-system-services os)) |
033adfe7 LC |
455 | (pam-services -> |
456 | ;; Services known to PAM. | |
457 | (delete-duplicates | |
09e028f4 LC |
458 | (append (operating-system-pam-services os) |
459 | (append-map service-pam-services services)))) | |
40281c54 | 460 | (profile-drv (operating-system-profile os)) |
c65e1834 LC |
461 | (skeletons (operating-system-skeletons os)) |
462 | (/etc/hosts (or (operating-system-hosts-file os) | |
463 | (default-/etc/hosts (operating-system-host-name os))))) | |
62f0a479 | 464 | (etc-directory #:pam-services pam-services |
40281c54 | 465 | #:skeletons skeletons |
548d4c13 | 466 | #:issue (operating-system-issue os) |
0b6f49ef LC |
467 | #:locale (operating-system-locale os) |
468 | #:timezone (operating-system-timezone os) | |
c65e1834 | 469 | #:hosts-file /etc/hosts |
69689380 | 470 | #:sudoers (operating-system-sudoers os) |
0b6f49ef | 471 | #:profile profile-drv))) |
033adfe7 | 472 | |
09e028f4 LC |
473 | (define %setuid-programs |
474 | ;; Default set of setuid-root programs. | |
475 | (let ((shadow (@ (gnu packages admin) shadow))) | |
476 | (list #~(string-append #$shadow "/bin/passwd") | |
477 | #~(string-append #$shadow "/bin/su") | |
69689380 | 478 | #~(string-append #$inetutils "/bin/ping") |
8a07c289 LC |
479 | #~(string-append #$sudo "/bin/sudo") |
480 | #~(string-append #$fuse "/bin/fusermount")))) | |
69689380 LC |
481 | |
482 | (define %sudoers-specification | |
483 | ;; Default /etc/sudoers contents: 'root' and all members of the 'wheel' | |
484 | ;; group can do anything. See | |
485 | ;; <http://www.sudo.ws/sudo/man/1.8.10/sudoers.man.html>. | |
486 | ;; TODO: Add a declarative API. | |
487 | "root ALL=(ALL) ALL | |
488 | %wheel ALL=(ALL) ALL\n") | |
09e028f4 | 489 | |
ab6a279a LC |
490 | (define (user-group->gexp group) |
491 | "Turn GROUP, a <user-group> object, into a list-valued gexp suitable for | |
492 | 'active-groups'." | |
493 | #~(list #$(user-group-name group) | |
494 | #$(user-group-password group) | |
c8fa3426 LC |
495 | #$(user-group-id group) |
496 | #$(user-group-system? group))) | |
ab6a279a LC |
497 | |
498 | (define (user-account->gexp account) | |
499 | "Turn ACCOUNT, a <user-account> object, into a list-valued gexp suitable for | |
500 | 'activate-users'." | |
501 | #~`(#$(user-account-name account) | |
502 | #$(user-account-uid account) | |
503 | #$(user-account-group account) | |
504 | #$(user-account-supplementary-groups account) | |
505 | #$(user-account-comment account) | |
506 | #$(user-account-home-directory account) | |
507 | ,#$(user-account-shell account) ; this one is a gexp | |
459dd9ea LC |
508 | #$(user-account-password account) |
509 | #$(user-account-system? account))) | |
ab6a279a | 510 | |
d460204f LC |
511 | (define (modprobe-wrapper) |
512 | "Return a wrapper for the 'modprobe' command that knows where modules live. | |
513 | ||
514 | This wrapper is typically invoked by the Linux kernel ('call_modprobe', in | |
515 | kernel/kmod.c), a situation where the 'LINUX_MODULE_DIRECTORY' environment | |
516 | variable is not set---hence the need for this wrapper." | |
517 | (let ((modprobe "/run/current-system/profile/bin/modprobe")) | |
518 | (gexp->script "modprobe" | |
519 | #~(begin | |
520 | (setenv "LINUX_MODULE_DIRECTORY" | |
521 | "/run/booted-system/kernel/lib/modules") | |
522 | (apply execl #$modprobe | |
523 | (cons #$modprobe (cdr (command-line)))))))) | |
524 | ||
484a2b3a LC |
525 | (define (operating-system-activation-script os) |
526 | "Return the activation script for OS---i.e., the code that \"activates\" the | |
527 | stateful part of OS, including user accounts and groups, special directories, | |
528 | etc." | |
09e028f4 | 529 | (define %modules |
548f7a8f | 530 | '((gnu build activation) |
8a9e21d1 | 531 | (gnu build linux-boot) |
e2f4b305 | 532 | (gnu build file-systems) |
548f7a8f | 533 | (guix build utils))) |
09e028f4 | 534 | |
55ccc388 LC |
535 | (define (service-activations services) |
536 | ;; Return the activation scripts for SERVICES. | |
537 | (let ((gexps (filter-map service-activate services))) | |
538 | (sequence %store-monad (map (cut gexp->file "activate-service.scm" <>) | |
539 | gexps)))) | |
540 | ||
ab6a279a | 541 | (mlet* %store-monad ((services (operating-system-services os)) |
55ccc388 | 542 | (actions (service-activations services)) |
ab6a279a LC |
543 | (etc (operating-system-etc-directory os)) |
544 | (modules (imported-modules %modules)) | |
545 | (compiled (compiled-modules %modules)) | |
d460204f | 546 | (modprobe (modprobe-wrapper)) |
f34c56be LC |
547 | (firmware (directory-union |
548 | "firmware" (operating-system-firmware os))) | |
ab6a279a | 549 | (accounts (operating-system-accounts os))) |
09e028f4 LC |
550 | (define setuid-progs |
551 | (operating-system-setuid-programs os)) | |
552 | ||
ab6a279a LC |
553 | (define user-specs |
554 | (map user-account->gexp accounts)) | |
555 | ||
556 | (define groups | |
557 | (append (operating-system-groups os) | |
558 | (append-map service-user-groups services))) | |
559 | ||
560 | (define group-specs | |
561 | (map user-group->gexp groups)) | |
562 | ||
4654439b | 563 | (gexp->file "activate" |
4dfe6c58 LC |
564 | #~(begin |
565 | (eval-when (expand load eval) | |
566 | ;; Make sure 'use-modules' below succeeds. | |
567 | (set! %load-path (cons #$modules %load-path)) | |
568 | (set! %load-compiled-path | |
569 | (cons #$compiled %load-compiled-path))) | |
570 | ||
548f7a8f | 571 | (use-modules (gnu build activation)) |
4dfe6c58 | 572 | |
ee248b6a LC |
573 | ;; Make sure /bin/sh is valid and current. |
574 | (activate-/bin/sh | |
575 | (string-append #$(canonical-package bash) | |
576 | "/bin/sh")) | |
577 | ||
4dfe6c58 LC |
578 | ;; Populate /etc. |
579 | (activate-etc #$etc) | |
580 | ||
ab6a279a LC |
581 | ;; Add users and user groups. |
582 | (setenv "PATH" | |
583 | (string-append #$(@ (gnu packages admin) shadow) | |
584 | "/sbin")) | |
585 | (activate-users+groups (list #$@user-specs) | |
586 | (list #$@group-specs)) | |
587 | ||
09e028f4 LC |
588 | ;; Activate setuid programs. |
589 | (activate-setuid-programs (list #$@setuid-progs)) | |
590 | ||
d460204f LC |
591 | ;; Tell the kernel to use our 'modprobe' command. |
592 | (activate-modprobe #$modprobe) | |
593 | ||
f34c56be LC |
594 | ;; Tell the kernel where firmware is. |
595 | (activate-firmware | |
596 | (string-append #$firmware "/lib/firmware")) | |
597 | ||
55ccc388 LC |
598 | ;; Run the services' activation snippets. |
599 | ;; TODO: Use 'load-compiled'. | |
600 | (for-each primitive-load '#$actions) | |
601 | ||
b4140694 | 602 | ;; Set up /run/current-system. |
484a2b3a LC |
603 | (activate-current-system))))) |
604 | ||
605 | (define (operating-system-boot-script os) | |
606 | "Return the boot script for OS---i.e., the code started by the initrd once | |
607 | we're running in the final root." | |
608 | (mlet* %store-monad ((services (operating-system-services os)) | |
609 | (activate (operating-system-activation-script os)) | |
610 | (dmd-conf (dmd-configuration-file services))) | |
611 | (gexp->file "boot" | |
612 | #~(begin | |
613 | ;; Activate the system. | |
614 | ;; TODO: Use 'load-compiled'. | |
615 | (primitive-load #$activate) | |
616 | ||
617 | ;; Keep track of the booted system. | |
618 | (false-if-exception (delete-file "/run/booted-system")) | |
619 | (symlink (readlink "/run/current-system") | |
620 | "/run/booted-system") | |
b4140694 | 621 | |
26a728eb LC |
622 | ;; Close any remaining open file descriptors to be on the |
623 | ;; safe side. This must be the very last thing we do, | |
624 | ;; because Guile has internal FDs such as 'sleep_pipe' | |
625 | ;; that need to be alive. | |
626 | (let loop ((fd 3)) | |
627 | (when (< fd 1024) | |
628 | (false-if-exception (close-fdes fd)) | |
629 | (loop (+ 1 fd)))) | |
630 | ||
4dfe6c58 LC |
631 | ;; Start dmd. |
632 | (execl (string-append #$dmd "/bin/dmd") | |
633 | "dmd" "--config" #$dmd-conf))))) | |
2106d3fc | 634 | |
83bcd0b8 LC |
635 | (define (operating-system-root-file-system os) |
636 | "Return the root file system of OS." | |
637 | (find (match-lambda | |
d4c87617 | 638 | (($ <file-system> _ _ "/") #t) |
83bcd0b8 LC |
639 | (_ #f)) |
640 | (operating-system-file-systems os))) | |
641 | ||
b4140694 LC |
642 | (define (operating-system-initrd-file os) |
643 | "Return a gexp denoting the initrd file of OS." | |
83bcd0b8 | 644 | (define boot-file-systems |
4d6b879c | 645 | (filter file-system-needed-for-boot? |
83bcd0b8 LC |
646 | (operating-system-file-systems os))) |
647 | ||
de1c158f LC |
648 | (define mapped-devices |
649 | (operating-system-boot-mapped-devices os)) | |
650 | ||
651 | (define make-initrd | |
652 | (operating-system-initrd os)) | |
653 | ||
654 | (mlet %store-monad ((initrd (make-initrd boot-file-systems | |
655 | #:mapped-devices mapped-devices))) | |
b4140694 LC |
656 | (return #~(string-append #$initrd "/initrd")))) |
657 | ||
598e19dc LC |
658 | (define (operating-system-locale-directory os) |
659 | "Return the directory containing the locales compiled for the definitions | |
660 | listed in OS. The C library expects to find it under | |
661 | /run/current-system/locale." | |
662 | ;; While we're at it, check whether the locale of OS is defined. | |
663 | (unless (member (operating-system-locale os) | |
664 | (map locale-definition-name | |
665 | (operating-system-locale-definitions os))) | |
666 | (raise (condition | |
667 | (&message (message "system locale lacks a definition"))))) | |
668 | ||
669 | (locale-directory (operating-system-locale-definitions os))) | |
670 | ||
2d23e6f0 LC |
671 | (define (kernel->grub-label kernel) |
672 | "Return a label for the GRUB menu entry that boots KERNEL." | |
42de9608 | 673 | (string-append "GNU with " |
2d23e6f0 LC |
674 | (string-titlecase (package-name kernel)) " " |
675 | (package-version kernel) | |
42de9608 | 676 | " (alpha)")) |
2d23e6f0 | 677 | |
fe6e3fe2 LC |
678 | (define* (operating-system-grub.cfg os #:optional (old-entries '())) |
679 | "Return the GRUB configuration file for OS. Use OLD-ENTRIES to populate the | |
680 | \"old entries\" menu." | |
0b6f49ef | 681 | (mlet* %store-monad |
b4140694 | 682 | ((system (operating-system-derivation os)) |
83bcd0b8 | 683 | (root-fs -> (operating-system-root-file-system os)) |
b4140694 | 684 | (kernel -> (operating-system-kernel os)) |
033adfe7 | 685 | (entries -> (list (menu-entry |
2d23e6f0 | 686 | (label (kernel->grub-label kernel)) |
033adfe7 | 687 | (linux kernel) |
f6a7b21d | 688 | (linux-arguments |
83bcd0b8 LC |
689 | (list (string-append "--root=" |
690 | (file-system-device root-fs)) | |
b4140694 LC |
691 | #~(string-append "--system=" #$system) |
692 | #~(string-append "--load=" #$system | |
693 | "/boot"))) | |
694 | (initrd #~(string-append #$system "/initrd")))))) | |
fe6e3fe2 LC |
695 | (grub-configuration-file (operating-system-bootloader os) entries |
696 | #:old-entries old-entries))) | |
b4140694 | 697 | |
64e40dbb LC |
698 | (define (operating-system-parameters-file os) |
699 | "Return a file that describes the boot parameters of OS. The primary use of | |
700 | this file is the reconstruction of GRUB menu entries for old configurations." | |
701 | (mlet %store-monad ((initrd (operating-system-initrd-file os)) | |
702 | (root -> (operating-system-root-file-system os)) | |
703 | (label -> (kernel->grub-label | |
704 | (operating-system-kernel os)))) | |
705 | (gexp->file "parameters" | |
706 | #~(boot-parameters (version 0) | |
707 | (label #$label) | |
708 | (root-device #$(file-system-device root)) | |
709 | (kernel #$(operating-system-kernel os)) | |
710 | (initrd #$initrd))))) | |
711 | ||
b4140694 LC |
712 | (define (operating-system-derivation os) |
713 | "Return a derivation that builds OS." | |
714 | (mlet* %store-monad | |
715 | ((profile (operating-system-profile os)) | |
716 | (etc (operating-system-etc-directory os)) | |
717 | (boot (operating-system-boot-script os)) | |
718 | (kernel -> (operating-system-kernel os)) | |
64e40dbb | 719 | (initrd (operating-system-initrd-file os)) |
598e19dc | 720 | (locale (operating-system-locale-directory os)) |
64e40dbb | 721 | (params (operating-system-parameters-file os))) |
23f6056b | 722 | (file-union "system" |
f6a7b21d | 723 | `(("boot" ,#~#$boot) |
23f6056b | 724 | ("kernel" ,#~#$kernel) |
64e40dbb | 725 | ("parameters" ,#~#$params) |
b4140694 | 726 | ("initrd" ,initrd) |
23f6056b | 727 | ("profile" ,#~#$profile) |
598e19dc | 728 | ("locale" ,#~#$locale) ;used by libc |
23f6056b | 729 | ("etc" ,#~#$etc))))) |
033adfe7 LC |
730 | |
731 | ;;; system.scm ends here |