From 4e2ead93eae58cf0e0eba71e222401ce96f15b05 Mon Sep 17 00:00:00 2001 From: nek0 Date: Sun, 7 Mar 2021 08:34:19 +0100 Subject: [PATCH 1/4] add configuration option --- nixos-module.nix | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/nixos-module.nix b/nixos-module.nix index 14a3256..76ed1b3 100644 --- a/nixos-module.nix +++ b/nixos-module.nix @@ -3,6 +3,52 @@ let yammat = import ./. { inherit pkgs; }; cfg = config.services.yammat; + defaultConfig = '' + # Values formatted like "_env:ENV_VAR_NAME:default_value" can be overridden by the specified environment variable. + # See https://github.com/yesodweb/yesod/wiki/Configuration#overriding-configuration-values-with-environment-variables + + static-dir: "_env:STATIC_DIR:static" + host: "_env:HOST:*4" # any IPv4 host + port: "_env:PORT:3000" + approot: "_env:APPROOT:http://localhost:3000" + ip-from-header: "_env:IP_FROM_HEADER:false" + + # Optional values with the following production defaults. + # In development, they default to the inverse. + # + # development: false + # detailed-logging: false + # should-log-all: false + # reload-templates: false + # mutable-static: false + # skip-combining: false + + database: + user: "_env:PGUSER:yammat" + password: "_env:PGPASS:yammat" + host: "_env:PGHOST:localhost" + port: "_env:PGPORT:5432" + database: "_env:PGDATABASE:yammat" + poolsize: "_env:PGPOOLSIZE:10" + + email: + - "nek0@momen" + currency: "€" + cash_charge: 50 + + copyright: "Powered by YAMMAT" + copyright_link: "https://github.com/nek0/yammat" + + block_users: false + + sendmail-location: "/usr/sbin/sendmail" + from-mail: "matemat@matemat.hq.c3d2.de" + + # optional administrative credentials. + # credentials: + # login: "admin" + # password: "password" + ''; in { options.services.yammat = with lib; { @@ -18,6 +64,14 @@ in default = "yammat"; description = "System group to run Yammat"; }; + + config = mkOption { + type = types.lines + example = '' + ${defaultConfig} + ''; + description = "Configuration for Yammat"; + }; }; config = lib.mkIf cfg.enable { @@ -55,5 +109,10 @@ in ExecStart = "${yammat}/bin/yammat"; }; }; + + environment.etc."yammat.yml" = { + enable = true; + text = cfg.config; + }; }; } From f7e29b172aa5c370921a07cea0f62971c979fa2d Mon Sep 17 00:00:00 2001 From: nek0 Date: Sun, 7 Mar 2021 19:46:36 +0100 Subject: [PATCH 2/4] execute service with config --- nixos-module.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos-module.nix b/nixos-module.nix index 76ed1b3..01af7c7 100644 --- a/nixos-module.nix +++ b/nixos-module.nix @@ -106,7 +106,7 @@ in User = cfg.user; Group = cfg.group; WorkingDirectory = yammat; - ExecStart = "${yammat}/bin/yammat"; + ExecStart = "${yammat}/bin/yammat /etc/yammata.yml"; }; }; From f98923382880d00d1d6e6bfdfc692cd80539f2ef Mon Sep 17 00:00:00 2001 From: nek0 Date: Wed, 10 Mar 2021 01:49:40 +0100 Subject: [PATCH 3/4] read default config from file --- nixos-module.nix | 50 +----------------------------------------------- 1 file changed, 1 insertion(+), 49 deletions(-) diff --git a/nixos-module.nix b/nixos-module.nix index 01af7c7..3636b02 100644 --- a/nixos-module.nix +++ b/nixos-module.nix @@ -3,52 +3,6 @@ let yammat = import ./. { inherit pkgs; }; cfg = config.services.yammat; - defaultConfig = '' - # Values formatted like "_env:ENV_VAR_NAME:default_value" can be overridden by the specified environment variable. - # See https://github.com/yesodweb/yesod/wiki/Configuration#overriding-configuration-values-with-environment-variables - - static-dir: "_env:STATIC_DIR:static" - host: "_env:HOST:*4" # any IPv4 host - port: "_env:PORT:3000" - approot: "_env:APPROOT:http://localhost:3000" - ip-from-header: "_env:IP_FROM_HEADER:false" - - # Optional values with the following production defaults. - # In development, they default to the inverse. - # - # development: false - # detailed-logging: false - # should-log-all: false - # reload-templates: false - # mutable-static: false - # skip-combining: false - - database: - user: "_env:PGUSER:yammat" - password: "_env:PGPASS:yammat" - host: "_env:PGHOST:localhost" - port: "_env:PGPORT:5432" - database: "_env:PGDATABASE:yammat" - poolsize: "_env:PGPOOLSIZE:10" - - email: - - "nek0@momen" - currency: "€" - cash_charge: 50 - - copyright: "Powered by YAMMAT" - copyright_link: "https://github.com/nek0/yammat" - - block_users: false - - sendmail-location: "/usr/sbin/sendmail" - from-mail: "matemat@matemat.hq.c3d2.de" - - # optional administrative credentials. - # credentials: - # login: "admin" - # password: "password" - ''; in { options.services.yammat = with lib; { @@ -67,9 +21,7 @@ in config = mkOption { type = types.lines - example = '' - ${defaultConfig} - ''; + default = builtins.readFile ./config/settings.yml; description = "Configuration for Yammat"; }; }; From 40badca197d722c35750746ca775ac6b7e118d4f Mon Sep 17 00:00:00 2001 From: nek0 Date: Wed, 10 Mar 2021 01:49:47 +0100 Subject: [PATCH 4/4] typo --- nixos-module.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos-module.nix b/nixos-module.nix index 3636b02..aebacee 100644 --- a/nixos-module.nix +++ b/nixos-module.nix @@ -58,7 +58,7 @@ in User = cfg.user; Group = cfg.group; WorkingDirectory = yammat; - ExecStart = "${yammat}/bin/yammat /etc/yammata.yml"; + ExecStart = "${yammat}/bin/yammat /etc/yammat.yml"; }; };