unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* Service definitions: create a symlink in /etc???
@ 2024-07-28 20:59 Zack Weinberg
  2024-08-03  8:43 ` Marek Paśnikowski
  0 siblings, 1 reply; 3+ messages in thread
From: Zack Weinberg @ 2024-07-28 20:59 UTC (permalink / raw)
  To: help-guix

I am trying to write a service definition for a slightly weird daemon
that, in particular, insists on being told the system hostname via a
file of its own, instead of reading it out of /etc/hostname or using
gethostname.  The logical way to deal with this is to make that special
file be a symlink to one of /etc/hostname, /etc/static/hostname, or
/gnu/store/xxxxxxxx-hostname (i.e. the store entry /etc/static/hostname
points at).  But I can't figure out how to do that.  There doesn't seem
to be an analogue of local-file or plain-file for symlinks, and I just
spent half an hour poking at the guix repl trying to get the daemon to
cough up /gnu/store/xxxxxxxx-hostname as a thing I could put into a
gexp, without any luck.

How would you suggest that this be done?

zw


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Service definitions: create a symlink in /etc???
  2024-07-28 20:59 Service definitions: create a symlink in /etc??? Zack Weinberg
@ 2024-08-03  8:43 ` Marek Paśnikowski
  2024-08-03 14:26   ` Edouard Klein
  0 siblings, 1 reply; 3+ messages in thread
From: Marek Paśnikowski @ 2024-08-03  8:43 UTC (permalink / raw)
  To: help-guix

"Zack Weinberg" <zack@owlfolio.org> writes:

> There doesn't seem to be an analogue of local-file or plain-file for
> symlinks, and I just spent half an hour poking at the guix repl trying
> to get the daemon to cough up /gnu/store/xxxxxxxx-hostname as a thing
> I could put into a gexp, without any luck.
>
> How would you suggest that this be done?
>

I was also stumped on this question in the past.  The key insight is
that any declared file is a symlink to the Gnu Store itself.  Further,
it does not really matter what kind of file type the daemon
configuration is in.  All it wants is A file with the hostname, right?

You could specify a (plain-file "filename" "hostname") in the
[extra-special-file service][1] for a quick solution, but that would
complicate any future hostname changes.  The proper solution is to
define a variable holding the hostname externally to the
operating-system record, and use this variable in both the
(operating-system (host-name)) field and a (mixed-text-file "filename"
hostname) [procedure][2]

[1]: https://guix.gnu.org/manual/devel/en/html_node/Base-Services.html

[2]: https://guix.gnu.org/manual/devel/en/html_node/G_002dExpressions.html


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Service definitions: create a symlink in /etc???
  2024-08-03  8:43 ` Marek Paśnikowski
@ 2024-08-03 14:26   ` Edouard Klein
  0 siblings, 0 replies; 3+ messages in thread
From: Edouard Klein @ 2024-08-03 14:26 UTC (permalink / raw)
  To: Marek Paśnikowski; +Cc: help-guix

Hi,

An quicker and dirtier solution is to create an activation service that will create a
symlink:

(extend-service
  activation
  #~(begin
            (unless (stat "/etc/whatever" #f)
              (symlink "/etc/hostname"
                       "/etc/whatever"))))

This is using beaverlabs's functional syntax
https://guix-hosting.com/docs/tuto/getting-started.html
but you can easily enough deduce the non sweetened version from the
macro definition
https://gitlab.com/edouardklein/guix/-/blob/beaverlabs/beaver/functional-services.scm?ref_type=heads#L60


Cheers,

Marek Paśnikowski <marek@marekpasnikowski.pl> writes:

> "Zack Weinberg" <zack@owlfolio.org> writes:
>
>> There doesn't seem to be an analogue of local-file or plain-file for
>> symlinks, and I just spent half an hour poking at the guix repl trying
>> to get the daemon to cough up /gnu/store/xxxxxxxx-hostname as a thing
>> I could put into a gexp, without any luck.
>>
>> How would you suggest that this be done?
>>
>
> I was also stumped on this question in the past.  The key insight is
> that any declared file is a symlink to the Gnu Store itself.  Further,
> it does not really matter what kind of file type the daemon
> configuration is in.  All it wants is A file with the hostname, right?
>
> You could specify a (plain-file "filename" "hostname") in the
> [extra-special-file service][1] for a quick solution, but that would
> complicate any future hostname changes.  The proper solution is to
> define a variable holding the hostname externally to the
> operating-system record, and use this variable in both the
> (operating-system (host-name)) field and a (mixed-text-file "filename"
> hostname) [procedure][2]
>
> [1]: https://guix.gnu.org/manual/devel/en/html_node/Base-Services.html
>
> [2]: https://guix.gnu.org/manual/devel/en/html_node/G_002dExpressions.html


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-03 14:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-28 20:59 Service definitions: create a symlink in /etc??? Zack Weinberg
2024-08-03  8:43 ` Marek Paśnikowski
2024-08-03 14:26   ` Edouard Klein

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).