Commit | Line | Data |
---|---|---|
47b9614b OP |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2019 Oleg Pykhalov <go.wigust@gmail.com> | |
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 services nix) | |
20 | #:use-module (gnu packages admin) | |
21 | #:use-module (gnu packages package-management) | |
22 | #:use-module (gnu services base) | |
23 | #:use-module (gnu services configuration) | |
24 | #:use-module (gnu services shepherd) | |
25 | #:use-module (gnu services web) | |
26 | #:use-module (gnu services) | |
27 | #:use-module (gnu system shadow) | |
28 | #:use-module (guix gexp) | |
29 | #:use-module (guix packages) | |
30 | #:use-module (guix records) | |
31 | #:use-module (guix store) | |
32 | #:use-module (srfi srfi-1) | |
33 | #:use-module (srfi srfi-26) | |
34 | #:export (nix-service-type)) | |
35 | ||
36 | ;;; Commentary: | |
37 | ;;; | |
38 | ;;; This module provides a service definition for the Nix daemon. | |
39 | ;;; | |
40 | ;;; Code: | |
41 | ||
42 | \f | |
43 | ;;; | |
44 | ;;; Accounts | |
45 | ;;; | |
46 | ||
47 | ;; Copied from gnu/services/base.scm | |
48 | (define* (nix-build-accounts count #:key | |
49 | (group "nixbld") | |
50 | (shadow shadow)) | |
51 | "Return a list of COUNT user accounts for Nix build users with the given | |
52 | GID." | |
53 | (unfold (cut > <> count) | |
54 | (lambda (n) | |
55 | (user-account | |
56 | (name (format #f "nixbld~2,'0d" n)) | |
57 | (system? #t) | |
58 | (group group) | |
59 | (supplementary-groups (list group "kvm")) | |
60 | (comment (format #f "Nix Build User ~2d" n)) | |
61 | (home-directory "/var/empty") | |
62 | (shell (file-append shadow "/sbin/nologin")))) | |
63 | 1+ | |
64 | 1)) | |
65 | (define (nix-accounts _) | |
66 | "Return the user accounts and user groups." | |
67 | (cons (user-group | |
68 | (name "nixbld") | |
69 | (system? #t) | |
70 | ||
71 | ;; Use a fixed GID so that we can create the store with the right | |
72 | ;; owner. | |
73 | (id 40000)) | |
74 | (nix-build-accounts 10 #:group "nixbld"))) | |
75 | ||
76 | (define (nix-activation _) | |
77 | "Return the activation gexp." | |
79d19d7d | 78 | (with-imported-modules '((guix build utils)) |
47b9614b | 79 | #~(begin |
2be6b5e2 TGR |
80 | (use-modules (guix build utils) |
81 | (srfi srfi-26)) | |
47b9614b OP |
82 | (for-each (cut mkdir-p <>) '("/nix/store" "/nix/var/log" |
83 | "/nix/var/nix/gcroots/per-user" | |
84 | "/nix/var/nix/profiles/per-user")) | |
85 | (chown "/nix/store" | |
86 | (passwd:uid (getpw "root")) (group:gid (getpw "nixbld01"))) | |
87 | (chmod "/nix/store" #o775) | |
88 | (for-each (cut chmod <> #o777) '("/nix/var/nix/profiles" | |
89 | "/nix/var/nix/profiles/per-user"))))) | |
90 | ||
91 | (define (nix-shepherd-service _) | |
92 | "Return a <shepherd-service> for Nix." | |
93 | (list | |
94 | (shepherd-service | |
95 | (provision '(nix-daemon)) | |
96 | (documentation "Run nix-daemon.") | |
97 | (requirement '()) | |
98 | (start #~(make-forkexec-constructor | |
99 | (list (string-append #$nix "/bin/nix-daemon")))) | |
100 | (respawn? #f) | |
101 | (stop #~(make-kill-destructor))))) | |
102 | ||
103 | (define nix-service-type | |
104 | (service-type | |
105 | (name 'nix) | |
106 | (extensions | |
107 | (list (service-extension shepherd-root-service-type nix-shepherd-service) | |
108 | (service-extension account-service-type nix-accounts) | |
109 | (service-extension activation-service-type nix-activation))) | |
110 | (default-value '()) | |
111 | (description "Run the Nix daemon."))) | |
112 | ||
113 | ;;; nix.scm ends here |