Skip to content

Instantly share code, notes, and snippets.

@cmacrae
Last active May 18, 2017 12:38
Show Gist options
  • Save cmacrae/219f16c4eb4493f4c006953ad7f04a45 to your computer and use it in GitHub Desktop.
Save cmacrae/219f16c4eb4493f4c006953ad7f04a45 to your computer and use it in GitHub Desktop.
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.netcat;
makeService = n: {
name = "netcat${toString n}";
value = {
enable = true;
description = "Netcat ${toString n}";
serviceConfig = {
ExecStart = ''
${pkgs.netcat}/bin/nc -l ${toString (config.services.netcat.basePort + n)}
'';
Restart = "on-failure";
};
};
};
in {
options = {
services.netcat = {
enable = mkOption {
type = types.bool;
default = false;
description = "Whether to start some pointless netcat processes";
};
count = mkOption {
type = types.int;
default = 1;
description = "How many pointless netcat processes to start";
};
basePort = mkOption {
type = types.int;
default = 999;
description = "The base port number";
};
};
};
config = mkIf cfg.enable {
systemd.user.services = builtins.listToAttrs (map makeService (lib.range 1 cfg.count));
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment