Created
June 28, 2023 05:21
-
-
Save DDoSolitary/3b95129c1438f173b558aa053b1435dc to your computer and use it in GitHub Desktop.
NixOS module for automatic authentication of BUAA campus network
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ config, lib, pkgs, ... }: | |
let beihanglogin = with pkgs; stdenv.mkDerivation rec { | |
pname = "beihanglogin"; | |
version = "unstable-2022-03-11"; | |
src = fetchFromGitHub { | |
owner = "buaahub"; | |
repo = "BeihangLogin"; | |
rev = "5aff7091e967df8c3a6648df9c6c3bc6357b051b"; | |
sha256 = "tbQ5JRcPQlebygWbJpaFY2HKcS7j4tPrdCXa/zEvLWg="; | |
}; | |
buildInputs = [ makeWrapper ]; | |
patches = [ | |
(fetchpatch { | |
url = "https://github.com/buaahub/BeihangLogin/pull/1.patch"; | |
sha256 = "1TOjhiTjGd2jPxbB8ybnfjP6suakyVOWALjmn1XrxRU="; | |
}) | |
(fetchpatch { | |
url = "https://github.com/buaahub/BeihangLogin/pull/2.patch"; | |
sha256 = "kEOxNg2m+cF98F/xpl5ibCV5kkAUbAVVJEX/HItMJCw="; | |
}) | |
(fetchpatch { | |
url = "https://github.com/buaahub/BeihangLogin/pull/3.patch"; | |
sha256 = "c45SbjDhLONvMCXtKh6mvbZIET3zowZ6pmm4x6KCqN0="; | |
}) | |
]; | |
installPhase = '' | |
install -Dm755 login-v2.sh $out/bin/login-v2.sh | |
install -Dm755 try-connect-v2.sh $out/bin/try-connect-v2.sh | |
substituteInPlace $out/bin/try-connect-v2.sh \ | |
--replace ./login-v2.sh $out/bin/login-v2.sh | |
wrapProgram $out/bin/login-v2.sh \ | |
--prefix PATH : ${lib.makeBinPath [ curl openssl ]} | |
wrapProgram $out/bin/try-connect-v2.sh \ | |
--prefix PATH : ${lib.makeBinPath [ curl ]} | |
''; | |
}; | |
in { | |
systemd.timers.beihanglogin = { | |
requires = [ "network-online.target" ]; | |
after = [ "network-online.target" ]; | |
wantedBy = [ "timers.target" ]; | |
timerConfig = { | |
OnActiveSec = 10; | |
OnUnitActiveSec = 60; | |
}; | |
}; | |
systemd.services.beihanglogin = { | |
path = [ beihanglogin pkgs.iputils ]; | |
script = '' | |
try-connect-v2.sh /etc/beihanglogin/account || true | |
if ! ping -c 1 2400:3200::1; then | |
systemctl restart systemd-networkd | |
fi | |
''; | |
serviceConfig = { | |
Type = "exec"; | |
SuccessExitStatus = 1; | |
}; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment