7 cfg = config.services.honk;
9 honk-initdb-script = cfg: pkgs.writeShellApplication {
10 name = "honk-initdb-script";
12 runtimeInputs = with pkgs; [ coreutils ];
15 PW=$(cat "$CREDENTIALS_DIRECTORY/honk_passwordFile")
17 echo -e "${cfg.username}\n''$PW\n${cfg.host}:${toString cfg.port}\n${cfg.servername}" | ${lib.getExe cfg.package} -datadir "$STATE_DIRECTORY" init
24 enable = lib.mkEnableOption "the Honk server";
25 package = lib.mkPackageOption pkgs "honk" { };
28 default = "127.0.0.1";
30 The host name or IP address the server should listen to.
38 The port the server should listen to.
40 type = lib.types.port;
43 username = lib.mkOption {
45 The admin account username.
50 passwordFile = lib.mkOption {
52 Password for admin account.
53 NOTE: Should be string not a store path, to prevent the password from being world readable
55 type = lib.types.path;
58 servername = lib.mkOption {
65 extraJS = lib.mkOption {
68 An extra JavaScript file to be loaded by the client.
70 type = lib.types.nullOr lib.types.path;
73 extraCSS = lib.mkOption {
76 An extra CSS file to be loaded by the client.
78 type = lib.types.nullOr lib.types.path;
83 config = lib.mkIf cfg.enable {
86 assertion = cfg.username or "" != "";
88 You have to define a username for Honk (`services.honk.username`).
92 assertion = cfg.servername or "" != "";
94 You have to define a servername for Honk (`services.honk.servername`).
99 systemd.services.honk-initdb = {
100 description = "Honk server database setup";
101 requiredBy = [ "honk.service" ];
102 before = [ "honk.service" ];
106 "honk_passwordFile:${cfg.passwordFile}"
109 StateDirectory = "honk";
111 RemainAfterExit = true;
112 ExecStart = lib.getExe (honk-initdb-script cfg);
117 ConditionPathExists = [
118 # Skip this service if the database already exists
124 systemd.services.honk = {
125 description = "Honk server";
126 wantedBy = [ "multi-user.target" ];
127 after = [ "network.target" ];
128 bindsTo = [ "honk-initdb.service" ];
130 mkdir -p $STATE_DIRECTORY/views
131 ${lib.optionalString (cfg.extraJS != null) "ln -fs ${cfg.extraJS} $STATE_DIRECTORY/views/local.js"}
132 ${lib.optionalString (cfg.extraCSS != null) "ln -fs ${cfg.extraCSS} $STATE_DIRECTORY/views/local.css"}
133 ${lib.getExe cfg.package} -datadir $STATE_DIRECTORY -viewdir ${cfg.package}/share/honk backup $STATE_DIRECTORY/backup
134 ${lib.getExe cfg.package} -datadir $STATE_DIRECTORY -viewdir ${cfg.package}/share/honk upgrade
135 ${lib.getExe cfg.package} -datadir $STATE_DIRECTORY -viewdir ${cfg.package}/share/honk cleanup
139 ${lib.getExe cfg.package} -datadir $STATE_DIRECTORY -viewdir ${cfg.package}/share/honk
141 StateDirectory = "honk";
144 Restart = "on-failure";
150 maintainers = with lib.maintainers; [ drupol ];