[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to declare symlinks in the configuration?
From: |
Gary Johnson |
Subject: |
Re: How to declare symlinks in the configuration? |
Date: |
Tue, 23 May 2023 10:40:44 -0400 |
Marek Paśnikowski <marekpasnikowski@protonmail.com> writes:
> Thank you Gary.
>
> This is the kind of answer I was hoping for. Could you also share with
> me the corresponding service-type for the system configuration?
Hi Marek,
In the system configuration, most of the files that you would edit by
hand on another distro (e.g., config files under /etc) are not managed
directly by a single service in Guix System. Instead, you typically add
services (e.g., `postgresql-service-type`, `cups-service-type`,
`strongswan-service-type`) to your `operating-system` definition and
declare their configurations within each service's scheme code.
For example, here is how you might edit the config files for a
Postgresql server:
```scheme
(use-modules
((gnu packages databases) #:select (postgresql))
((gnu packages geo) #:select (postgis))
((gnu services) #:select (service))
((gnu services databases) #:select (postgresql-service-type
postgresql-configuration postgresql-config-file))
((gnu services desktop) #:select (%desktop-services))
((gnu system) #:select (operating-system))
((guix gexp) #:select (local-file)))
(operating-system
;; ...Eliding all the fields except `services`...
(services (cons (service postgresql-service-type
(postgresql-configuration
(postgresql postgresql)
(extension-packages (list postgis))
(config-file
(postgresql-config-file
(hba-file (local-file "etcfiles/pg_hba.conf"))
(extra-config '(("max_worker_processes" "12")
("max_parallel_workers" "40")
("max_parallel_maintenance_workers" "8")
("max_parallel_workers_per_gather"
"4")
("parallel_leader_participation"
"on")))))))
%desktop-services)))
```
In this example, I showed two ways of specifying the contents of a
config file for this service:
1. Using `local-file` to pull in the contents of a text file somewhere
on disk. In this case, I keep my system-wide service config files
under a directory called "etcfiles" (in my home directory). For
config files referenced in my `guix home` configuration, I use a
directory called "dotfiles".
2. Including the contents of these files directly in the
`operating-system` declaration. In this case, you see me specifying
key-value pairs for the main Postgresql config file in a nested list
under the `extra-config` record parameter.
=======================================================================
Now...having provided the above explanation as the typical usage pattern
for configuring services on Guix System, I will add that there is an
escape hatch that you can use (as a last resort if there isn't an
existing service that controls the files you want to edit).
This is the service called `etc-service-type`. You can use it to declare
any arbitrary files that would like added immutably under the top level
"/etc" directory. You can use it like so:
```scheme
(use-modules
((gnu services) #:select (service etc-service-type))
((gnu services desktop) #:select (%desktop-services))
((gnu system) #:select (operating-system))
((guix gexp) #:select (local-file)))
(operating-system
;; ...Eliding all the fields except `services`...
(services (cons (service etc-service-type
`(("resolv.conf" ,(local-file
"etcfiles/resolv.conf"))))
%desktop-services)))
```
Now you know, and knowing is half the battle. ;)
Have fun and happy hacking on Guix!
~Gary
--
Protect yourself from surveillance: https://emailselfdefense.fsf.org
=======================================================================
() ascii ribbon campaign - against html e-mail
/\ www.asciiribbon.org - against proprietary attachments
Why is HTML email a security nightmare? See https://useplaintext.email/
Please avoid sending me MS-Office attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html