tv umts: cleanup
This commit is contained in:
parent
b091ebbab7
commit
8c23c4d17f
@ -1,17 +1,32 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with import <stockholm/lib>;
|
||||
{ config, lib, pkgs, ... }: let
|
||||
|
||||
let
|
||||
cfg = config.tv.umts;
|
||||
|
||||
out = {
|
||||
options.tv.umts = api;
|
||||
config = lib.mkIf cfg.enable imp;
|
||||
};
|
||||
umts-dial = pkgs.writeDash "umts-dial" ''
|
||||
set -euf
|
||||
${pkgs.systemd}/bin/systemctl start umts
|
||||
trap 'cleanup; trap - EXIT INT TERM' EXIT INT TERM
|
||||
cleanup() {
|
||||
${pkgs.systemd}/bin/systemctl stop umts
|
||||
}
|
||||
echo nameserver 8.8.8.8 >> /etc/resolv.conf
|
||||
${pkgs.systemd}/bin/journalctl -xfu umts
|
||||
'';
|
||||
|
||||
api = {
|
||||
enable = mkEnableOption "umts";
|
||||
# https://github.com/NixOS/nixpkgs/issues/16113
|
||||
wvdial = let
|
||||
nixpkgs-1509 = import (pkgs.fetchFromGitHub {
|
||||
owner = "NixOS"; repo = "nixpkgs-channels";
|
||||
rev = "91371c2bb6e20fc0df7a812332d99c38b21a2bda";
|
||||
sha256 = "1as1i0j9d2n3iap9b471y4x01561r2s3vmjc5281qinirlr4al73";
|
||||
}) {};
|
||||
in
|
||||
nixpkgs-1509.wvdial;
|
||||
|
||||
in {
|
||||
options.tv.umts = {
|
||||
enable = mkEnableOption "tv.umts";
|
||||
modem = mkOption {
|
||||
type = types.str;
|
||||
default = "/dev/ttyUSB0";
|
||||
@ -43,24 +58,10 @@ let
|
||||
};
|
||||
};
|
||||
|
||||
nixpkgs-1509 = import (pkgs.fetchFromGitHub {
|
||||
owner = "NixOS"; repo = "nixpkgs-channels";
|
||||
rev = "91371c2bb6e20fc0df7a812332d99c38b21a2bda";
|
||||
sha256 = "1as1i0j9d2n3iap9b471y4x01561r2s3vmjc5281qinirlr4al73";
|
||||
}) {};
|
||||
|
||||
wvdial = nixpkgs-1509.wvdial; # https://github.com/NixOS/nixpkgs/issues/16113
|
||||
|
||||
umts-bin = pkgs.writeScriptBin "umts" ''
|
||||
#!/bin/sh
|
||||
set -euf
|
||||
systemctl start umts
|
||||
trap "systemctl stop umts;trap - INT TERM EXIT;exit" INT TERM EXIT
|
||||
echo nameserver 8.8.8.8 | tee -a /etc/resolv.conf
|
||||
journalctl -xfu umts
|
||||
'';
|
||||
|
||||
wvdial-defaults = ''
|
||||
config = lib.mkIf cfg.enable {
|
||||
environment.etc = {
|
||||
"ppp/peers/wvdial".text = cfg.pppDefaults;
|
||||
"wvdial.conf".text = ''
|
||||
[Dialer Defaults]
|
||||
Modem = ${cfg.modem}
|
||||
${cfg.initstrings}
|
||||
@ -73,31 +74,18 @@ let
|
||||
Idle Seconds = 0
|
||||
PPPD Path = ${pkgs.ppp}/bin/pppd
|
||||
'';
|
||||
|
||||
imp = {
|
||||
environment.shellAliases = {
|
||||
umts = "sudo ${umts-bin}/bin/umts";
|
||||
};
|
||||
|
||||
environment.systemPackages = [
|
||||
pkgs.ppp
|
||||
krebs.per-user.tv.packages = [
|
||||
(pkgs.writeDashBin "umts" ''
|
||||
exec sudo ${umts-dial}
|
||||
'')
|
||||
];
|
||||
|
||||
security.sudo.extraConfig = ''
|
||||
tv ALL= (root) NOPASSWD: ${umts-bin}/bin/umts
|
||||
tv ALL= (root) NOPASSWD: ${umts-dial}
|
||||
'';
|
||||
|
||||
environment.etc = [
|
||||
{
|
||||
source = pkgs.writeText "wvdial.conf" wvdial-defaults;
|
||||
target = "wvdial.conf";
|
||||
}
|
||||
{
|
||||
source = pkgs.writeText "wvdial" cfg.pppDefaults;
|
||||
target = "ppp/peers/wvdial";
|
||||
}
|
||||
];
|
||||
|
||||
systemd.services.umts = {
|
||||
description = "UMTS wvdial Service";
|
||||
serviceConfig = {
|
||||
@ -108,5 +96,4 @@ let
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
in out
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user