From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id uB+XCaA9818HMAAA0tVLHw (envelope-from ) for ; Mon, 04 Jan 2021 16:09:04 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 0EhpBaA9819pPgAAbx9fmQ (envelope-from ) for ; Mon, 04 Jan 2021 16:09:04 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id C24DC94060F for ; Mon, 4 Jan 2021 16:09:03 +0000 (UTC) Received: from localhost ([::1]:38836 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kwSPm-0007qC-Nj for larch@yhetil.org; Mon, 04 Jan 2021 11:09:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60478) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kwRwY-0002bE-Iw for guix-devel@gnu.org; Mon, 04 Jan 2021 10:38:50 -0500 Received: from mail-40141.protonmail.ch ([185.70.40.141]:14893) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kwRwT-0006Wp-Lx for guix-devel@gnu.org; Mon, 04 Jan 2021 10:38:49 -0500 Date: Mon, 04 Jan 2021 15:38:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1609774721; bh=xh+4OC7XBJtinb1mvlBoaiKrYig5Y/RGPlg1cxkwvwM=; h=Date:To:From:Reply-To:Subject:From; b=HhDUeErkFeBdT8BJfQPR+cElIRrwuqXJ41RDfauCAWUWLZIrIPVibNm1NtCMw0fV7 Kbvdh20NXyHRoyokRSIneAfeNeYJumwXW/C+0qesIo3OXo803m44AagIrfyofBfJ6P CP4CRFdoNAoZo6IAocViR/sKZwODa8EUYIcA1N3M= To: "guix-devel@gnu.org" From: raid5atemyhomework Subject: A new paradigm for modifying operating system declarations Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=185.70.40.141; envelope-from=raid5atemyhomework@protonmail.com; helo=mail-40141.protonmail.ch 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_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 04 Jan 2021 11:08:45 -0500 X-BeenThere: guix-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: raid5atemyhomework Errors-To: guix-devel-bounces+larch=yhetil.org@gnu.org Sender: "Guix-devel" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -3.03 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=protonmail.com header.s=protonmail header.b=HhDUeErk; dmarc=pass (policy=quarantine) header.from=protonmail.com; spf=pass (aspmx1.migadu.com: domain of guix-devel-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-devel-bounces@gnu.org X-Migadu-Queue-Id: C24DC94060F X-Spam-Score: -3.03 X-Migadu-Scanner: scn1.migadu.com X-TUID: +o/C4hi5xOWH Hi guix-developers, I'd like to propose an idea for constructing `` objects. First, let me present the `decorate` form: ```scheme (define-syntax decorate (syntax-rules () ((decorate ((x ...)) a ...) (x ... a ...)) ((decorate (x) a ...) (x a ...)) ((decorate ((x ...) y ...) a ...) (x ... (decorate (y ...) a ...))) ((decorate (x y ...) a ...) (x (decorate (y ...) a ...))))) ``` Here's an example usage, instead of: ```scheme (with-output-to-port (current-error-port) (lambda () (system "echo" "an error occurred"))) ``` We can use: ```scheme (decorate ((with-output-to-port (current-error-port)) (lambda ())) (system "echo" "an error occurred")) ``` The reason why this is relevant, is that when I was tying out https://issue= s.guix.gnu.org/45643 , I ended up having several changes to the base `opera= ting-system` form: ```scheme (define system-zfs (make-zfs-package linux-libre-5.4)) (operating-system ; ... other fields ... (kernel linux-libre-5.4) (kernel-loadable-modules (list (list system-zfs "module"))) (packages (cons* system-zfs ; ... other packages ... %base-packages)) (services (cons* (service zfs-loader-service-type system-zfs) ; ... other services ... %desktop-services))) ``` So, I imagined instead of exposing `make-zfs-package` and `zfs-loader-servi= ce-type` and requiring so many modifications to various fields of `operatin= g-system` form, expose instead a `install-zfs` form, like so: ```scheme (install-zfs (operating-system (kernel linux-libre-5.4) ; ... other fields ... )) ``` This `install-zfs` form would be defined as below: ```scheme (define-public (install-zfs os) (define system-zfs (make-zfs-package (operating-system-kernel os))) (operating-system (inherit os) (location (operating-system-location os)) (kernel-loadable-modules (cons (list system-zfs "module") (operating-system-kernel-loadable-module= s os))) (packages (cons system-zfs (operating-system-packages os))) (services (cons (sevice zfs-loader-service-type system-zfs) (operating-system-services os))))) ``` This would install ZFS "correctly", by adding the module to kernel loadable= modules, adding the package so that ZFS can be managed at runtime, and add= ing the service to load ZFS module and import ZFS pools. The hope is that = this reduces the scope for errors in defining the operating system. On the other hand, if this kind of pattern becomes common, then consider: ```scheme (install-foo (install-bar (install-zfs (operating-system #;...)))) ``` Which brings us back to the `decorate` form, which reduces nestedness: ```scheme (decorate (install-foo install-bar install-zfs operating-system) #;...) ``` This seems quite elegant to me. Now for example we can consider that the `"zfs"` module supports various op= tions as well, which would be put in a `/etc/modprobe.d/zfs.conf` file. We = could consider for example that `install-zfs` could support an `options` ke= yed argument, which it will then add to the `modprobe` configuration file i= n an `etc-service-type` in a new service that it extends to the given ``. ```scheme (define install-zfs-full (lambda* (#:key (options '()) os) #;...)) (define-public install-zfs (match-lambda ((os) (install-zfs-full #:os os)) (rest (apply install-zfs-full rest)))) ``` Then in a system configuration: ```scheme (decorate ((install-zfs #:options '(("zfs_arc_max" 5000000000)) #:os) operating-system) #;...) ``` Something similar could be done for the `ddcci-driver-linux` example in the= documentation for `kernel-module-loader-service-type`: ```scheme (define-public install-ddcci (match-lambda ((os) (install-ddcci-full #:os os)) (rest (apply install-ddcci-full rest)))) (define install-ddcci-full (lambda* (#:key (options '())) os) (define config-file (plain-file "ddcci.conf" (if (null? options) "" (string-join (cons "options ddcci" options) " ")))) (operating-system (inherit os) (location (operating-system-location os)) (kernel-loadable-modules (cons ddcci-driver-linux (operating-system-kernel-loadable-modu= les os))) (services (cons* (service kernel-module-loader-service-type '("ddcci" "ddcci_backlight")) (simple-service 'ddcci-config etc-service-type `(("modprobe.d/ddcci.conf" ,config-file))) (operating-system-services os)))))) ``` Then, in the system configuration file: ```scheme (decorate (install-zfs (install-ddcci #:options '("dyndbg" "delay=3D120") #:os) operating-system) (name "example-system") #;...) ``` Obviously, it's called "decorate" since it's partly inspired by Python deco= rators, which use a similar-looking pattern, with different syntax. What are your opinions? Blech? Yummy? Is it worth exploring this paradig= m for adding particularly complex features to an operating system definitio= n? Thanks raid5atemyhomework