From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id AhNiEKSA+WPJXgEAbAwnHQ (envelope-from ) for ; Sat, 25 Feb 2023 04:29:40 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id SF3ND6SA+WOQsAAA9RJhRA (envelope-from ) for ; Sat, 25 Feb 2023 04:29:40 +0100 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 D59EC13E0A for ; Sat, 25 Feb 2023 04:29:39 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVlFG-0005AK-0U; Fri, 24 Feb 2023 22:29:10 -0500 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 1pVlFE-00059u-7w for guix-devel@gnu.org; Fri, 24 Feb 2023 22:29:08 -0500 Received: from mail-qv1-xf2f.google.com ([2607:f8b0:4864:20::f2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pVlFC-0001ee-8h for guix-devel@gnu.org; Fri, 24 Feb 2023 22:29:07 -0500 Received: by mail-qv1-xf2f.google.com with SMTP id jo29so893090qvb.0 for ; Fri, 24 Feb 2023 19:29:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=3mL+xa6Tf48ITDRoigLWL+wdmVYqinlCqKNVQrZ+GQk=; b=EzgmtbLc2gPMQ6LABVrxrLRxojBmvyvcSu3igxr8Q6m7ZvvDXYJiQ0+VpDfFszmVep o9tuuMbYPJmRY3ZiDvi899h71oGiGi4ZfJU5NxVZCwXAW7EDhP4/IuAmJdYpcejN2Ec4 nC92zYF3Gb8JOluIC+yg6wbjLfkbRZGWLAQLqjlPcw8Uz0tswYoPt1iBo2x4jus8tBrr aQ8wNJzzYNRpvobiVx0GlxVwXalX7810QXQ+faBmnpUfNtgt6kxu286GNMktI76420+x 7/l+niCD9hinHOOtpCObOv1MsleLv3CP3YOyTcf/UV/KwE89mW8z1Dkf7P48fKETwc4L Ql+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=3mL+xa6Tf48ITDRoigLWL+wdmVYqinlCqKNVQrZ+GQk=; b=uOB8pS+VjPi1gc0xE6zSpWf6Wd4ce9R+pQ0sne36OYAqfAKSybGmL+XdD/nCg4Ogi0 9z5b/zWJWBwJ4L1UWZrfAWE9BjaUXFIKFtae3LqrNsz1PaHw8via5qBv58OdobUHElOs F4VhsWcX3UsC1C7jOpO9P2AXb/MPiTYg/EoMVabhexD6epNbCTh4OgxZ8Hi1ToGJYCvY sR54qEGe4CdQShxO0Ks9kRmegGQH+6YVSE8CAKW5GrHEYrMHHMkBxfqM3DgWyZ6PKqG3 fTKIRfT8oKhIaJbvL32cYtlGexJhk9ZU18RKf7D7rHzstxv+hxNTo7z5Wiy0Ntkmus9J qmEQ== X-Gm-Message-State: AO0yUKUU2X8QpoDOQgcfZLkZizk+1RjFRogX1EmZ/s3LRrGyGTFxc3eB XdmXlTWcJle0Irjfe8dlny7x3l7AX6CkWA== X-Google-Smtp-Source: AK7set/SGeIqglkK5zktW615pXK//4dXuz008xYENun0r4v573ApCldZ1eEZKncMnPVkpmrNjnAOzw== X-Received: by 2002:a05:6214:1bc7:b0:56e:bdfb:f4c5 with SMTP id m7-20020a0562141bc700b0056ebdfbf4c5mr36455895qvc.36.1677295744861; Fri, 24 Feb 2023 19:29:04 -0800 (PST) Received: from hurd (dsl-141-27.b2b2c.ca. [66.158.141.27]) by smtp.gmail.com with ESMTPSA id p9-20020a05620a056900b007423caef02fsm490738qkp.122.2023.02.24.19.29.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Feb 2023 19:29:04 -0800 (PST) From: Maxim Cournoyer To: Liliana Marie Prikler Cc: guix-devel@gnu.org Subject: Re: Proof of concept: Shepherd + DBus = =?utf-8?Q?=E2=99=A5?= References: Date: Fri, 24 Feb 2023 22:29:02 -0500 In-Reply-To: (Liliana Marie Prikler's message of "Fri, 24 Feb 2023 21:55:40 +0100") Message-ID: <87sfeufmo1.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=2607:f8b0:4864:20::f2f; envelope-from=maxim.cournoyer@gmail.com; helo=mail-qv1-xf2f.google.com 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_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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.29 Precedence: list List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+larch=yhetil.org@gnu.org Sender: guix-devel-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1677295780; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=3mL+xa6Tf48ITDRoigLWL+wdmVYqinlCqKNVQrZ+GQk=; b=IEDuaNiBNL8N6fEnJtSu1nnBxrkI1MIxN8vh7TOx0jqX+ZYSDY+WAtylZiQnHpWBd3y/E2 2QLspOJafMvH9q7Z4rmaxbk1M5bQME4dmR4XKzaPhKyFwP4sWmfDbi9xEIb0sHK1103Xad XRTPQh1ck8PFGDGpN/JF3IdmeH0ll1ilu/SrgsFHE4ypiZzKq1NeXlasqp9JayCH3PeDwR D3stVgpYIr0Mur9VPwuD9Fl26tBub7QhK63sB9QNrHdepTX00fATNSIBIdpwiknOV5xFdX oc4VlqCGJ3hrdMBH6RJrmv411mb/q0J5bC7fWb0DOA3+unKE1wc7UJMCs6Ekdg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=EzgmtbLc; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1677295780; a=rsa-sha256; cv=none; b=WwHZD79EyxyVJ8PsZIENMa3UtfBuVfPozsONQv2SoI36fJEB3hv9ENNbG+LMxENkJM/U/A BhTqfPZTSjkCm043tcS35Qhl+zKkfRgr4CTUjDvJ39BQBGepJ6M3MP02QeWuFK0d5+Z6WD 7i+xXcr3Gw6XrjDPkvFdskc8YCDL3hfMEPfX4QMCHl9MVS2/SYlhpKegtBoamdc8r0r+4o EN0i/cKtvT65VGhvFoHT745SPWe56ec1kU/etv0FddgRgVRHr8DYYLXoFtspcvC0DVdKK+ 4f6FGQha7c968Urvwtv0opZJIORzRdr/dkhVbxPAh8hT4F4DIkk9R3bPrtoj+g== Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=EzgmtbLc; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -4.90 X-Spam-Score: -4.90 X-Migadu-Queue-Id: D59EC13E0A X-Migadu-Scanner: scn1.migadu.com X-TUID: W40S9FAfq5HP Hi Liliana, Liliana Marie Prikler writes: > Hi Guix, > > this comes a little late, as Gnome folks have decided that evaluating > arbitrary Javascript over DBus is perhaps not always the wisest idea=C2= =B9, > but I want to share with you a cool nifty tool regardless. > > For starters, recall that Guix can only really set up its profile > environment variables during login =E2=80=93 that is if all processes are= to > respect them. This brings us into a weird chimera state after running > `guix package': Any new variable introduced in our profile will be lost > until we restart our shell. Or will it? > > Enter guile-ac-d-bus. With the newest version of Guile (3.0.9 at time > of writing), we can actually connect to the session bus and do cool > stuff with it. Watch me: > > (define (d-bus-send/wait-for-reply bus message) > (let ((serial (d-bus-write-message bus message))) > (d-bus-conn-flush bus) > (let loop ((msg (d-bus-read-message bus))) > (if (equal? (d-bus-headers-ref (d-bus-message-headers msg) > 'REPLY_SERIAL) > serial) > msg > (loop (d-bus-read-message bus)))))) > > (let ((bus (d-bus-connect)) > (message (make-d-bus-message > MESSAGE_TYPE_METHOD_CALL 0 #f '() > (vector > (header-PATH "/org/freedesktop/DBus") > (header-DESTINATION "org.freedesktop.DBus") > (header-INTERFACE "org.freedesktop.DBus") > (header-MEMBER "Hello")) > #f))) > (write (d-bus-send/wait-for-reply bus message)) > (d-bus-disconnect bus)) > > > Okay, but how does this solve our aforementioned problem? > Well... > > (define shell > (make > #:docstring "Communicate with the GNOME Shell" > #:provides '(gnome shell) > #:start > (lambda () > (let ((bus (d-bus-connect)) > (message (make-d-bus-message > MESSAGE_TYPE_METHOD_CALL 0 #f '() > (vector > (header-PATH "/org/freedesktop/DBus") > (header-DESTINATION "org.freedesktop.DBus") > (header-INTERFACE "org.freedesktop.DBus") > (header-MEMBER "Hello")) > #f))) > (d-bus-send/wait-for-reply bus message) > bus)) > #:stop > (lambda (conn) > (when conn (d-bus-disconnect conn)) > #f) > #:actions > (let ((action->js > (lambda (action . args) > (format #f "imports.gi.GLib.~a(~{~s~^,~})" action args))) > (shell-exec > (lambda (conn js) > (let ((method-call > (make-d-bus-message > MESSAGE_TYPE_METHOD_CALL 0 #f '() > (vector > (header-PATH "/org/gnome/Shell") > (header-DESTINATION "org.gnome.Shell") > (header-INTERFACE "org.gnome.Shell") > (header-SIGNATURE "s") > (header-MEMBER "Eval")) > (list js)))) > (let ((reply (d-bus-send/wait-for-reply conn=C2=A0 > method-call))) > (apply peek 'reply (d-bus-message-body reply))))))) > (make-actions > (getenv > (lambda (conn var) > (and=3D> conn (cut shell-exec <> > (action->js 'getenv var))))) > (setenv > (lambda (conn var val) > (and=3D> conn (cut shell-exec <> > (action->js 'setenv var val))))) > (unsetenv > (lambda (conn var) > (and=3D> conn (cut shell-exec <> > (action->js 'unsetenv var))))))))) > Interesting! [...] > Anyway, we can now talk to DBus services from Shepherd, although doing > so is currently a bit of a pain in the buttocks. Much of this is due > to guile-ac-d-bus being somewhat obtuse and not having enough fibers in > it. That being said, I'm sure there's some other use-case out there > that is a good fit for this (wanna talk to loginctl for hibernation > perhaps?) One use case I saw while working on jami-service-type, where I used guile-ac-d-bus (you may want to take a peek at (guix build dbus-service)) to talk to its daemon via its D-Bus interface, was to wait until a D-Bus service is truly 'activated'. We've had problems in the past for example where services would start before a critical D-Bus service was truly up (activated), and this could be used to poll for the D-Bus service. The 'dbus-available-services' procedure from (guix build dbus-services) could be used to poll and delay a service to start until its D-Bus requirement is running. --=20 Thanks, Maxim