Skip to content

Instantly share code, notes, and snippets.

@benwr
Last active January 3, 2024 15:15
Show Gist options
  • Save benwr/aebe6cf6b4680bbc436612995aae7453 to your computer and use it in GitHub Desktop.
Save benwr/aebe6cf6b4680bbc436612995aae7453 to your computer and use it in GitHub Desktop.
ProtonMail Pre-mangled Transcript
[...]
Delivered-To: b@w-r.me
Received: by 2002:a05:6359:628a:b0:172:dcef:47e8 with SMTP id se10csp7687555rwb;
Wed, 3 Jan 2024 07:07:35 -0800 (PST)
X-Google-Smtp-Source: AGHT+IH4ojW/2eSP6bnumv1mMLAoAxFSeLXEys78nBFy+H3/y5fnnc7Dnxfm/WactOUsdfWbYvPy
X-Received: by 2002:a5d:5005:0:b0:336:6bf1:6e6c with SMTP id e5-20020a5d5005000000b003366bf16e6cmr9987854wrt.108.1704294454666;
Wed, 03 Jan 2024 07:07:34 -0800 (PST)
[...]
Return-Path: <root@benwr.net>
Received: from mail-4323.proton.ch (mail-4323.proton.ch. [185.70.43.23])
by mx.google.com with ESMTPS id u12-20020adfed4c000000b003368b41e153si12539108wro.258.2024.01.03.07.07.34
for <b@w-r.me>
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Wed, 03 Jan 2024 07:07:34 -0800 (PST)
Received-SPF: pass (google.com: domain of root@benwr.net designates 185.70.43.23 as permitted sender) client-ip=185.70.43.23;
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=benwr.net;
s=protonmail; t=1704294453; x=1704553653;
bh=IOpzBADibjROLVtvAMQIBOK8NOXwCFU6dvFFdJjBLj4=;
h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date:
Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector;
b=RbEpvUHNav/dHtmvHofLwMZitqdjXnRZqZ1kfsnOLPUgdCbVGumStJNVf083tTP7B
eptVfEUAb7rAyGRFa2iEk9Wk4sSV7gr3oYBvAzmBiDY7X5LNY1ud1pYEFd3PuR/YIy
7ClCqg/yChzI30dfJEkkXQhAZvTPAOO0RgplWuLk=
Date: Wed, 03 Jan 2024 15:07:30 +0000
To: Ben Weinstein-Raun <b@w-r.me>
From: Ben Weinstein-Raun <root@benwr.net>
Subject: Re: Shepherd user services that run on startup?
Message-ID: <9b72b912-8fa9-45cb-8a6f-a21cb0a80684@benwr.net>
Feedback-ID: 7118633:user:proton
MIME-Version: 1.0
Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha256; boundary="------23ff91eb91f1f9653081d9d0d07bc7238120879e7544c3be344520d778ad34f5"; charset=utf-8
This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
--------23ff91eb91f1f9653081d9d0d07bc7238120879e7544c3be344520d778ad34f5
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Message-ID: <9b72b912-8fa9-45cb-8a6f-a21cb0a80684@benwr.net>
Date: Wed, 3 Jan 2024 10:07:28 -0500
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Content-Language: en-US
To: Ben Weinstein-Raun <b@w-r.me>
From: Ben Weinstein-Raun <root@benwr.net>
Subject: Re: Shepherd user services that run on startup?
On 12/20/23 16:42, Ben Weinstein-Raun wrote:
> My guess is that this is at least possible, by defining a system-level
> service that starts a shepherd for each user. Would that work?
After struggling with this for a week, I've managed to get a user-level
`shepherd` starting! It fails to actually run, probably due to errors in
my init.scm, but I'm happy with the progress! I still have some fairly
important-feeling questions though:
* When I tried to use `sudo` via the actual package, I get an error
about it needing to be setuid-root. My workaround is to jut directly add
/run/setuid-programs to the PATH, but this is a pretty bad-feeling hack,
as it leaves an unspecified dependency. What's the right way to depend
on sudo? Force the user to pass it in as an argument, maybe?
* I still don't know how to "properly" ensure that the XDG_RUNTIME_DIR
is set, like it should be for a "proper" login shell. Right now, the
shell script just brute-creates the directory where I expec
t it on my
system (and exports that path to the environment). So, if anybody knows:
what's the right way to do this?
* Several times throughout this process, when I had errors in the shell
script that caused it to exit early, my system shepherd became
unresponsive and I had to roll-back, and then reboot using
/proc/sysrq-trigger. This was a little terrifying, since I'm currently
traveling and won't physically see my server again until February. It
was also surprising, since the script is running inside a shepherd
fork-exec constructor, and I'd have thought that this would deal
gracefully with failed starts. Is this a bug in shepherd, or am I
misusing it?
> Anyone have tips on how to go about building this, if so? Especially:
> What's the easiest way to ensure that a guix service knows the list of
> users-with-login-shells on the system?
I sidestepped this issue by forcing the user to specify usernames when
instantiating the service. This seems nicer anyway, as may
be you don't
want to start a shepherd for every user.
> And, of course, is there a simpler way?
This question still stands!
My code is on github if you're curious:
* service definition is here:
https://github.com/benwr/benwr_guix/blob/main/benwr/services/userherd.scm
* package definition is here:
https://github.com/benwr/benwr_guix/blob/main/benwr/packages/userherd.scm
* shell script is here: https://github.com/benwr/userherd
(This is probably obvious, but just in case: I'd strongly caution
against directly relying on my channel, as I break it constantly)
Thanks in advance for any help!
--------23ff91eb91f1f9653081d9d0d07bc7238120879e7544c3be344520d778ad34f5
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"
-----BEGIN PGP SIGNATURE-----
Version: ProtonMail
wnUEARYIACcFAmWVeDIJEB9MBG51G3uoFiEEkw3z4F36dhwIvy/hH0wEbnUb
e6gAAPGuAP0RQCyov0MFn4S5KEmd8FA85jZSuEeW2D/M6GGGEwN/tgEAuVXt
FYBmLawXaUV3ZrcPYOwnS02XdZMejew4W/FVAAY=
=EaBn
-----END PGP SIGNATURE-----
--------23ff91eb91f1f9653081d9d0d07bc7238120879e7544c3be344520d778ad34f5--
TRAC[Jan 3 10:07:28.660] MAIL FROM:<root@benwr.net> BODY=8BITMIME SIZE=3014 pkg=SMTP
TRAC[Jan 3 10:07:28.660] 250 2.0.0 Roger, accepting mail from <root@benwr.net> pkg=SMTP
TRAC[Jan 3 10:07:28.661] 250 2.0.0 I'll make sure <b@w-r.me> gets this pkg=SMTP
TRAC[Jan 3 10:07:28.661] RCPT TO:<b@w-r.me> pkg=SMTP
DEBU[Jan 3 10:07:28.661] Received send mail request service=smtp user="[redacted]"
DEBU[Jan 3 10:07:28.661] Received send mail request service=smtp user="[redacted]"
TRAC[Jan 3 10:07:28.661] DATA pkg=SMTP
TRAC[Jan 3 10:07:28.661] 354 2.0.0 Go ahead. End your data with <CR><LF>.<CR><LF> pkg=SMTP
TRAC[Jan 3 10:07:28.662] Message-ID: <9b72b912-8fa9-45cb-8a6f-a21cb0a80684@benwr.net> pkg=SMTP
TRAC[Jan 3 10:07:28.662] Date: Wed, 3 Jan 2024 10:07:28 -0500 pkg=SMTP
TRAC[Jan 3 10:07:28.662] . pkg=SMTP
TRAC[Jan 3 10:07:28.684] MIME-Version: 1.0 pkg=SMTP
TRAC[Jan 3 10:07:28.684] User-Agent: Mozilla Thunderbird pkg=SMTP
TRAC[Jan 3 10:07:28.684] Content-Language: en-US pkg=SMTP
DEBU[Jan 3 10:07:28.662] Checking for duplicate message service=smtp user="[redacted]"
TRAC[Jan 3 10:07:28.684] To: Ben Weinstein-Raun <b@w-r.me> pkg=SMTP
TRAC[Jan 3 10:07:28.685] From: Ben Weinstein-Raun <root@benwr.net> pkg=SMTP
TRAC[Jan 3 10:07:28.685] Subject: Re: Shepherd user services that run on startup? pkg=SMTP
TRAC[Jan 3 10:07:28.685] Content-Type: text/plain; charset=UTF-8 pkg=SMTP
TRAC[Jan 3 10:07:28.685] Content-Transfer-Encoding: 7bit pkg=SMTP
TRAC[Jan 3 10:07:28.685] pkg=SMTP
TRAC[Jan 3 10:07:28.685] On 12/20/23 16:42, Ben Weinstein-Raun wrote: pkg=SMTP
TRAC[Jan 3 10:07:28.685] pkg=SMTP
TRAC[Jan 3 10:07:28.685] > My guess is that this is at least possible, by defining a system-level pkg=SMTP
TRAC[Jan 3 10:07:28.685] > service that starts a shepherd for each user. Would that work? pkg=SMTP
TRAC[Jan 3 10:07:28.685] pkg=SMTP
TRAC[Jan 3 10:07:28.685] After struggling with this for a week, I've managed to get a user-level pkg=SMTP
TRAC[Jan 3 10:07:28.685] `shepherd` starting! It fails to actually run, probably due to errors in pkg=SMTP
TRAC[Jan 3 10:07:28.685] my init.scm, but I'm happy with the progress! I still have some fairly pkg=SMTP
TRAC[Jan 3 10:07:28.685] important-feeling questions though: pkg=SMTP
TRAC[Jan 3 10:07:28.685] pkg=SMTP
TRAC[Jan 3 10:07:28.685] * When I tried to use `sudo` via the actual package, I get an error pkg=SMTP
TRAC[Jan 3 10:07:28.685] about it needing to be setuid-root. My workaround is to jut directly add pkg=SMTP
TRAC[Jan 3 10:07:28.685] /run/setuid-programs to the PATH, but this is a pretty bad-feeling hack, pkg=SMTP
TRAC[Jan 3 10:07:28.685] as it leaves an unspecified dependency. What's the right way to depend pkg=SMTP
TRAC[Jan 3 10:07:28.685] on sudo? Force the user to pass it in as an argument, maybe? pkg=SMTP
TRAC[Jan 3 10:07:28.685] * I still don't know how to "properly" ensure that the XDG_RUNTIME_DIR pkg=SMTP
TRAC[Jan 3 10:07:28.685] is set, like it should be for a "proper" login shell. Right now, the pkg=SMTP
TRAC[Jan 3 10:07:28.685] shell script just brute-creates the directory where I expect it on my pkg=SMTP
TRAC[Jan 3 10:07:28.685] system (and exports that path to the environment). So, if anybody knows: pkg=SMTP
TRAC[Jan 3 10:07:28.685] what's the right way to do this? pkg=SMTP
TRAC[Jan 3 10:07:28.685] * Several times throughout this process, when I had errors in the shell pkg=SMTP
TRAC[Jan 3 10:07:28.685] script that caused it to exit early, my system shepherd became pkg=SMTP
TRAC[Jan 3 10:07:28.685] unresponsive and I had to roll-back, and then reboot using pkg=SMTP
TRAC[Jan 3 10:07:28.685] /proc/sysrq-trigger. This was a little terrifying, since I'm currently pkg=SMTP
TRAC[Jan 3 10:07:28.685] traveling and won't physically see my server again until February. It pkg=SMTP
TRAC[Jan 3 10:07:28.685] was also surprising, since the script is running inside a shepherd pkg=SMTP
TRAC[Jan 3 10:07:28.685] fork-exec constructor, and I'd have thought that this would deal pkg=SMTP
TRAC[Jan 3 10:07:28.685] gracefully with failed starts. Is this a bug in shepherd, or am I pkg=SMTP
TRAC[Jan 3 10:07:28.685] misusing it? pkg=SMTP
TRAC[Jan 3 10:07:28.685] pkg=SMTP
TRAC[Jan 3 10:07:28.685] > Anyone have tips on how to go about building this, if so? Especially: pkg=SMTP
TRAC[Jan 3 10:07:28.685] > What's the easiest way to ensure that a guix service knows the list of pkg=SMTP
TRAC[Jan 3 10:07:28.685] > users-with-login-shells on the system? pkg=SMTP
TRAC[Jan 3 10:07:28.685] pkg=SMTP
TRAC[Jan 3 10:07:28.685] I sidestepped this issue by forcing the user to specify usernames when pkg=SMTP
TRAC[Jan 3 10:07:28.685] instantiating the service. This seems nicer anyway, as maybe you don't pkg=SMTP
TRAC[Jan 3 10:07:28.685] want to start a shepherd for every user. pkg=SMTP
TRAC[Jan 3 10:07:28.685] pkg=SMTP
TRAC[Jan 3 10:07:28.685] > And, of course, is there a simpler way? pkg=SMTP
TRAC[Jan 3 10:07:28.685] pkg=SMTP
TRAC[Jan 3 10:07:28.685] This question still stands! pkg=SMTP
TRAC[Jan 3 10:07:28.685] pkg=SMTP
TRAC[Jan 3 10:07:28.685] pkg=SMTP
TRAC[Jan 3 10:07:28.685] pkg=SMTP
TRAC[Jan 3 10:07:28.685] My code is on github if you're curious: pkg=SMTP
TRAC[Jan 3 10:07:28.685] pkg=SMTP
TRAC[Jan 3 10:07:28.685] * service definition is here: pkg=SMTP
TRAC[Jan 3 10:07:28.685] https://github.com/benwr/benwr_guix/blob/main/benwr/services/userherd.scm pkg=SMTP
TRAC[Jan 3 10:07:28.685] * package definition is here: pkg=SMTP
TRAC[Jan 3 10:07:28.685] https://github.com/benwr/benwr_guix/blob/main/benwr/packages/userherd.scm pkg=SMTP
TRAC[Jan 3 10:07:28.685] * shell script is here: https://github.com/benwr/userherd pkg=SMTP
TRAC[Jan 3 10:07:28.685] pkg=SMTP
TRAC[Jan 3 10:07:28.685] (This is probably obvious, but just in case: I'd strongly caution pkg=SMTP
TRAC[Jan 3 10:07:28.685] against directly relying on my channel, as I break it constantly) pkg=SMTP
TRAC[Jan 3 10:07:28.685] pkg=SMTP
TRAC[Jan 3 10:07:28.685] Thanks in advance for any help! pkg=SMTP
TRAC[Jan 3 10:07:28.685] pkg=SMTP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment