diff options
Diffstat (limited to 'krebs')
-rw-r--r-- | krebs/3modules/default.nix | 1 | ||||
-rw-r--r-- | krebs/3modules/go.nix | 66 |
2 files changed, 67 insertions, 0 deletions
diff --git a/krebs/3modules/default.nix b/krebs/3modules/default.nix index b4e7f9254..6d62b2e38 100644 --- a/krebs/3modules/default.nix +++ b/krebs/3modules/default.nix @@ -13,6 +13,7 @@ let ./exim-smarthost.nix ./github-hosts-sync.nix ./git.nix + ./go.nix ./iptables.nix ./nginx.nix ./per-user.nix diff --git a/krebs/3modules/go.nix b/krebs/3modules/go.nix new file mode 100644 index 000000000..793d1f60d --- /dev/null +++ b/krebs/3modules/go.nix @@ -0,0 +1,66 @@ +{ config, lib, pkgs, ... }: + +with builtins; +with lib; + +let + cfg = config.krebs.go; + + out = { + options.krebs.go = api; + config = mkIf cfg.enable imp; + }; + + 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 = { + services.redis = { + enable = mkDefault true; + bind = mkDefault "127.0.0.1"; + }; + + users.extraUsers.go = { + name = "go"; + uid = 42774411; #genid go + 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 |