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; [
|
|
|
|
go
|
|
|
|
];
|
|
|
|
|
|
|
|
environment = {
|
|
|
|
PORT = cfg.port;
|
|
|
|
REDIS_KEY_PREFIX = cfg.redisKeyPrefix;
|
|
|
|
};
|
|
|
|
|
|
|
|
restartIfChanged = true;
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
User = "go";
|
|
|
|
Restart = "always";
|
|
|
|
ExecStart = "${pkgs.go}/bin/go";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
in out
|