diff options
author | Maxime Devos <maximedevos@telenet.be> | 2021-09-13 17:22:37 +0200 |
---|---|---|
committer | Maxime Devos <maximedevos@telenet.be> | 2021-09-21 12:21:07 +0200 |
commit | ec2062f0da48c494a6b91cfb8bf31d4edb218ba3 (patch) | |
tree | 8fe452d3fe4310dd649e4bf4b364481c85832a3e /gnu | |
parent | a91e402dec1e7444543ce12870e6b5eff580c4c9 (diff) | |
download | gnunet-scheme-ec2062f0da48c494a6b91cfb8bf31d4edb218ba3.tar.gz gnunet-scheme-ec2062f0da48c494a6b91cfb8bf31d4edb218ba3.zip |
config: Automatically load defaults, system and user configuration.
* gnu/gnunet/config/fs.scm
(locate-defaults,load-configuration): New procedures.
* doc/scheme-gnunet.tm
(Loading configuration files): Document new procedure.
* gnu/gnunet/config/default.conf: New file.
* Makefile.am (nobase_dist_guilesite_DATA): Add new file.
Diffstat (limited to 'gnu')
-rw-r--r-- | gnu/gnunet/config/default.conf | 19 | ||||
-rw-r--r-- | gnu/gnunet/config/fs.scm | 35 |
2 files changed, 52 insertions, 2 deletions
diff --git a/gnu/gnunet/config/default.conf b/gnu/gnunet/config/default.conf new file mode 100644 index 0000000..ea019ef --- /dev/null +++ b/gnu/gnunet/config/default.conf | |||
@@ -0,0 +1,19 @@ | |||
1 | # -*- coding: utf-8 -*- | ||
2 | # Copyright (C) 2020, 2021 Maxime Devos | ||
3 | # SPDX-License-Identifier: FSFAP | ||
4 | # Copying and distribution of this file, with or without modification, | ||
5 | # are permitted in any medium without royalty provided the copyright | ||
6 | # notice and this notice are preserved. This file is offered as-is, | ||
7 | # without any warranty. | ||
8 | # | ||
9 | # For compatibility with C GNUnet, it is important that the default UNIXPATH, | ||
10 | # GNUNET_RUNTIME_DIR and GNUNET_USER_RUNTIME_DIR is the same. | ||
11 | |||
12 | [nse] | ||
13 | UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-nse.sock | ||
14 | |||
15 | [PATHS] | ||
16 | # Directory for UNIX domain sockets of system-wide services. | ||
17 | GNUNET_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/gnunet-system-runtime/ | ||
18 | # Likewise, for per-user services | ||
19 | GNUNET_USER_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/gnunet-${USERHOME:-${USER:-user}}-runtime/ | ||
diff --git a/gnu/gnunet/config/fs.scm b/gnu/gnunet/config/fs.scm index dfd10a5..1a073ab 100644 --- a/gnu/gnunet/config/fs.scm +++ b/gnu/gnunet/config/fs.scm | |||
@@ -34,12 +34,15 @@ | |||
34 | (define-library (gnu gnunet config fs) | 34 | (define-library (gnu gnunet config fs) |
35 | (export locate-system-configuration | 35 | (export locate-system-configuration |
36 | locate-user-configuration | 36 | locate-user-configuration |
37 | load-configuration | ||
37 | load-configuration/port! | 38 | load-configuration/port! |
38 | make-expanded-configuration) | 39 | make-expanded-configuration) |
39 | (import (only (rnrs base) | 40 | (import (only (rnrs base) |
40 | begin define and not or cond define-syntax identifier-syntax | 41 | begin define and not or cond define-syntax identifier-syntax |
41 | if ... eq? values + lambda quote vector car cdr cons string? | 42 | if ... eq? values + lambda quote vector car cdr cons string? |
42 | string-length vector? vector-ref string=? list) | 43 | string-length vector? vector-ref string=? list) |
44 | (only (rnrs control) | ||
45 | when) | ||
43 | (prefix (rnrs hashtables) | 46 | (prefix (rnrs hashtables) |
44 | rnrs:) | 47 | rnrs:) |
45 | (only (ice-9 optargs) | 48 | (only (ice-9 optargs) |
@@ -50,13 +53,18 @@ | |||
50 | getenv in-vicinity string-null? define-syntax-rule eof-object? | 53 | getenv in-vicinity string-null? define-syntax-rule eof-object? |
51 | substring error syntax-error define-syntax-parameter | 54 | substring error syntax-error define-syntax-parameter |
52 | syntax-parameterize syntax-violation identity | 55 | syntax-parameterize syntax-violation identity |
53 | make-hash-table hash-set! hash-ref hash-for-each) | 56 | make-hash-table hash-set! hash-ref hash-for-each |
57 | call-with-input-file for-each file-exists? | ||
58 | search-path %load-path) | ||
54 | (only (gnu gnunet utils hat-let) | 59 | (only (gnu gnunet utils hat-let) |
55 | let^) | 60 | let^) |
56 | (gnu gnunet config db) | 61 | (gnu gnunet config db) |
57 | (gnu gnunet config expand) | 62 | (gnu gnunet config expand) |
58 | (gnu gnunet config parser)) | 63 | (gnu gnunet config parser)) |
59 | (begin | 64 | (begin |
65 | (define (locate-defaults) | ||
66 | (search-path %load-path "gnu/gnunet/config/default.conf")) | ||
67 | |||
60 | (define (locate-system-configuration) | 68 | (define (locate-system-configuration) |
61 | "/etc/gnunet.conf") | 69 | "/etc/gnunet.conf") |
62 | 70 | ||
@@ -212,6 +220,29 @@ are added to the configuration and every variable is expanded." | |||
212 | hash) | 220 | hash) |
213 | config) | 221 | config) |
214 | 222 | ||
223 | ;; XXX no tests | ||
224 | (define* (load-configuration #:key (getenv getenv) | ||
225 | (files (list (locate-defaults) | ||
226 | (locate-system-configuration) | ||
227 | (locate-user-configuration | ||
228 | #:getenv getenv)))) | ||
229 | "Load the user configuration, system configuration and defaults. | ||
230 | The configuration files to load can be overridden by setting @var{files} | ||
231 | appropriately." | ||
232 | (define configurations | ||
233 | (list (locate-system-configuration) | ||
234 | (locate-user-configuration))) | ||
235 | (define (load! set-value!) | ||
236 | (define (load-file! file) | ||
237 | (when (and file (file-exists? file)) | ||
238 | (call-with-input-file file | ||
239 | (lambda (p) | ||
240 | (load-configuration/port! set-value! p)) | ||
241 | #:guess-encoding #t | ||
242 | #:encoding "UTF-8"))) | ||
243 | (for-each load-file! configurations)) | ||
244 | (define c (make-expanded-configuration load! #:getenv getenv)) | ||
245 | c) | ||
246 | |||
215 | ;; TODO error reporting | 247 | ;; TODO error reporting |
216 | ;; TODO actually load the configuration, defaults, ... | ||
217 | )) | 248 | )) |