diff options
author | tv <tv@krebsco.de> | 2017-10-24 22:48:57 +0200 |
---|---|---|
committer | tv <tv@krebsco.de> | 2017-10-24 23:07:45 +0200 |
commit | 8c23c4d17ff89dbba18ce5ab2b6c8124a87c2c11 (patch) | |
tree | ecafe1e0b116b9f18521f00b6cc3c81906b806d2 /tv | |
parent | b091ebbab79d6780839ced56e3eef28241e6ea4c (diff) |
tv umts: cleanup
Diffstat (limited to 'tv')
-rw-r--r-- | tv/3modules/umts.nix | 105 |
1 files changed, 46 insertions, 59 deletions
diff --git a/tv/3modules/umts.nix b/tv/3modules/umts.nix index ebf4f780f..a60627025 100644 --- a/tv/3modules/umts.nix +++ b/tv/3modules/umts.nix @@ -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,61 +58,34 @@ 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 = '' - [Dialer Defaults] - Modem = ${cfg.modem} - ${cfg.initstrings} - Modem Type = Analog Modem - Baud = 460800 - phone= *99# - Username = ${cfg.username} - Password = ${cfg.password} - Stupid Mode = 1 - Idle Seconds = 0 - PPPD Path = ${pkgs.ppp}/bin/pppd - ''; - - imp = { - environment.shellAliases = { - umts = "sudo ${umts-bin}/bin/umts"; + config = lib.mkIf cfg.enable { + environment.etc = { + "ppp/peers/wvdial".text = cfg.pppDefaults; + "wvdial.conf".text = '' + [Dialer Defaults] + Modem = ${cfg.modem} + ${cfg.initstrings} + Modem Type = Analog Modem + Baud = 460800 + phone= *99# + Username = ${cfg.username} + Password = ${cfg.password} + Stupid Mode = 1 + Idle Seconds = 0 + PPPD Path = ${pkgs.ppp}/bin/pppd + ''; }; - 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 +} |