From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id WExaAQu08197EwAA0tVLHw (envelope-from ) for ; Tue, 05 Jan 2021 00:34:19 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id WCXMOAq081+tCAAA1q6Kng (envelope-from ) for ; Tue, 05 Jan 2021 00:34:18 +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 A75D39403CD for ; Tue, 5 Jan 2021 00:34:18 +0000 (UTC) Received: from localhost ([::1]:58200 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kwaIj-0007Ux-Gk for larch@yhetil.org; Mon, 04 Jan 2021 19:34:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33972) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kwaHQ-00060l-22 for guix-devel@gnu.org; Mon, 04 Jan 2021 19:32:56 -0500 Received: from mail-40130.protonmail.ch ([185.70.40.130]:30679) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kwaHG-0008SS-5G for guix-devel@gnu.org; Mon, 04 Jan 2021 19:32:54 -0500 Date: Tue, 05 Jan 2021 00:32:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1609806761; bh=/ItxembXg6xw3s3ussT6Wj3P/ur4GOnsxwDCBKeX3J8=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=qUmTmAkO/2l4B8Lf8ZsYS/gPVZ3O87XcFKMJT3R3clzEQYW2HnZlB96bZ/elT1EM4 yVvn2FR0ESh2dp4GrGFJVVke6bbIGrVqL1XoK+JiPBLqeUxQL9GI9dZoAEtybciHj2 PtKHVF6iJMhGXp8+td1jptt4tfY9KB7Jm4OksJYs= To: Taylan Kammer From: raid5atemyhomework Subject: Re: A new paradigm for modifying operating system declarations Message-ID: In-Reply-To: <87b59430-b53e-47ec-32d5-abbd3be42ce7@gmail.com> References: <87b59430-b53e-47ec-32d5-abbd3be42ce7@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=185.70.40.130; envelope-from=raid5atemyhomework@protonmail.com; helo=mail-40130.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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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 Cc: "guix-devel@gnu.org" 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=qUmTmAkO; 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: A75D39403CD X-Spam-Score: -3.03 X-Migadu-Scanner: scn0.migadu.com X-TUID: f+xkN7dR4Hun Good morning Taylan, > First, let me point out a more conventional alternative to what your > 'decorate' macro does: > > (define (compose proc . rest) > "Functional composition; e.g. ((compose x y) a) =3D (x (y a))." > (if (null? rest) > proc > (let ((rest-proc (apply compose rest))) > (lambda x > (let-values ((x (apply rest-proc x))) > (apply proc x)))))) > > This allows for something like: > > ((compose install-foo install-bar install-zfs) > (operating-system ...)) > > Or perhaps cleaner: > > (define my-os-modifier (compose install-foo install-bar install-zfs)) > > (my-os-modifier > (operating-system ...)) > > If you need custom modifications within, you can do: > > (define my-os-modifier > (compose install-foo > (lambda (os) ...) > install-bar)) > > It's more verbose, but doesn't "break" standard Scheme syntax as much. > Function composition is conceptually pretty easy and probably more > well-known than "decorators" (which I had never heard of, personally). Yes, except function composition does not work on syntactic forms, which is= why, with `compose`, you have to separate the `operating-system` form inst= ead of being able to compose `operating-system` with the rest of the os mod= ifications. The intent is that you have already an existing `operating-system` form wit= h a single layer of parenthesis. With `compose`, if you want to install ZFS= and a bunch of other complex OS modifications, you have to add a layer of = parenthesis. With `decorate`, you don't: ```scheme ((compose install-zfs install-foo) (operating-system (name "my-system") #;...)) ;vs (decorate (install-zfs install-foo operating-system) (nmae "my-system") #;...) ``` > > Fewer macros means the reader needs to keep fewer special rules in mind. Fine, I'm doubling down then. ```scheme (define-syntax compose-syntax (syntax-rules () ((compose-syntax (x ...)) (syntax-rules ::: () ((form args :::) (x ... args :::)))) ((compose-syntax x) (syntax-rules ::: () ((form args :::) (x args :::)))) ((compose-syntax (x ...) y ...) (syntax-rules ::: () ((form args :::) (let-syntax ((sub-syntax (compose-syntax y ...))) (x ... (sub-syntax args :::)))))) ((compose-syntax x y ...) (syntax-rules ::: () ((form args :::) (let-syntax ((sub-syntax (compose-syntax y ...)) (x (sub-syntax args :::))))))))) ``` Then use it as follows: ``` (define-syntax my-operating-system (compose-syntax (install-zfs #:options '(("zfs_arc_max" 5000000000)) #:os) operating-system)) (my-operating-system (name "my-system") #;...) ``` Again, the goal here is to keep the nestedness of your existing, very long = `operating-system` form, which your simple `compose` function fails to do, = because you can't compose syntax with `compose` and `operating-system` is a= syntax form. > > Secondly, I wonder if passing an OS declaration through various > procedures that modify it is really the best approach in the first place. > > For build phases, we have the 'modify-phases' syntax. For services, > there is 'modify-services'. Maybe there should be a 'modify-os' kind of > syntax. (In other words, if we're going to invent new syntax, why not > go all-out and create the most convenient syntax for the use-case.) Because a *generic* form to modify the operating system is worthless --- yo= u can just define the operating-system directly. What `install-zfs` does is that it installs the same kernel-specific packag= e in three different points: * `kernel-loadable-modules`, because ZFS needs to get into the kernel someh= ow. * `packages`, because the kernel module is useless if you don't have the us= erland tools to interact with the kernel module. * `services`, because ZFS is well-documented outside of Guix as automatical= ly mounting its filesystems at bootup, but that actually requires a bit of = magic in the `init` system, specifically you need to actually **load** the = module, then execute `zpool import -a -l` to have it scan for all filesyste= ms and mount those that need automounting. Thus, an `install-zfs`, that is a *single* form that inserts the correct bi= ts in the correct ***three*** places, makes the experience of adding ZFS to= your `operating-system` easier because there's less scope for error in act= ually adding the package. You just add a single `install-zfs`, not add thr= ee things (plus an extra `(define my-zfs (make-zfs-package linux-libre-5.4)= )` before your form). Now, if this kind of simplifying form is useful for ZFS, I imagine that thi= s kind of simplifying form would also exist for other things you could inst= all into your operating system in the future. Thus, we need some way to ta= ke an existing `` and pass it through a number of single = simplifying operating system transformations, which I don't think something= like `modify-os` would work well with. Thanks raid5atemyhomework