From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 8CkYGWMk+WMCdQAAbAwnHQ (envelope-from ) for ; Fri, 24 Feb 2023 21:56:03 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id aNUNGWMk+WPOVQEA9RJhRA (envelope-from ) for ; Fri, 24 Feb 2023 21:56:03 +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 EA8E4E1BC for ; Fri, 24 Feb 2023 21:56:02 +0100 (CET) Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=es7fYD0A; 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"; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=key1; d=yhetil.org; t=1677272163; a=rsa-sha256; cv=none; b=C0782xyqkWxy1pTN9EnLkN1PLzU5Jx33G3JxhS6BXHYD+iChrAa2Gh1pHf6m4mdMGA1WLR V4T5z2tEXSXvdD415XN6vMtPSkP83BProhARp4ZB+hz7MJTtCECt/hNe6paADsIXXqwaU7 I6wqiglxDRNIdnsbkyi4AhOlQr/BRdYVwfx4GWLrixgsLjunvjTdpEQ5L5BmNJ3RqSuhbj Up5e2kJ/7eS+Ca2gjGGGhj0mG4wJASuihDvZFZiwWAuiwmJMiRR6fwigAX36TjEVOXrgKq NnAh5flkb4/jLX4ykCJf6SwcjKSVtbiDmjoRtuDcwMA/1D1QZliSAbEyY9i8pw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=es7fYD0A; 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"; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1677272163; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=KFtmmR1DgFIw23BSCzKqi4pF3XTkq/+WpuI6sn00tnw=; b=qx5BtOClBQSTNjYR7sq01BCnmZoNL1AfYAR3g46BOLyPwUcCWSYUugPhvZ0wyNsR84BZ0n URVT1wlzLEgW9rgsJSWJarm2gfB8YTJR/GDOSyFSqwgszIKClG7joDdNfxkJPESG6d4m6M M1l7S0xr3oO6LoqoKbJs3PJ2DnN2abCdg0ilyqJrfnMKJlyb1Ts4rpre80kp7vUzv42BeJ HPDifwarzRlp9/a/8bSqVVwz1O7QqEwoojXJ+ey9mbPRfwxK8N5IF6okdHuVnIlB4hMZrO Z1hzVy9arjz48RClZfkD7W2xrCBa417e2hcASMw1yzMEj47NGNCac8MOpQczxg== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVf6Z-00037j-IY; Fri, 24 Feb 2023 15:55:47 -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 1pVf6Y-00037b-Qw for guix-devel@gnu.org; Fri, 24 Feb 2023 15:55:46 -0500 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pVf6X-0006jm-29 for guix-devel@gnu.org; Fri, 24 Feb 2023 15:55:46 -0500 Received: by mail-ed1-x541.google.com with SMTP id cq23so2386660edb.1 for ; Fri, 24 Feb 2023 12:55:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:user-agent:content-transfer-encoding:date:to:from :subject:message-id:from:to:cc:subject:date:message-id:reply-to; bh=KFtmmR1DgFIw23BSCzKqi4pF3XTkq/+WpuI6sn00tnw=; b=es7fYD0Adq3sBH4s6/2xsmgKuVTiOAfgwkbpW/rKFl3ijsVb5vyIZdokwNcnnXrRBX 1zqshnITJcso5Cucl1IMHTe8bwR67N8I4xvmGyb4PqS47r2p8UxaBheSL59Pd1vtKifw J5IjQo9OnAaz6hnZ06GFiNgHdfH8e+bRVdHEL0YOzcSlQD4yLJ2zxIjM4hBbQPYpGN9A n/89TbNRfhpKjENhzDjyw2DvCTcFwIt8dpvXOduzdL+wDbcSeW/1cc4c6C7sOx7yM6sp whVOH1krfa4ErxolqbIocaVxsdHJdqU3yU+Srab/2GNsV9DtrhTR5d7Y2OPGwg/zRfX9 unNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:content-transfer-encoding:date:to:from :subject:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=KFtmmR1DgFIw23BSCzKqi4pF3XTkq/+WpuI6sn00tnw=; b=aK/9ugzH8mFcYfgLAuZD99JyWMkZ1n0ql1rjE2m1ELGcRIik/jqkQ6mUJKVxtY/SWZ z5QDBQmyBM++AIEJlj2eAwlYO6+gxdbxvM9bG1eY1ALJ1X42ZSmwzXf0+Xk+THAUT3RE Cv2WuwNEcwAgEj4GPrsnn8eiaY94LItDeJvAcO+x9WztujdoB+spB+I2u2nKrN8cCIrC 6+AwOrVAX7un05iRpfBX3X/9Sauv9vgUrjgcNAI0GtR4KXBTlbqDtvGpNIc9JMzpfu29 +5zNZY3nAotG9fsEsgEiQVGnOTt7S0sTo5tyAqIowb10tSwoX3CC0DlMHvspWRqqOwxo Ldfg== X-Gm-Message-State: AO0yUKUjPgE1QeU+QE+guYWIziPhzJfc6cZLawNJloWXPL/OOoxK3vt4 e7iFAMXN2cAquaMKhYFxt/FxNuZKpO2UlQ== X-Google-Smtp-Source: AK7set9DwILAfqKzRlRUnIHEI6Rg17cghXbsGSmntHLeCKzpiZMRHos/k9NkmpDrHISnDX4iIHMXkA== X-Received: by 2002:a17:906:aac5:b0:8b1:7a83:1a33 with SMTP id kt5-20020a170906aac500b008b17a831a33mr25674036ejb.54.1677272143355; Fri, 24 Feb 2023 12:55:43 -0800 (PST) Received: from lumine.fritz.box (85-127-52-93.dsl.dynamic.surfer.at. [85.127.52.93]) by smtp.gmail.com with ESMTPSA id kx20-20020a170907775400b008b17de96f00sm10348074ejc.151.2023.02.24.12.55.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Feb 2023 12:55:42 -0800 (PST) Message-ID: Subject: Proof of concept: Shepherd + DBus = =?UTF-8?Q?=E2=99=A5?= From: Liliana Marie Prikler To: guix-devel@gnu.org Date: Fri, 24 Feb 2023 21:55:40 +0100 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.0 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::541; envelope-from=liliana.prikler@gmail.com; helo=mail-ed1-x541.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: X-Migadu-Queue-Id: EA8E4E1BC X-Spam-Score: -10.20 X-Migadu-Spam-Score: -10.20 X-Migadu-Scanner: scn0.migadu.com 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-Flow: FLOW_IN X-Migadu-Country: US X-TUID: JnM3R0QXxbzg 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 t= o 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: --8<---------------cut here---------------start------------->8--- (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)) --8<---------------cut here---------------end--------------->8--- Okay, but how does this solve our aforementioned problem? Well... --8<---------------cut here---------------start------------->8--- (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))))))))) --8<---------------cut here---------------end--------------->8--- Once you set the unsafe flag in Looking Glass and promise to be a very good girl, you can now extract environment variables. --8<---------------cut here---------------start------------->8--- $ herd getenv gnome PATH =20 ;;; (reply #t "\"/gnu/store/s43dhx83c3a2g79vs5anf3wdmv9lwpi3-glib- 2.70.2-bin/bin:/run/setuid- programs:/home/yuri/.config/guix/current/bin:$HOME/.guix- profile/bin:$HOME/.guix-profile/sbin:/run/current- system/profile/bin:/run/current-system/profile/sbin\"") --8<---------------cut here---------------end--------------->8--- If you were naughty and didn't do the magic dance, you get a rather unhelpful result instead. --8<---------------cut here---------------start------------->8--- $ herd getenv gnome PATH =20 ;;; (reply #f "") --8<---------------cut here---------------end--------------->8--- 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?) Cheers =C2=B9 How dare they? Don't they know that this breaks my spacebar heating workflow?