~ruther/guix-config

ref: a178510f63e4e391479c8eee6cb87e6c062861f5 guix-config/modules/ruther/services/nix.scm -rw-r--r-- 2.5 KiB
a178510f — Rutherther chore: update 8 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
;; Custom nix-daemon service that raises its NOFILE rlimit.
;;
;; The stock (gnu services nix) nix-daemon is started by shepherd with the
;; default 1024/4096 open-files rlimit.  Build processes run as @nixbld are
;; spawned as children of the daemon, so they inherit that limit — PAM limits
;; for @nixbld are ineffective because nixbld users never log in.
;;
;; This module re-exports a service type that inherits from nix-service-type
;; but replaces its shepherd-root-service-type extension with one that passes
;; #:resource-limits to make-forkexec-constructor.

(define-module (ruther services nix)
  #:use-module (srfi srfi-1)
  #:use-module (guix gexp)
  #:use-module (gnu services)
  #:use-module (gnu services nix)
  #:use-module (gnu services shepherd)
  #:export (nix-service-type/raised-nofile))

;; The nix-configuration-* accessors are not exported from (gnu services nix),
;; so reach in with @@.
(define nix-configuration-package
  (@@ (gnu services nix) nix-configuration-package))
(define nix-configuration-build-directory
  (@@ (gnu services nix) nix-configuration-build-directory))
(define nix-configuration-extra-options
  (@@ (gnu services nix) nix-configuration-extra-options))

(define (nix-shepherd-service/raised-nofile config)
  (let ((package (nix-configuration-package config))
        (build-directory (nix-configuration-build-directory config))
        (extra-options (nix-configuration-extra-options config)))
    (list
     (shepherd-service
      (provision '(nix-daemon))
      (documentation "Run nix-daemon with a raised NOFILE rlimit.")
      (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")
                #:resource-limits
                '((nofile 1048576 1048576))))
      (respawn? #f)
      (stop #~(make-kill-destructor))))))

(define nix-service-type/raised-nofile
  (service-type
   (inherit nix-service-type)
   (extensions
    (cons (service-extension shepherd-root-service-type
                             nix-shepherd-service/raised-nofile)
          (filter (lambda (ext)
                    (not (eq? (service-extension-target ext)
                              shepherd-root-service-type)))
                  (service-type-extensions nix-service-type))))))