stockholm/krebs/3modules/go.nix

66 lines
1.3 KiB
Nix
Raw Normal View History

2015-10-08 23:11:29 +00:00
{ config, lib, pkgs, ... }:
2016-10-20 18:54:38 +00:00
with import <stockholm/lib>;
2015-10-08 23:11:29 +00:00
let
2015-11-13 00:16:15 +00:00
cfg = config.krebs.go;
2015-10-08 23:11:29 +00:00
out = {
2015-11-13 00:16:15 +00:00
options.krebs.go = api;
2016-02-14 15:43:44 +00:00
config = lib.mkIf cfg.enable imp;
2015-10-08 23:11:29 +00:00
};
api = {
enable = mkEnableOption "Enable go url shortener";
port = mkOption {
type = types.str;
default = "1337";
description = "on which port go should run on";
};
redisKeyPrefix = mkOption {
type = types.str;
default = "go:";
description = "change the Redis key prefix which defaults to `go:`";
};
};
imp = {
2015-11-12 23:50:02 +00:00
services.redis = {
enable = mkDefault true;
bind = mkDefault "127.0.0.1";
};
2015-12-26 04:55:13 +00:00
users.extraUsers.go = rec {
2015-10-08 23:11:29 +00:00
name = "go";
2015-12-26 04:55:13 +00:00
uid = genid name;
2015-10-08 23:11:29 +00:00
description = "go url shortener user";
home = "/var/lib/go";
createHome = true;
};
systemd.services.go = {
description = "go url shortener";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
path = with pkgs; [
2016-10-27 12:47:21 +00:00
go-shortener
2015-10-08 23:11:29 +00:00
];
environment = {
PORT = cfg.port;
REDIS_KEY_PREFIX = cfg.redisKeyPrefix;
};
restartIfChanged = true;
serviceConfig = {
User = "go";
Restart = "always";
2016-10-27 12:47:21 +00:00
ExecStart = "${pkgs.go-shortener}/bin/go";
2015-10-08 23:11:29 +00:00
};
};
};
in out