{ config, lib, pkgs, ... }: { options = { services.smart-ipv6-rotator = { enable = lib.mkOption { type = lib.types.bool; default = false; description = "Enable smart-ipv6-rotator service"; }; ipv6range = lib.mkOption { type = lib.types.str; default = ""; description = "IPv6 range to rotate (e.g. 2407:7000:9827:4100::/64)"; }; rev = lib.mkOption { type = lib.types.str; default = "master"; description = "git rev (branch/commit/tag) for the upstream repo"; }; sha256 = lib.mkOption { type = lib.types.str; default = "0000000000000000000000000000000000000000000000000000"; description = "sha256 for fetchFromGitHub (replace after first build)"; }; }; }; config = lib.mkIf config.services.smart-ipv6-rotator.enable (let rev = config.services.smart-ipv6-rotator.rev; sha256 = config.services.smart-ipv6-rotator.sha256; src = pkgs.fetchFromGitHub { owner = "iv-org"; repo = "smart-ipv6-rotator"; inherit rev sha256; }; pythonEnv = pkgs.python3.withPackages (ps: with ps; [ requests pyroute2 ]); rotatorPkg = pkgs.runCommand "smart-ipv6-rotator" { inherit src; } '' mkdir -p $out/bin cat > $out/bin/smart-ipv6-rotator <<'EOF' #!${pkgs.stdenv.shell} exec ${pythonEnv}/bin/python3 ${src}/smart-ipv6-rotator.py "$@" EOF chmod +x $out/bin/smart-ipv6-rotator ''; in { environment.systemPackages = [ rotatorPkg ]; systemd.services.smart-ipv6-rotator = { description = "Smart IPv6 Rotator (oneshot)"; wantedBy = [ "multi-user.target" ]; serviceConfig = { Type = "oneshot"; ExecStart = "${rotatorPkg}/bin/smart-ipv6-rotator run --cron --ipv6range=${config.services.smart-ipv6-rotator.ipv6range} --services google"; }; }; systemd.timers.smart-ipv6-rotator = { description = "Run smart-ipv6-rotator twice a day"; wantedBy = [ "timers.target" ]; timerConfig = { OnBootSec = "30s"; OnUnitActiveSec = "12h"; }; unitConfig = { Unit = "smart-ipv6-rotator.service"; }; }; }); }