nixos/keter: 2.0 -> 2.1

keter 2.1 now can log to stderr instead of file rotation.
Which is faster and more reliable.
These changes support that.

Announcement:
https://discourse.haskell.org/t/keter-2-1-0-released/6134

fix test by disabling log rotation

run nixpkgs fmt

move comment right before L37

run nixpkgs format on test

Add overridable default configuration

depracate keterRoot and use root, same for package

split doc lines

use lib.getExe to get keter binary

put mkRenamedOptionModule on one line
This commit is contained in:
Jappie Klooster 2023-04-11 15:38:34 +02:00
parent 2d623b4689
commit 3f2f5bea96
2 changed files with 87 additions and 57 deletions

View File

@ -1,53 +1,82 @@
{ config, pkgs, lib, ... }: { config, pkgs, lib, ... }:
let let
cfg = config.services.keter; cfg = config.services.keter;
yaml = pkgs.formats.yaml {};
in in
{ {
meta = { meta = {
maintainers = with lib.maintainers; [ jappie ]; maintainers = with lib.maintainers; [ jappie ];
}; };
imports = [
(lib.mkRenamedOptionModule [ "services" "keter" "keterRoot" ] [ "services" "keter" "root" ])
(lib.mkRenamedOptionModule [ "services" "keter" "keterPackage" ] [ "services" "keter" "package" ])
];
options.services.keter = { options.services.keter = {
enable = lib.mkEnableOption (lib.mdDoc ''keter, a web app deployment manager. enable = lib.mkEnableOption (lib.mdDoc ''keter, a web app deployment manager.
Note that this module only support loading of webapps: Note that this module only support loading of webapps:
Keep an old app running and swap the ports when the new one is booted. Keep an old app running and swap the ports when the new one is booted.
''); '');
keterRoot = lib.mkOption { root = lib.mkOption {
type = lib.types.str; type = lib.types.str;
default = "/var/lib/keter"; default = "/var/lib/keter";
description = lib.mdDoc "Mutable state folder for keter"; description = lib.mdDoc "Mutable state folder for keter";
}; };
keterPackage = lib.mkOption { package = lib.mkOption {
type = lib.types.package; type = lib.types.package;
default = pkgs.haskellPackages.keter; default = pkgs.haskellPackages.keter;
defaultText = lib.literalExpression "pkgs.haskellPackages.keter"; defaultText = lib.literalExpression "pkgs.haskellPackages.keter";
description = lib.mdDoc "The keter package to be used"; description = lib.mdDoc "The keter package to be used";
}; };
globalKeterConfig = lib.mkOption { globalKeterConfig = lib.mkOption {
type = lib.types.attrs; type = lib.types.submodule {
default = { freeformType = yaml.type;
ip-from-header = true; options = {
listeners = [{ ip-from-header = lib.mkOption {
host = "*4"; default = true;
port = 6981; type = lib.types.bool;
}]; description = lib.mdDoc "You want that ip-from-header in the nginx setup case. It allows nginx setting the original ip address rather then it being localhost (due to reverse proxying)";
}; };
# You want that ip-from-header in the nginx setup case listeners = lib.mkOption {
# so it's not set to 127.0.0.1. default = [{ host = "*"; port = 6981; }];
# using a port above 1024 allows you to avoid needing CAP_NET_BIND_SERVICE type = lib.types.listOf (lib.types.submodule {
defaultText = lib.literalExpression '' options = {
{ host = lib.mkOption {
ip-from-header = true; type = lib.types.str;
listeners = [{ description = lib.mdDoc "host";
host = "*4"; };
port = 6981; port = lib.mkOption {
}]; type = lib.types.int;
} description = lib.mdDoc "port";
''; };
description = lib.mdDoc "Global config for keter"; };
});
description = lib.mdDoc ''
You want that ip-from-header in
the nginx setup case.
It allows nginx setting the original ip address rather
then it being localhost (due to reverse proxying).
However if you configure keter to accept connections
directly you may want to set this to false.'';
};
rotate-logs = lib.mkOption {
default = false;
type = lib.types.bool;
description = lib.mdDoc ''
emits keter logs and it's applications to stderr.
which allows journald to capture them.
Set to true to let keter put the logs in files
(useful on non systemd systems, this is the old approach
where keter handled log management)'';
};
};
};
description = lib.mdDoc "Global config for keter, see <https://github.com/snoyberg/keter/blob/master/etc/keter-config.yaml> for reference";
}; };
bundle = { bundle = {
@ -90,12 +119,12 @@ Keep an old app running and swap the ports when the new one is booted.
config = lib.mkIf cfg.enable ( config = lib.mkIf cfg.enable (
let let
incoming = "${cfg.keterRoot}/incoming"; incoming = "${cfg.root}/incoming";
globalKeterConfigFile = pkgs.writeTextFile { globalKeterConfigFile = pkgs.writeTextFile {
name = "keter-config.yml"; name = "keter-config.yml";
text = (lib.generators.toYAML { } (cfg.globalKeterConfig // { root = cfg.keterRoot; })); text = (lib.generators.toYAML { } (cfg.globalKeterConfig // { root = cfg.root; }));
}; };
# If things are expected to change often, put it in the bundle! # If things are expected to change often, put it in the bundle!
@ -122,7 +151,7 @@ Keep an old app running and swap the ports when the new one is booted.
script = '' script = ''
set -xe set -xe
mkdir -p ${incoming} mkdir -p ${incoming}
{ tail -F ${cfg.keterRoot}/log/keter/current.log -n 0 & ${cfg.keterPackage}/bin/keter ${globalKeterConfigFile}; } ${lib.getExe cfg.package} ${globalKeterConfigFile};
''; '';
wantedBy = [ "multi-user.target" "nginx.service" ]; wantedBy = [ "multi-user.target" "nginx.service" ];

View File

@ -14,6 +14,7 @@ in
enable = true; enable = true;
globalKeterConfig = { globalKeterConfig = {
cli-port = 123; # just adding this to test the freeform
listeners = [{ listeners = [{
host = "*4"; host = "*4";
inherit port; inherit port;