From patchwork Mon May 19 00:29:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 42736 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 83D1D27BC4B; Mon, 19 May 2025 01:30:34 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL, RCVD_IN_VALIDITY_SAFE,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id D8A4927BC49 for ; Mon, 19 May 2025 01:30:33 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uGoOU-0003Mg-N1; Sun, 18 May 2025 20:30:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uGoOS-0003Le-2F for guix-patches@gnu.org; Sun, 18 May 2025 20:30:12 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uGoOQ-00014H-N8; Sun, 18 May 2025 20:30:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=g6w3hsNNrJGkxCqIraPMerlWKqQy6ltFb3o9SFjI0D8=; b=eqKIqCiJOV+Cix8AnTWnnyQeZoQSAEp4u1Yw50Y8Zbp1czuO5mPWIHd28Py1gRACr2fWBLJR8CfUK3kknpKx+/2hwoSNtmc+BrNzCOhOPl0vH6QZXP59OfhrIzlIuAFS5aqGo8H3PAxM6TjgSHYLyMMJleR+Zh6tpQq6aF4VK3NMDyEcce2UA7T8gby6KxiMDLJdKEaG4/DrS0vaGzr2eL+wJ6Ogqarea64w8ckc6DS9gyEXPyGOrkMTm4e6I07dmGFkD/YBrWzNFFH1q5KLvxdPb0F62BdX1yXnn2tWaCgpcbH0o5q9wECKIO0jSRSdX4r95mIM9VcWfl0UX/6MbQ==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1uGoOL-0006nQ-Ct; Sun, 18 May 2025 20:30:05 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#78308] [PATCH v3 02/10] services: Add etc-profile-d-service-type. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: maxim.cournoyer@gmail.com, rutherther@ditigal.xyz, lgcoelho@disroot.org, gabriel@erlikon.ch, ludo@gnu.org, guix-patches@gnu.org Resent-Date: Mon, 19 May 2025 00:30:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 78308 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 78308@debbugs.gnu.org Cc: Maxim Cournoyer , Maxim Cournoyer , Rutherther , Luis Guilherme Coelho , Gabriel Wicki , Ludovic =?utf-8?q?Court=C3=A8s?= X-Debbugs-Original-Xcc: Maxim Cournoyer , Rutherther , Luis Guilherme Coelho , Gabriel Wicki , Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 78308-submit@debbugs.gnu.org id=B78308.174761459225793 (code B ref 78308); Mon, 19 May 2025 00:30:05 +0000 Received: (at 78308) by debbugs.gnu.org; 19 May 2025 00:29:52 +0000 Received: from localhost ([127.0.0.1]:34023 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uGoO5-0006hX-7E for submit@debbugs.gnu.org; Sun, 18 May 2025 20:29:52 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]:61521) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uGoNw-0006gj-Hn for 78308@debbugs.gnu.org; Sun, 18 May 2025 20:29:44 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-7424ccbef4eso3818156b3a.2 for <78308@debbugs.gnu.org>; Sun, 18 May 2025 17:29:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747614574; x=1748219374; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=g6w3hsNNrJGkxCqIraPMerlWKqQy6ltFb3o9SFjI0D8=; b=IuNhLdIdOJ6Dpdwqkj+v/tGVvCBzDCaoDcHC/KnQJgECwP/jqZxIE0SJtZkfk6MCWv VKr9VsW2nUxCbJQd4kzI8iJxzQkYdD4NXHraFHpn3IlDeIjby/XsL4lW1BLWFHqjmmXd ORVs7GTw2G/GWMYbxK7Pq4lE02UWwHrdayouEbk5jYd1Dh5ap5YderZPBG4VrgtXeYdL wSqt/Km5u1aGFZzUr67d/84GOtmjhWlnyvy3tf2Rb0lHUhX2/0YS/ekm6RDaS+TA6lxX 4oRzInacbJFQf9rcXMixnRc4R9uCTpOMmAku6qKtBDs1TvcS/sfGs4urcQyVcHr1PWe+ M0Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747614574; x=1748219374; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g6w3hsNNrJGkxCqIraPMerlWKqQy6ltFb3o9SFjI0D8=; b=C1apeqHBsZDHctx6APjSetE1lWIOtMj6tlo1oIeRWz1XtFx8KmIRwHpJrxR8r8y5kk uJFXw/xWjCwvwS8uJ5kJbQeIrm0ovLixLTPNu8EqpJilMnFgS/12S1ys09Oyv/cdQuFz pnogwRs8FWqI3WW4Hda0nmedwQTZRR/jVReh1tWQ3BRlToK1K0UtCU0wdwP7UHE0l0v6 mClkLANse56KSobWZ2+tEYenzM3AkjVZ9ZTXDtQm3YXyvfpeCSiY5E/lxL3yz3HUDx/X RQabL85W/rRQMBGYazt2DZY3UYuEvcbCwbS0antLt4vH4IzcQTOqOPY0wxME7FrkYlGU FiNg== X-Gm-Message-State: AOJu0Yykigb4a9PAO1Mm5NGusOS6Y3uH3JlU1AvpAPejLg+ACzJww72Z Rz18d4r2a+dRE+a2zJSBH3dyeNLDdWALjBU+B5uvfqNAUkZjl8ZhKY0NIYhVFQ== X-Gm-Gg: ASbGncsfUZZ5ajYqvaUWoHg1piBgdxzzeFt/dKzL9IktpG2IZ/2POolLP+zMZLdCfDm Vay3NI7rCaZnDtpWdaclSiTdzVh4gehNo3Tv75ZOq1FgrAfN2zrnPS9KHZ8iGKDbQ793VmfyI0U 1Wx+q2SX24GDMiGb2ZtoOlKNyJIj55qeSaRu7USjfag623LWd348RAIyqc+K0f+sLp2Dq1DVNvL rTOEkzzldIsC9EVfAQxGDWCNNhLqonutZ1dObUsgo78c6qrADkidA7CdAOo0loY28HqI091Jq/X g94jYiycUZcwyNpj5A91MCeeutjLDUDTHZy6Au1s+wKGIMN6AMclPOZCrdusEcAIh4a7llQ= X-Google-Smtp-Source: AGHT+IERgAo7WwOo2rZP08ORdlRD8mGCzJ7eIIqfsswlkhqceFeXfft9fq0lM85C0I9pm783fztpxQ== X-Received: by 2002:aa7:888e:0:b0:742:a02e:dd8d with SMTP id d2e1a72fcca58-742a98b4a84mr15019038b3a.20.1747614573835; Sun, 18 May 2025 17:29:33 -0700 (PDT) Received: from localhost.localdomain ([2405:6586:be0:0:83c8:d31d:2cec:f542]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-742a970c882sm5254027b3a.55.2025.05.18.17.29.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 May 2025 17:29:33 -0700 (PDT) From: Maxim Cournoyer Date: Mon, 19 May 2025 09:29:00 +0900 Message-ID: <18ad655bcd4a5e0fba23130315d48c2e15792f47.1747614548.git.maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 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-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/services.scm (make-files->etc-directory) (files->profile-d-entries): New procedures. (etc-profile-d-service-type): New service type. * doc/guix.texi (Service Reference): Document it. * gnu/tests/base.scm (run-basic-test): Test it. Change-Id: I45dde43a1b9603c3384b933ebd1d6e45dba146b9 --- doc/guix.texi | 16 ++++++++++++ gnu/services.scm | 62 ++++++++++++++++++++++++++++++++++++++++++++++ gnu/tests/base.scm | 19 +++++++++++++- 3 files changed, 96 insertions(+), 1 deletion(-) diff --git a/doc/guix.texi b/doc/guix.texi index 8e73685a216..b236a358a1f 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -47629,6 +47629,22 @@ Service Reference pointing to the given file. @end defvar +@defvar etc-profile-d-service-type +The type of the @file{/etc/profile.d} service. This service is used to +create files under @file{/etc/profile.d}. It takes as value a list of +file-like objects, as can be produced with @code{local-file}, +@code{plain-file}, etc. Note that provided files whose file names do +not end with @file{.sh} are @emph{not} added to @file{/etc/profile.d/} +and are silently dropped. Package objects can also be provided directly +to have their @file{etc/profile.d/*.sh} prefixed files added. A simple +usage may look like: + +@example +(service etc-profile-d-service-type + (list (plain-file "youppi.sh" "HOW_IMPORTANT=very"))) +@end example +@end defvar + @defvar privileged-program-service-type Type for the ``privileged-program service''. This service collects lists of executable file names, passed as gexps, and adds them to the set of diff --git a/gnu/services.scm b/gnu/services.scm index af054339fd9..8584b16ac5c 100644 --- a/gnu/services.scm +++ b/gnu/services.scm @@ -9,6 +9,7 @@ ;;; Copyright © 2022 Tobias Geerinckx-Rice ;;; Copyright © 2023 Brian Cully ;;; Copyright © 2024 Nicolas Graves +;;; Copyright © 2025 Maxim Cournoyer ;;; ;;; This file is part of GNU Guix. ;;; @@ -26,6 +27,7 @@ ;;; along with GNU Guix. If not, see . (define-module (gnu services) + #:use-module (guix derivations) #:use-module (guix gexp) #:use-module (guix monads) #:use-module (guix store) @@ -120,6 +122,7 @@ (define-module (gnu services) special-files-service-type extra-special-file etc-service-type + etc-profile-d-service-type etc-directory privileged-program-service-type setuid-program-service-type ; deprecated @@ -926,6 +929,65 @@ (define-deprecated (etc-service files) FILES must be a list of name/file-like object pairs." (service etc-service-type files)) +(define (make-files->etc-directory name) + "Return a procedure that accept a list of FILES and compute a directory named NAME. +The returned procedure FILES argument can be packages containing +@file{etc/@var{name}.d/@var{x}.sh} scripts or single file-like objects of the +@file{.sh} file extension. The constructed procedure returns a list of +two-elements list suitable for extending `etc-service-type'." + (lambda (files) + `((,name + ,(computed-file name + ;; This is specialized variant of `file-union'. + (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (guix build utils) + (ice-9 ftw) + (ice-9 match) + (srfi srfi-1) + (srfi srfi-26)) + + (define sh-files + (append-map + (lambda (f) + (let* ((dir (format #f "~a/etc/~a" f #$name))) + `(,@(if (file-exists? dir) + (map (lambda (x) + (list x (string-append dir "/" x))) + (scandir dir + (cut string-suffix? ".sh" <>))) + (if (string-suffix? ".sh" f) + (list (list (basename + (strip-store-file-name f)) f)) + '()))))) + (list #$@files))) + + (mkdir #$output) + (chdir #$output) + + (map (match-lambda ;XXX: adapted from file-union + ((target source) + ;; Stat the source to abort early if it does not exist. + (stat source) + (mkdir-p (dirname target)) + (symlink source target))) + sh-files)))))))) + +(define files->profile-d-directory + (make-files->etc-directory "profile.d")) + +(define etc-profile-d-service-type + (service-type + (name 'etc-profile-d) + (extensions (list (service-extension etc-service-type + files->profile-d-directory))) + (compose concatenate) + (extend append) + (default-value '()) + (description "A service for populating @file{/etc/profile.d/} with POSIX +scripts having the @file{.sh} file extension, to be sourced when users +log in."))) + (define (privileged-program->activation-gexp programs) "Return an activation gexp for privileged-program from PROGRAMS." (let ((programs diff --git a/gnu/tests/base.scm b/gnu/tests/base.scm index f28c610ccb2..09fc91383df 100644 --- a/gnu/tests/base.scm +++ b/gnu/tests/base.scm @@ -170,6 +170,14 @@ (define* (run-basic-test os command #:optional (name "basic") info --version") marionette))) + (test-assert "/etc/profile.d is sourced" + (zero? (marionette-eval '(system " +. /etc/profile +set -e -x +test -f /etc/profile.d/test_profile_d.sh +test \"$PROFILE_D_OK\" = yes") + marionette))) + (test-equal "special files" '#$special-files (marionette-eval @@ -576,7 +584,16 @@ (define* (test-basic-os #:optional (kernel linux-libre)) (let* ((os (marionette-operating-system (operating-system (inherit %simple-os) - (kernel kernel)) + (kernel kernel) + (services (cons (service + etc-profile-d-service-type + (list (plain-file + "test_profile_d.sh" + "export PROFILE_D_OK=yes\n") + (plain-file + "invalid-name" + "not a POSIX script -- ignore me"))) + %base-services))) #:imported-modules '((gnu services herd) (guix combinators)))) (vm (virtual-machine os)))