aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2019, 2020, 2021, 2024 Oleg Pykhalov <go.wigust@gmail.com>
;;; Copyright © 2020 Peng Mei Yu <i@pengmeiyu.com>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (gnu services nix)
  #:use-module (gnu packages admin)
  #:use-module (gnu packages bash)
  #:use-module (gnu packages package-management)
  #:use-module (gnu services base)
  #:use-module (gnu services configuration)
  #:use-module (gnu services shepherd)
  #:use-module (gnu services web)
  #:use-module (gnu services)
  #:use-module (gnu system file-systems)
  #:use-module (gnu system shadow)
  #:use-module (guix gexp)
  #:use-module (guix packages)
  #:use-module (guix records)
  #:use-module (guix store)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-26)
  #:use-module (ice-9 match)
  #:use-module (ice-9 format)
  #:use-module (guix modules)
  #:export (nix-service-type

            nix-configuration
            nix-configuration?))

;;; Commentary:
;;;
;;; This module provides a service definition for the Nix daemon.
;;;
;;; Code:

(define-record-type* <nix-configuration>
  nix-configuration make-nix-configuration
  nix-configuration?
  (package             nix-configuration-package ;file-like
                       (default nix))
  (sandbox             nix-configuration-sandbox ;boolean
                       (default #t))
  (build-directory     nix-configuration-build-directory ;string
                       (default "/tmp"))
  (build-sandbox-items nix-configuration-build-sandbox-items ;list of strings
                       (default '()))
  (extra-config        nix-configuration-extra-config ;list of strings
                       (default '()))
  (extra-options       nix-configuration-extra-options ;list of strings
                       (default '())))

;; Copied from gnu/services/base.scm
(define* (nix-build-accounts count #:key
                             (group "nixbld")
                             (shadow shadow))
  "Return a list of COUNT user accounts for Nix build users with the given
GID."
  (unfold (cut > <> count)
          (lambda (n)
            (user-account
             (name (format #f "nixbld~2,'0d" n))
             (system? #t)
             (group group)
             (supplementary-groups (list group "kvm"))
             (comment (format #f "Nix Build User ~2d" n))
             (home-directory "/var/empty")
             (shell (file-append shadow "/sbin/nologin"))))
          1+
          1))
(define (nix-accounts _)
  "Return the user accounts and user groups."
  (cons (user-group
         (name "nixbld")
         (system? #t)

         ;; Use a fixed GID so that we can create the store with the right
         ;; owner.
         (id 40000))
        (nix-build-accounts 10 #:group "nixbld")))

(define (nix-activation _)
  ;; Return the activation gexp.
  #~(begin
      (use-modules (guix build utils)
                   (srfi srfi-26))
      (for-each (cut mkdir-p <>) '("/nix/var/log"
                                   "/nix/var/nix/gcroots/per-user"
                                   "/nix/var/nix/profiles/per-user"))
      (unless (file-exists? #$%nix-store-directory)
        (mkdir-p #$%nix-store-directory)
        (chown #$%nix-store-directory
               (passwd:uid (getpw "root")) (group:gid (getpw "nixbld01")))
        (chmod #$%nix-store-directory #o775))
      (for-each (cut chmod <> #o777) '("/nix/var/nix/profiles"
                                       "/nix/var/nix/profiles/per-user"))))

(define nix-service-etc
  (match-lambda
    (($ <nix-configuration> package sandbox build-directory build-sandbox-items extra-config)
     (let ((ref-file (references-file package)))
       `(("nix/nix.conf"
          ,(computed-file
            "nix.conf"
            #~(begin
                (use-modules (srfi srfi-26)
                             (ice-9 format))
                (with-output-to-file #$output
                  (lambda _
                    (define internal-sandbox-paths
                      (call-with-input-file #$ref-file read))

                    (format #t "sandbox = ~a~%" (if #$sandbox "true" "false"))
                    ;; config.nix captures store file names.
                    (format #t "build-sandbox-paths = ~{~a ~}~%"
                            (append (list (string-append "/bin/sh=" #$bash-minimal "/bin/sh"))
                                    internal-sandbox-paths
                                    '#$build-sandbox-items))
                    (for-each (cut display <>) '#$extra-config)))))))))))

(define %nix-store-directory
  "/nix/store")

(define %immutable-nix-store
  ;; Read-only store to avoid users or daemons accidentally modifying it.
  ;; 'nix-daemon' has provisions to remount it read-write in its own name
  ;; space.
  (list (file-system
          (device %nix-store-directory)
          (mount-point %nix-store-directory)
          (type "none")
          (check? #f)
          (flags '(read-only bind-mount)))))

(define nix-shepherd-service
  ;; Return a <shepherd-service> for Nix.
  (match-lambda
    (($ <nix-configuration> package _ build-directory _ _ extra-options)
     (list
      (shepherd-service
       (provision '(nix-daemon))
       (documentation "Run nix-daemon.")
       (requirement '(user-processes file-system-/nix/store))
       (start #~(make-forkexec-constructor
                 (list (string-append #$package "/bin/nix-daemon")
                       #$@extra-options)
                 #:environment-variables
                 (list (string-append "TMPDIR=" #$build-directory)
                       "PATH=/run/current-system/profile/bin")))
       (respawn? #f)
       (stop #~(make-kill-destructor)))))))

(define nix-service-type
  (service-type
   (name 'nix)
   (extensions
    (list (service-extension shepherd-root-service-type nix-shepherd-service)
          (service-extension account-service-type nix-accounts)
          (service-extension activation-service-type nix-activation)
          (service-extension etc-service-type nix-service-etc)
          (service-extension profile-service-type
                             (compose list nix-configuration-package))
          (service-extension file-system-service-type
                             (const %immutable-nix-store))))
   (description "Run the Nix daemon.")
   (default-value (nix-configuration))))

;;; nix.scm ends here
ckages/video.scm (obs)[inputs]: Likewise. * gnu/packages/web.scm (hiawatha)[arguments]<#:phases>: Likewise. Change-Id: I0c58b3cd0bcf6e44e7b16a69f6d2739aa3c1545b Hilton Chain 2024-02-03gnu: raylib: Update to 5.0....* gnu/packages/game-development.scm (raylib): Update to 5.0. Change-Id: If3797a5f88bdd7f72d47f7f83556e16b319a38f9 Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com> Juliana Sims 2024-01-28gnu: renpy: Fix hashes....* gnu/packages/game-development.scm (python-pygame-sdl2, python-renpy): Redownload sources from upstream and use the provided hashes. Fixes: Broken hashes for Ren'py <https://bugs.gnu.org/68644#20> Liliana Marie Prikler 2024-01-28gnu: python-renpy: Update to 8.2.0....* gnu/packages/game-development.scm (python-renpy): Update to 8.2.0. Liliana Marie Prikler 2024-01-28gnu: python-pygame-sdl2: Update to 2.1.0+renpy8.2.0....* gnu/packages/game-development.scm (python-pygame-sdl2): Update to 2.1.0+renpy8.2.0. Liliana Marie Prikler 2024-01-07gnu: dds: Update to 2.9.0-1.d2bc4c2....* gnu/packages/game-development.scm (dds): Update to 2.9.0-1.d2bc4c2. Change-Id: I3c6db4e81d70112f020f2d7a0f7db26069c7591f Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com> Nicolas Goaziou 2024-01-07gnu: bbcsdl: Update to 1.39a....* gnu/packages/game-development.scm (bbcsdl): Update to 1.39a. [arguments]: Replace bundled "DejaVuSans-Oblique.ttf" with symlink in the 'install' phase. Change-Id: I7b7c8ec8a8216812e1c7a1fab74695b14f4d3ca2 宋文武 2023-12-31gnu: Add informlib....* gnu/packages/game-development.scm (informlib): New variable. Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com> Adam Faiz 2023-12-31gnu: Add inform....* gnu/packages/game-development.scm (inform): New variable. Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com> Adam Faiz 2023-12-17gnu: python-renpy: Update to 8.1.3....* gnu/packages/game-development.scm (python-renpy): Update to 8.1.3. Change-Id: I5e265cdc0f83eda9ae19a3627fa8cd69ef103806 Liliana Marie Prikler 2023-12-17gnu: python-pygame-sdl2: Update to 2.1.0+renpy8.1.3....* gnu/packages/game-development.scm (python-pygame-sdl2): Update to 2.1.0+renpy8.1.3. Change-Id: Ide0baef4762b2c4174d10e07ec94427916ac41af Liliana Marie Prikler 2023-12-10gnu: openmw: Update to 0.48.0....* gnu/packages/game-development.scm (openmw): Update to 0.48.0. * gnu/packages/graphics.scm (openmw-openscenegraph): Update to commit 68c5c5. Change-Id: I5e1ae0d59ead8de7976714cb82e8d514c308f19a Signed-off-by: Ludovic Courtès <ludo@gnu.org> Rodion Goritskov 2023-11-23gnu: godot: Update to 4.1.3....* gnu/packages/game-development.scm (godot): Update to 4.1.3. Change-Id: Ia8844da04b568e32e9138b222ddfdca7868b010f Signed-off-by: Christopher Baines <mail@cbaines.net> Adriel Dumas--Jondeau 2023-10-28gnu: godot: Update to 4.1.2....* gnu/packages/game-development.scm (godot): Update to 4.1.2. Change-Id: I358305245305c2cf31e40ce1d33f28c97c224b52 John Kehayias 2023-10-03gnu: openvr: Update to 1.26.7....* gnu/packages/game-development.scm (openvr): Update to 1.26.7. John Kehayias 2023-09-16gnu: python-pyxel: Update to 1.4.3-2.be75b72....* gnu/packages/game-development.scm (python-pyxel): Update to 1.4.3-2.be75b72. [version]: Use git-version even though it is a release. [source]<git-reference>: Use commit. <snippet>: Adjust accordingly. Liliana Marie Prikler 2023-09-02gnu: Add scummc....* gnu/packages/game-development.scm (scummc): New variable. Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com> AwesomeAdam54321 2023-08-05gnu: godot: Use system brotli....* gnu/packages/game-development.scm (godot)[source]: Do not preserve brotli. [arguments]<#:scons-flags>: Add “builtin_brotli=no”. [inputs]: Add brotli. Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com> TakeV 2023-07-30gnu: renpy: Fix image reference paths....The current approach to fixing paths is flawed in that it affects too many of them. See <https://issues.guix.gnu.org/issue/64925#4> for a detailed report of the current defect. gnu/packages/game-development.scm: (renpy)[drop-game-from-paths]: Only drop game from paths that also have “gui7”. Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com> Jesse Gibbons 2023-07-16gnu: godot: Update to 4.1.1....* gnu/packages/game-development.scm (godot): Update to 4.1.1. Tobias Geerinckx-Rice 2023-07-16gnu: mygui: Update to 3.4.2....* gnu/packages/game-development.scm (mygui): Update to 3.4.2. (mygui-gl)[inputs]: Add libglvnd, and a union of sdl2 and sdl2-image. Tobias Geerinckx-Rice 2023-07-16gnu: ode: Update to 0.16.4....* gnu/packages/game-development.scm (ode): Update to 0.16.4. Tobias Geerinckx-Rice