From patchwork Thu May 8 06:02:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 42396 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 6F83A27BC4C; Thu, 8 May 2025 07:37:35 +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=-7.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_MSPIKE_H2,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 6CD9C27BC4B for ; Thu, 8 May 2025 07:37:34 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uCusY-0006Zf-Ng; Thu, 08 May 2025 02:37:11 -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 1uCusT-0006Z3-0F for guix-patches@gnu.org; Thu, 08 May 2025 02:37: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 1uCusS-0001iW-8I; Thu, 08 May 2025 02:37: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=NAuAEev3j6+ljyF5wKWcQu6KtEfQre7Sm97aiwdDhXI=; b=nlzl+n0w7899D+3BihoeRUSJx+4aZ1OusoacOCMWs1bjP7hP7FXz6jwO3WM/FC7KFVh1PETmwQ0s9VMGPHi2XJyoiZxO/KQ4yVR6UqcpesKy3hs182qorNFziM86myzSVnGzeQGAqQk1H/beKTT1Aj3wsa4EG0jV6RXODXEg8OjmWhRHeBfdkwpeucP7jsc+hQi5nzbIwmKseNAG6GUxVewqporG0F/ePndlkEFPFpY37yZlIEV2smuJqxYGuwqHxAhuiQez8cGggGlnJHuX9/lylmO4PxlTEJLoefvoZX4yLFZ5GNqfbZI8FQb5ZTLd158iB6MQiF+YH88SGMFb1Q==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1uCusQ-0000le-9J; Thu, 08 May 2025 02:37:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#78308] [PATCH 2/9] services: Add etc-profile-d-service-type. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: gabriel@erlikon.ch, ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Thu, 08 May 2025 06:37: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 , Gabriel Wicki , Ludovic =?utf-8?q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Gabriel Wicki , Ludovic =?utf-8?q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by 78308-submit@debbugs.gnu.org id=B78308.17466861672721 (code B ref 78308); Thu, 08 May 2025 06:37:02 +0000 Received: (at 78308) by debbugs.gnu.org; 8 May 2025 06:36:07 +0000 Received: from localhost ([127.0.0.1]:52866 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uCurW-0000hp-Dk for submit@debbugs.gnu.org; Thu, 08 May 2025 02:36:07 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]:46454) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uCurT-0000gf-1E for 78308@debbugs.gnu.org; Thu, 08 May 2025 02:36:04 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-736b98acaadso690160b3a.1 for <78308@debbugs.gnu.org>; Wed, 07 May 2025 23:36:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746686156; x=1747290956; 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=NAuAEev3j6+ljyF5wKWcQu6KtEfQre7Sm97aiwdDhXI=; b=jH2SRHvaTjFrRJ6c5dfwciwy6nQzNHOMNRg+NEzUGJRvmuWRfGxQ2rvIJo2b86j8Xq xoKO0tO2+0WKbdb5WeFrfTA4d/rWIv0GzuRM5+XrTtXqYjNtcc+/kuBjocfwod46MycL swR7ZOBH7obt25uTMwNTuD5zqaDjw9ziCEFd1L18ueO0xYRAcTKq9/8LRr086ovmCglG 8liAKl62tqtJsARYB2bO8xr3QwyGl5gvBp+f2INR/M5STQmaAHT4iZVr+WjlcCEzH6l2 i5QreMB0keJCLuscgUbR/bJEP43pvLXK91/2eZik6cc9frUwU3qRZmOAz28alFECcRle 2+9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746686156; x=1747290956; 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=NAuAEev3j6+ljyF5wKWcQu6KtEfQre7Sm97aiwdDhXI=; b=ABcB9xng4jFmXDLJwSG/+H5J/U1pNQu7hOHMcUngdrMEZi8QWF0yamEZajaKJ9pttO xTNRnFuOD2E+O1BthwH6J2IkaYLhi6tK3hxAxwBun49SxxyGFRA/eLoj3kJH2gYb3+qD iv96deZWJsWSignkTggfBjEN2Il4pGc2H1NhHDFKRMuQBNNZnyE9H7uN0EOH+MccA5cQ IOGyc6kZ7KS3cB7MpEVo1YzlycpjZg9ePF6/HGj7JiEVDT+FqnwFLfZWnja3w0fkRlyv d2jSMgIU6cBoRWZ3Cc4B0qrV1UpaHhl55m8PR2u06OKXBqH4AbH/GhkGUryMUtH6De1w ErmA== X-Gm-Message-State: AOJu0YxOEaQxTsRZOiLRHy/rjKOrNsmjeFv96fDOMjpt9hrNVNboqzu+ o8w1tmurmHq3qBe9oe7VJnsu0Pw3Cvh3NyxyMS61L0F0rkGBpFRFDOGZZQ== X-Gm-Gg: ASbGncupFKgCOqHRI9YvYDrgQcQ5QxmGl0LGLuah96bKFRX+GplrF8w7KK3IvqxM6+o xIYqnWIJSHJ8q/RJ8hD51oEpdJe4hSnHaApiH87laOq2vPIRqiKvaiBIy2Z1OgebD+MXwMtbH5Y xeKcfZxkOMuPHY+UHZ+GJZ7KsanRVg5mcgsZgevLM0XvqQ5hLxPIKt9OPDxtYPR7XbxR5MI28BN x2UIDMtwHAZ2raO4PGWBkhRptbYnEcc9xdeM2OVxHNtD7YkuKwr/bSOxe6NX51C8MuPA5QRN1Rg SRVrKRwipRWmSiH7mi5X5bz3af0ny50fDPN18HSfHPnZOChYuwhSh0NvfTS9 X-Google-Smtp-Source: AGHT+IF+NlHRTPhpz0r7g4lDG1pFu+mplR6GiXfABxlV83TYPXDlgB65l0/vFgpvlytnqOLXQl6SOg== X-Received: by 2002:a05:6a21:9002:b0:1f5:7873:3041 with SMTP id adf61e73a8af0-2148bc0fccamr9907046637.18.1746686156436; Wed, 07 May 2025 23:35:56 -0700 (PDT) Received: from localhost.localdomain ([2405:6586:be0:0:83c8:d31d:2cec:f542]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-74058dc45c7sm12452121b3a.71.2025.05.07.23.35.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 May 2025 23:35:55 -0700 (PDT) From: Maxim Cournoyer Date: Thu, 8 May 2025 15:02:18 +0900 Message-ID: <96db80de431149cb07171ce517d37330719fbbba.1746682206.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 | 14 +++++++++++ gnu/services.scm | 62 ++++++++++++++++++++++++++++++++++++++++++++++ gnu/tests/base.scm | 21 ++++++++++++++-- 3 files changed, 95 insertions(+), 2 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 889eab2ab35..05124e8ce6f 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -47522,6 +47522,20 @@ 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. 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 "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)))