From patchwork Sun Dec 6 08:30:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhu Zihao X-Patchwork-Id: 25598 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id D0E6727BC00; Sun, 6 Dec 2020 08:32:31 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id E6A8627BC01 for ; Sun, 6 Dec 2020 08:32:29 +0000 (GMT) Received: from localhost ([::1]:51044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1klpT3-0005Wt-0G for patchwork@mira.cbaines.net; Sun, 06 Dec 2020 03:32:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1klpRe-0004nJ-NN for guix-patches@gnu.org; Sun, 06 Dec 2020 03:31:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:37293) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1klpRe-0000VA-Ey for guix-patches@gnu.org; Sun, 06 Dec 2020 03:31:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1klpRe-0006Yn-CO for guix-patches@gnu.org; Sun, 06 Dec 2020 03:31:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#45065] [PATCH] services: nix: Move nix.conf generation to etc-service-type. Resent-From: Zhu Zihao Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 06 Dec 2020 08:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 45065 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 45065@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.160724345925206 (code B ref -1); Sun, 06 Dec 2020 08:31:02 +0000 Received: (at submit) by debbugs.gnu.org; 6 Dec 2020 08:30:59 +0000 Received: from localhost ([127.0.0.1]:48839 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1klpRa-0006YU-Lg for submit@debbugs.gnu.org; Sun, 06 Dec 2020 03:30:58 -0500 Received: from lists.gnu.org ([209.51.188.17]:43302) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1klpRY-0006YK-CX for submit@debbugs.gnu.org; Sun, 06 Dec 2020 03:30:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38948) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1klpRY-0004el-54 for guix-patches@gnu.org; Sun, 06 Dec 2020 03:30:56 -0500 Received: from mail-m975.mail.163.com ([123.126.97.5]:38786) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1klpRQ-0000DC-KW for guix-patches@gnu.org; Sun, 06 Dec 2020 03:30:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=VJCwS 0p3Df8MJc7RXfxEZ9oyhE3FF4ef6x7zMXGjSJ0=; b=ekxOUH677501KUZp4uLh5 JP+5nGVCD9fT3THnte2HO/uhXJpOiblyJmAeOonlk8Ji3NnVroUJhdQlExOi87Pu YSXJeZ2rlmlPnVcJxQCaloj5MT1kxtNzXySPuj/8F9cm3pEIDKXE5xU2Uqv1741b cF2Ch8lTSsN4kk9/2vTXPU= Received: from asus-laptop (unknown [112.93.142.243]) by smtp5 (Coremail) with SMTP id HdxpCgA3Z5uflsxfuh4RDw--.194S2; Sun, 06 Dec 2020 16:30:24 +0800 (CST) User-agent: mu4e 1.4.13; emacs 27.1 From: Zhu Zihao Date: Sun, 06 Dec 2020 16:30:22 +0800 Message-ID: <86sg8j49r5.fsf@163.com> MIME-Version: 1.0 X-CM-TRANSID: HdxpCgA3Z5uflsxfuh4RDw--.194S2 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjxU9eT5DUUUU X-Originating-IP: [112.93.142.243] X-CM-SenderInfo: pdoosuxxwbztlvw6il2tof0z/1tbiKQHyr1XlymtAYgAAsG Received-SPF: pass client-ip=123.126.97.5; envelope-from=all_but_last@163.com; helo=mail-m975.mail.163.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches From 506968bd136dd00f7aecb7a89d4000ef56d752f9 Mon Sep 17 00:00:00 2001 From: Zhu Zihao Date: Sun, 6 Dec 2020 16:26:02 +0800 Subject: [PATCH] services: nix: Move nix.conf generation to etc-service-type. /etc/nix/nix.conf is a static file doesn't need rebuild on every boot. * gnu/services/nix.scm(nix-activation): Don't create /etc/nix/nix.conf. (nix-service-etc): New function. (nix-service-type): New service-extension "nix-service-etc" to etc-service-type. --- gnu/services/nix.scm | 61 ++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/gnu/services/nix.scm b/gnu/services/nix.scm index 93f46ef71e..1aef47db0a 100644 --- a/gnu/services/nix.scm +++ b/gnu/services/nix.scm @@ -89,37 +89,41 @@ GID." (id 40000)) (nix-build-accounts 10 #:group "nixbld"))) -(define nix-activation +(define (nix-activation _) ;; Return the activation gexp. + #~(begin + (use-modules (guix build utils) + (srfi srfi-26)) + (for-each (cut mkdir-p <>) '("/nix/store" "/nix/var/log" + "/nix/var/nix/gcroots/per-user" + "/nix/var/nix/profiles/per-user")) + (chown "/nix/store" + (passwd:uid (getpw "root")) (group:gid (getpw "nixbld01"))) + (chmod "/nix/store" #o775) + (for-each (cut chmod <> #o777) '("/nix/var/nix/profiles" + "/nix/var/nix/profiles/per-user")))) + +(define nix-service-etc (match-lambda (($ package sandbox build-sandbox-items extra-config) - (with-imported-modules (source-module-closure - '((guix build store-copy))) - #~(begin - (use-modules (guix build utils) - (ice-9 format) - (srfi srfi-1) - (srfi srfi-26)) - (for-each (cut mkdir-p <>) '("/nix/store" "/nix/var/log" - "/nix/var/nix/gcroots/per-user" - "/nix/var/nix/profiles/per-user")) - (chown "/nix/store" - (passwd:uid (getpw "root")) (group:gid (getpw "nixbld01"))) - (chmod "/nix/store" #o775) - (for-each (cut chmod <> #o777) '("/nix/var/nix/profiles" - "/nix/var/nix/profiles/per-user")) - (mkdir-p "/etc/nix") - (with-output-to-file "/etc/nix/nix.conf" - (lambda _ - (format #t "sandbox = ~a~%" (if #$sandbox "true" "false")) - ;; config.nix captures store file names. - (format #t "build-sandbox-paths = ~{~a ~}~%" - (append (append-map (cut call-with-input-file <> read) - '#$(map references-file - (list package))) - '#$build-sandbox-items)) - (for-each (cut display <>) '#$extra-config) - (newline)))))))) + (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 internal-sandbox-paths + '#$build-sandbox-items)) + (for-each (cut display <>) '#$extra-config))))))))))) (define nix-shepherd-service ;; Return a for Nix. @@ -143,6 +147,7 @@ GID." (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)))) (description "Run the Nix daemon.") -- 2.29.2