From patchwork Tue May 13 02:31:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 42567 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 CBDB127BC4B; Tue, 13 May 2025 03:33:57 +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 1EF3527BC49 for ; Tue, 13 May 2025 03:33:57 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uEfS6-0004gw-Az; Mon, 12 May 2025 22:33:06 -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 1uEfS5-0004g4-0C for guix-patches@gnu.org; Mon, 12 May 2025 22:33:05 -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 1uEfS3-00084V-Vr; Mon, 12 May 2025 22:33:04 -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=sr8i9WlrVK6qoTRljMxFioJyNQBxdICkoH6x/AADZdw=; b=ZhGvRX1CpTsBjJ/CzciC1oxcEoRAViZSVKGAFrKtMSdpHNqIxIOiVBfPk31bguLf1IDjHV1dVs3Z3zHCd2BWCxMmJ0k+ZDi0cTzmMk0hlj6hu+59GQxNDGVG+1bUax5wR18bHpZiZ6WvB8HTTT3heV7mL5NomMWhyKWUzllFS0xoispTLkVyKGqj6TOSfOteRMOy0l0BK+XV8Zk3BGsD32eon6BP1054Qbh/V1wlghAUtL4fAjWMfY04U3CzCVyanmMp/N+jNYyQXC2+5mZDFlcn5w4OHlY4r4Q+pO8FRJt7xZTModgR8KrnwEsEC3DbGKZHNQvNIvM1dSqnn6UXlA==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1uEfS2-0001hy-8y; Mon, 12 May 2025 22:33:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#78308] [PATCH v2 2/9] services: Add etc-profile-d-service-type. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: maxim.cournoyer@gmail.com, rutherther@ditigal.xyz, gabriel@erlikon.ch, ludo@gnu.org, guix-patches@gnu.org Resent-Date: Tue, 13 May 2025 02:33:02 +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 , Gabriel Wicki , Ludovic =?utf-8?q?Court=C3=A8s?= X-Debbugs-Original-Xcc: Maxim Cournoyer , Rutherther , Gabriel Wicki , Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 78308-submit@debbugs.gnu.org id=B78308.17471035556437 (code B ref 78308); Tue, 13 May 2025 02:33:02 +0000 Received: (at 78308) by debbugs.gnu.org; 13 May 2025 02:32:35 +0000 Received: from localhost ([127.0.0.1]:56317 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uEfRW-0001fT-CE for submit@debbugs.gnu.org; Mon, 12 May 2025 22:32:35 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]:47419) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uEfRQ-0001er-Ea for 78308@debbugs.gnu.org; Mon, 12 May 2025 22:32:25 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-7423fb98cb1so3285550b3a.3 for <78308@debbugs.gnu.org>; Mon, 12 May 2025 19:32:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747103538; x=1747708338; 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=sr8i9WlrVK6qoTRljMxFioJyNQBxdICkoH6x/AADZdw=; b=aFx3wvP0W3ob9fodA4OhikpfJiz1QW4LS2SqWBQLlYHNRvIb0s8ol6lRqzR0oYBo/V 3n0XR5E31whdBftW33YjL0t71ZLJjnxacpOJSV07+gRRwK/boRgl/i6seD9i6pWS0wUs RzA5GlKRn6lXWI76VHuqt6meGUfUXesVBnJyj1sB4uNSwwLAa3bxiyPdOL3HSBjXOc0t hVHPpF783NQAjosASVyfPPsRNqCosk8i33UsfBTJGC88NZ3Ni0HevWYT0a7wub2GTQy/ FyPDlkLv4vebDWHqbM+umoBMquznszX66v54t391N4ESQFygO0Vo/KhOcxXYafTatjLq 6tAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747103538; x=1747708338; 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=sr8i9WlrVK6qoTRljMxFioJyNQBxdICkoH6x/AADZdw=; b=mMLa7sIj9Tw3O2sMsHBtrWwG5o7eE8EISXaaiCZq3XmNpyqBRGG3mAgMoW1WSoC9Pk jm5i7oG7/o4u9thHPGkqDW++ZD60z6/GtwGIkwvuhNRbx5kOcb6L708jiEwrGWcKBLwE okF7JN46UoIa4TvyhRdLRmKOAUPldA6CH6B9Cy9VIGBPMxDuEp6hyhw7xy5WDEO8tcZS a/oFQq3g6Ukg9TDwoxWwapvC+Gwgij1o8AbgQWPWToNE+XY3Hz7rqgDAM5VNx2dOADPg AmeBlkVxBeWBiNki7sBmxoG9PPvIQnV50PsKcITHMmd3CMCsUsPIuSb3h/gzuD2+NRal 1+CQ== X-Gm-Message-State: AOJu0Yz3wpOTqzZ7XdzDcn5+q7pynsJkMUXkXCgLLWcG1vUDvCYBwddp AWhumATBU59lNZ2RouL+EbWFyWrK1XLfCMnBx49t6A2o3garv0mN4o/JnPf3 X-Gm-Gg: ASbGncv5JTKkCQn03vzlo1PhI4tlu+vYRoLmdz3PMAbfdkGurb20R5B3oDxPrFjsyYW LK4XPIOO5gPH99dGgpWa0StkT79v6xl26CWiSFnundrC08YzzPkW0pGi5uAMjgsB44YM/9mJha1 W8k4aks76yqu7fw6hpHcivPsW+wWnDY533ujAvQ/PKPceI8hO681rP2Ww8FdbJdiilEunxTsDtw HVr6YgvU6d/a/IXVleachnEnWx9bSwPQO4Tu/Rcp4WMM+hpWZpUUn/ELjd/b+zUDG12o9ntpPba mjOA6q0salQ2TiiK3+bHl07duZBFEGI1LoThmNqBESCMXAi3eithjpm6a8yCaC8sEoHfkKM= X-Google-Smtp-Source: AGHT+IGULyFZG4xvMPkKi3sars85caOzp5DlPZT43pUAIBycblHu2h1PuV/bnRo55J/Ylpww9HUghQ== X-Received: by 2002:a05:6a00:148b:b0:736:a540:c9ad with SMTP id d2e1a72fcca58-7423c073074mr21735549b3a.20.1747103537608; Mon, 12 May 2025 19:32:17 -0700 (PDT) Received: from localhost.localdomain ([2405:6586:be0:0:83c8:d31d:2cec:f542]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74237a387a6sm6947460b3a.137.2025.05.12.19.32.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 May 2025 19:32:17 -0700 (PDT) From: Maxim Cournoyer Date: Tue, 13 May 2025 11:31:41 +0900 Message-ID: <1492757e33cc1159cde8a144cbaeca783c1012f1.1747103508.git.maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <5cf9f21c9626bb8c8357089caa747c2ae8ae2fca.1747103508.git.maxim.cournoyer@gmail.com> References: <5cf9f21c9626bb8c8357089caa747c2ae8ae2fca.1747103508.git.maxim.cournoyer@gmail.com> 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 | 21 ++++++++++++++-- 3 files changed, 97 insertions(+), 2 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 34092a2f735..2f80b2a0296 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -47556,6 +47556,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 20fc848e5ce..988212b4a7a 100644 --- a/gnu/tests/base.scm +++ b/gnu/tests/base.scm @@ -1,7 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2016-2020, 2022, 2024-2025 Ludovic Courtès ;;; Copyright © 2018 Clément Lassieur -;;; Copyright © 2022 Maxim Cournoyer +;;; Copyright © 2022, 2025 Maxim Cournoyer ;;; Copyright © 2022 Marius Bakke ;;; Copyright © 2024 Dariqq ;;; @@ -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 @@ -563,7 +571,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)))