nixos/codimd: add package option, refactor prettyJSON

This adds a `package` option to allow for easier overriding of the used
CodiMD version and `runCommandLocal` with `nativeBuildInputs` is now
used to pretty print the configuration.
This commit is contained in:
WilliButz 2020-11-13 16:14:41 +01:00
parent eb64d1518f
commit 74d354a397
No known key found for this signature in database
GPG Key ID: 92582A10F1179CB2

View File

@ -6,8 +6,10 @@ let
cfg = config.services.codimd;
prettyJSON = conf:
pkgs.runCommand "codimd-config.json" { preferLocalBuild = true; } ''
echo '${builtins.toJSON conf}' | ${pkgs.jq}/bin/jq \
pkgs.runCommandLocal "codimd-config.json" {
nativeBuildInputs = [ pkgs.jq ];
} ''
echo '${builtins.toJSON conf}' | jq \
'{production:del(.[]|nulls)|del(.[][]?|nulls)}' > $out
'';
in
@ -878,7 +880,6 @@ in
};
};
environmentFile = mkOption {
type = with types; nullOr path;
default = null;
@ -908,6 +909,14 @@ in
<literal>CodiMD</literal> is running.
'';
};
package = mkOption {
type = types.package;
default = pkgs.codimd;
description = ''
Package that provides CodiMD.
'';
};
};
config = mkIf cfg.enable {
@ -938,7 +947,7 @@ in
'';
serviceConfig = {
WorkingDirectory = cfg.workDir;
ExecStart = "${pkgs.codimd}/bin/codimd";
ExecStart = "${cfg.package}/bin/codimd";
EnvironmentFile = mkIf (cfg.environmentFile != null) [ cfg.environmentFile ];
Environment = [
"CMD_CONFIG_FILE=${cfg.workDir}/config.json"