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