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 ms0.migadu.com with LMTPS id wO9iOBiEbmHJhAAAgWs5BA (envelope-from ) for ; Tue, 19 Oct 2021 10:38:48 +0200 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 cK/8MxiEbmHlIAAAbx9fmQ (envelope-from ) for ; Tue, 19 Oct 2021 08:38:48 +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 50FBB8A90 for ; Tue, 19 Oct 2021 10:38:48 +0200 (CEST) Received: from localhost ([::1]:37864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mckdx-0007Cc-MD for larch@yhetil.org; Tue, 19 Oct 2021 04:38:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45008) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mckdc-0007CK-Vv for help-guix@gnu.org; Tue, 19 Oct 2021 04:38:25 -0400 Received: from mx1.dismail.de ([78.46.223.134]:6220) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mckda-00076F-8l for help-guix@gnu.org; Tue, 19 Oct 2021 04:38:24 -0400 Received: from mx1.dismail.de (localhost [127.0.0.1]) by mx1.dismail.de (OpenSMTPD) with ESMTP id d6534491 for ; Tue, 19 Oct 2021 10:38:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=dismail.de; h=date :message-id:from:to:subject; s=20190914; bh=nW5QAJmkZ9LvQMsz5Twc uA2xhBg948ZqRMRL4kyF0Ts=; b=uWUsVFpbRsvHxMCmpWbNLsRsaDhZd4iwNWb9 JeTUatw0ndWi4ibEaDhM/178v7Twu83gu3tUaRS6C8Uke5hGTOl8+loJ6111IrV/ ToPQxc5tmUOXorbYelmDPGIDLtv3c3W/wT+o+2BNaFk19NoJUBXR1Ew8BVZQ8chW rXIEKqOqguwa8d08esbMUdLeZJBMxAeEpBt4tgh8rnqCoGZ1dB/3MzGin+tlnVfx yF9lCl64KZpMj6amWYBRETL1NusYH+qatxGSOXbWhHCBeN7FZ38//HiiO+eXyz4A yZk2pJzNZICPhwat1+LV6DMDCx4Url/jOW8Ppft8KkPdRCxUgg== Received: from smtp1.dismail.de ( [10.240.26.11]) by mx1.dismail.de (OpenSMTPD) with ESMTP id a4ede990 for ; Tue, 19 Oct 2021 10:38:15 +0200 (CEST) Received: from smtp1.dismail.de (localhost [127.0.0.1]) by smtp1.dismail.de (OpenSMTPD) with ESMTP id 8d18f8e1 for ; Tue, 19 Oct 2021 10:38:15 +0200 (CEST) Received: by dismail.de (OpenSMTPD) with ESMTPSA id b3f3d871 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO) for ; Tue, 19 Oct 2021 10:38:14 +0200 (CEST) Date: Tue, 19 Oct 2021 04:38:12 -0400 Message-Id: <87bl3lxvd7.fsf@dismail.de> From: Joshua Branson To: help-guix@gnu.org Subject: When and how should one use "(thunked)" from (guix records)? Received-SPF: pass client-ip=78.46.223.134; envelope-from=jbranso@dismail.de; helo=mx1.dismail.de X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-guix@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-guix-bounces+larch=yhetil.org@gnu.org Sender: "Help-Guix" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1634632728; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=osEQ4hRGVE0hoHhXAKouqB0YeDOlKTw2Xii+G4TDkKM=; b=NoQzx4zbMoipfBWFTHWWZnxgQo0+MGIVb/HbhWGXgjkK+HpyP6QXCFKQgk2mwmj33701A9 XuE3pDfcQnqI/eQPb93bYqFcEBbj7KStHvaQAHsbgX0umt7YWm6IK8lHaf66SVzqrIKTdT 6nDPLoeqR4qFM9rxqcZdbN70wbOiyDdphkkqwAJM6ngl3ChdIVAOkYxeeOm9LUw7lh3fEN 6GLpuiGbE5eLm0efUXxiGNDjHQNE1lBfXut7QXVfkBNgJDKocbSU87waJnmUh1GawOBJMb Ffp6XJhpLdGRrDyHxVdtzRaN0ajSd9EJdfuvayM4rL9sr+H0F/WvIfC2A5Muwg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1634632728; a=rsa-sha256; cv=none; b=UGQxyYnNNxulK+XE7AeC8+XoDNWahzmuY8gsWDobCel/nTh0VgrlZzTc+EUkEo7j93WROU jjzyXmAWG2bgWZkhtSJA6JYvjcDySUUbDR0aZtxeAgQPMFiIwcll4jvrqu8yEDu35P0zf1 lMebJNoN45pp3lvi4K6oaLP5v9TzNAK4ThTlGsM51PYFiiAhJO+eUvyV0HaGvDhHjFhImv RZOs2lNs+g9q9CiNDprw/EE1W+VEa9Z53pZTtwz8pPodm8JCULq0wBEIQRAW3CzhMsNGd4 +pfi4vzGG5bR5pKFStqB2yfRSFX2PEtqHWc6tTckt3AUReYp5Lx7vDj2lkWemw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=dismail.de header.s=20190914 header.b=uWUsVFpb; spf=pass (aspmx1.migadu.com: domain of help-guix-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=help-guix-bounces@gnu.org X-Migadu-Spam-Score: -4.13 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=dismail.de header.s=20190914 header.b=uWUsVFpb; dmarc=pass (policy=reject) header.from=dismail.de; spf=pass (aspmx1.migadu.com: domain of help-guix-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=help-guix-bounces@gnu.org X-Migadu-Queue-Id: 50FBB8A90 X-Spam-Score: -4.13 X-Migadu-Scanner: scn1.migadu.com X-TUID: s8g1DQz03sL2 Hey guix! I'm trying to flush out the (guix records) for the =opensmtpd-service=. It's super fun doing it by the way. If you've never messed with (guix records) then you should totally give it a try. Thanks for the author of (guix records). You did a really great job! The purpose of this email is to get some suggestions on my opensmtpd-records.scm file and to use this email as a VERY ROUGH draft for a (guix records) blog post, if there is interest in it. :) The code that I have so far can be seen here: https://notabug.org/jbranso/linode-guix-system-configuration/src/master/opensmtpd-records.scm I'm open to suggestions. :) I have a basic procedure that turns a into a string... (define (opensmtpd-configuration->string record) ...) I've had a ton of fun using the =(thunked)= bit in records. The documentation in the source code says something like this (also does the guix manual document guix records somewhere?). #+BEGIN_EXAMPLE The 'port' field is \"thunked\", meaning that calls like '(thing-port x)' will actually compute the field's value in the current dynamic extent, which is useful when referring to fluids in a field's value. Furthermore, that thunk can access the record it belongs to via the 'this-thing' identifier. #+END_EXAMPLE I've found some "too-clever" ways of using (thunked) that people on irc mentioned may NOT be wise to use. For example, using (thunked) to define mutually exclusive fieldnames and a fieldname that returns another fieldnames value. I think these are not "good" ways of using (thunked). Anyone have any good ideas for using (thunked)? Below is some obligatory code. * This bit of guix records shows off the =(thunked)= and =this-record=. =(thunked)= lets you refer to the record that is being defined. In this case, I am defining mutually exclusive fieldnames...If =relay= is defined, then =local-delivery= returns =#f= as its value, which is pretty awesome. *Note*: a simpler way to define a mutually exclusive fieldnames is to have one fieldname that accepts == or ==. #+BEGIN_SRC scheme (define-record-type* opensmtpd-action make-opensmtpd-action opensmtpd-action? this-record (name opensmtpd-action-name (default "local")) (relay opensmtpd-action-relay (default "#f") (local-delivery opensmtpd-action-local-delivery ;;type ;; local-delivery has a default value so (service opensmtpd-service) will just work for ;; local email delivery (default (opensmtpd-local-delivery-configuration)) (thunked) (sanitize (lambda (value) (cond ;; if relay has a value, then local-delivery should be #f ;; man (guix records) rocks! ;; TODO/FIXME, perhaps I should merge fieldnames 'relay', 'local-delivery', 'forward-only', ;; and 'expand-only' into one fildname called "method". Then the user has to use a specific ;; record type to be mutually exclusive. [(opensmtpd-action-relay this-record) #f] [(opensmtpd-local-delivery-configuration? value) value] [else (display (string-append " fieldname 'local-delivery' " "needs to be of type .\n")) (throw 'bad! value)]))))) #+END_SRC * This bit of guix records defines a fieldname which returns the type of another fieldname Fieldname =type= returns the type of values that =values= has either ='list-of-strings= or ='assoc-list=. *Note*: It is probably better to define a function outside of the record that returns the type that value is. That just makes it conceptually easier for the next hacker. #+BEGIN_SRC scheme (define-record-type* opensmtpd-table make-opensmtpd-table opensmtpd-table? this-record ;; string ;; is a list of values or key values ;; eg: (list "mysite.me" "your-site.com") ;; eg: (list ("joshua" . "joshua@gnu.org") ("james" . "james@gnu.org")) (values opensmtpd-table-values (default #f) (sanitize (lambda (value) (if (or (list-of-strings? value) (assoc-list? value)) value (begin (display " fieldname: 'value' must be a list of strings or an association list.\n") (throw 'bad! value)))))) ;; can be of type: (quote list-of-strings) or (quote assoc-list) ;; type is discovered during the initialition phase. The user SHOULD NEVER set the type. ;; TODO jpoiret: on irc reccomends that I just use an outside function to determine fieldname 'values', type. ;; it would be "simpler" and possibly easier for the next person working on this code to understand what is happening. (type opensmtpd-table-type (default #f) (thunked) (sanitize (lambda (value) (if (list-of-strings? (opensmtpd-table-values this-record)) (quote list-of-strings) (quote assoc-list)))))) #+END_SRC * I found this is the guix source code...I'm not sure what the (thunked) offers... #+BEGIN_SRC scheme ;; Configuration of an Xorg server. (define-record-type* xorg-configuration make-xorg-configuration xorg-configuration? (modules xorg-configuration-modules ;list of packages (thunked) ; filter out modules not supported on current system (default (filter (lambda (p) (member (%current-system) (package-supported-systems p))) %default-xorg-modules))) (fonts xorg-configuration-fonts ;list of packges (default %default-xorg-fonts)) (drivers xorg-configuration-drivers ;list of strings (default '())) (resolutions xorg-configuration-resolutions ;list of tuples (default '())) (keyboard-layout xorg-configuration-keyboard-layout ;#f | (default #f)) (extra-config xorg-configuration-extra-config ;list of strings (default '())) (server xorg-configuration-server ;package (default xorg-server)) (server-arguments xorg-configuration-server-arguments ;list of strings (default %default-xorg-server-arguments))) #+END_SRC