summaryrefslogtreecommitdiffstats
path: root/tv/3modules
diff options
context:
space:
mode:
Diffstat (limited to 'tv/3modules')
-rw-r--r--tv/3modules/umts.nix105
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
+}