summaryrefslogtreecommitdiff
path: root/rodion/services
diff options
context:
space:
mode:
authorRodion Goritskov <rodion.goritskov@gmail.com>2024-04-15 00:08:55 +0400
committerRodion Goritskov <rodion.goritskov@gmail.com>2024-04-15 00:08:55 +0400
commit0547afb9d1fa12949eae81a3e5b16b114ba5ea32 (patch)
tree9775370ec4dd04c62f63c25f54733daadd02b748 /rodion/services
parent41dc65b0487f450a066e74edece5a527036b0748 (diff)
Make Miniflux configurable
Diffstat (limited to 'rodion/services')
-rw-r--r--rodion/services/miniflux.scm93
1 files changed, 64 insertions, 29 deletions
diff --git a/rodion/services/miniflux.scm b/rodion/services/miniflux.scm
index 23db38c..fbd60ab 100644
--- a/rodion/services/miniflux.scm
+++ b/rodion/services/miniflux.scm
@@ -8,47 +8,82 @@
#:use-module (gnu packages admin)
#:use-module (gnu services databases)
#:use-module (rodion packages go)
+ #:use-module (ice-9 string-fun)
#:export (miniflux-service-type
miniflux-configuration
miniflux-configuration?
miniflux-configuration-test?))
-(define-record-type* <miniflux-configuration>
- miniflux-configuration make-miniflux-configuration
- miniflux-configuration?
- (test? miniflux-configuration-test? (default #t)))
+(define (initial-string? val) (string? val))
-(define (miniflux-shepherd-service _) (list (shepherd-service
- (documentation "Run Miniflux server")
- (provision '(miniflux))
- (requirement '(networking postgresql))
- (start #~(make-forkexec-constructor
- (list (string-append #$miniflux "/bin/miniflux"))
- #:environment-variables (list
- "DATABASE_URL=host=/var/run/postgresql user=miniflux dbname=miniflux sslmode=disable"
- "RUN_MIGRATIONS=1"
- "CREATE_ADMIN=1"
- "ADMIN_USERNAME=admin"
- "ADMIN_PASSWORD=password")
- #:user "miniflux"
- #:group "miniflux"
- #:log-file "/var/log/miniflux.log"))
- (stop #~(make-kill-destructor)))))
+(define (serialize-string field-name val)
+ (format #f "~a=~a\n" (string-upcase
+ (string-replace-substring
+ (if (symbol? field-name) (symbol->string field-name) field-name) "-" "_"))
+ val))
+
+(define (serialize-initial-string field-name val)
+ (serialize-string (string-drop (symbol->string field-name) 8) val))
+
+(define (non-negative-integer? val)
+ (and (exact-integer? val) (not (negative? val))))
+
+(define (serialize-non-negative-integer field-name val)
+ (serialize-string field-name (number->string val)))
+
+(define-configuration miniflux-configuration
+ (port
+ (non-negative-integer 8080)
+ "Listening port")
+ (initial-admin-username
+ (initial-string "admin")
+ "Initial admin username")
+ (initial-admin-password
+ (initial-string "password")
+ "Initial admin password")
+ (user
+ (string "miniflux")
+ "User name for Postgresql and system account")
+ (database-url
+ (string "host=/var/run/postgresql")
+ "PostgreSQL connection string")
+ (group
+ (string "miniflux")
+ "Group for the system account"
+ empty-serializer)
+ (log-file
+ (string "/var/log/miniflux.log")
+ "Path to the log file"
+ empty-serializer))
+
+(define (miniflux-shepherd-service config)
+ (let* ((config-file (mixed-text-file "miniflux.conf" (serialize-configuration config miniflux-configuration-fields))))
+ (list (shepherd-service
+ (documentation "Run Miniflux server")
+ (provision '(miniflux))
+ (requirement '(networking postgresql))
+ (start #~(make-forkexec-constructor
+ (list (string-append #$miniflux "/bin/miniflux")
+ "-config-file" #$config-file)
+ #:user #$(miniflux-configuration-user config)
+ #:group #$(miniflux-configuration-group config)
+ #:log-file #$(miniflux-configuration-log-file config)))
+ (stop #~(make-kill-destructor))))))
(define (miniflux-account config) (list (user-group
- (name "miniflux")
+ (name (miniflux-configuration-group config))
(system? #t))
(user-account
- (name "miniflux")
- (group "miniflux")
+ (name (miniflux-configuration-user config))
+ (group (miniflux-configuration-group config))
(home-directory "/var/empty")
(shell (file-append shadow "/sbin/nologin"))
(system? #t))))
(define (miniflux-postgresql-role config)
(list (postgresql-role
- (name "miniflux")
- (create-database? #t))))
+ (name (miniflux-configuration-user config))
+ (create-database? #t))))
(define miniflux-service-type
(service-type
@@ -56,10 +91,10 @@
(description "Miniflux service")
(default-value (miniflux-configuration))
(extensions
- (list (service-extension shepherd-root-service-type
- miniflux-shepherd-service)
- (service-extension account-service-type
+ (list (service-extension account-service-type
miniflux-account)
(service-extension postgresql-service-type (const #t))
(service-extension postgresql-role-service-type
- miniflux-postgresql-role)))))
+ miniflux-postgresql-role)
+ (service-extension shepherd-root-service-type
+ miniflux-shepherd-service)))))