1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2019 Oleg Pykhalov <go.wigust@gmail.com>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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))
38 ;;; This module provides a service definition for the Nix daemon.
47 ;; Copied from gnu/services/base.scm
48 (define* (nix-build-accounts count #:key
51 "Return a list of COUNT user accounts for Nix build users with the given
53 (unfold (cut > <> count)
56 (name (format #f "nixbld~2,'0d" n))
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"))))
65 (define (nix-accounts _)
66 "Return the user accounts and user groups."
71 ;; Use a fixed GID so that we can create the store with the right
74 (nix-build-accounts 10 #:group "nixbld")))
76 (define (nix-activation _)
77 "Return the activation gexp."
78 (with-imported-modules '((guix build utils))
80 (use-modules (guix build utils)
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"))
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")))))
91 (define (nix-shepherd-service _)
92 "Return a <shepherd-service> for Nix."
95 (provision '(nix-daemon))
96 (documentation "Run nix-daemon.")
98 (start #~(make-forkexec-constructor
99 (list (string-append #$nix "/bin/nix-daemon"))))
101 (stop #~(make-kill-destructor)))))
103 (define nix-service-type
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)))
111 (description "Run the Nix daemon.")))
113 ;;; nix.scm ends here