stockholm/lass/3modules/umts.nix

113 lines
2.4 KiB
Nix
Raw Normal View History

2016-06-13 11:48:43 +00:00
{ config, lib, pkgs, ... }:
2016-10-20 18:54:38 +00:00
with import <stockholm/lib>;
2016-06-13 11:48:43 +00:00
let
2016-07-05 07:18:16 +00:00
cfg = config.lass.umts;
out = {
options.lass.umts = api;
config = lib.mkIf cfg.enable imp;
};
api = {
enable = mkEnableOption "umts";
modem = mkOption {
type = types.str;
default = "/dev/ttyUSB0";
};
initstrings = mkOption {
type = types.str;
default = ''
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2
'';
};
username = mkOption {
type = types.str;
default = "default";
};
password = mkOption {
type = types.str;
default = "default";
};
pppDefaults = mkOption {
type = types.str;
default = ''
noipdefault
usepeerdns
defaultroute
persist
noauth
'';
};
2016-07-05 07:18:16 +00:00
};
2016-06-13 11:48:43 +00:00
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
2016-07-05 07:18:16 +00:00
trap "systemctl stop umts;trap - INT TERM EXIT;exit" INT TERM EXIT
2016-06-13 11:48:43 +00:00
echo nameserver 8.8.8.8 | tee -a /etc/resolv.conf
journalctl -xfu umts
'';
wvdial-defaults = ''
2017-09-19 18:28:12 +00:00
[Dialer Defaults]
2016-07-05 07:18:16 +00:00
Modem = ${cfg.modem}
${cfg.initstrings}
Modem Type = Analog Modem
2016-06-13 20:58:41 +00:00
Baud = 460800
2016-06-13 11:48:43 +00:00
phone= *99#
2016-07-05 07:18:16 +00:00
Username = ${cfg.username}
Password = ${cfg.password}
2016-06-13 20:58:41 +00:00
Stupid Mode = 1
Idle Seconds = 0
2017-09-19 18:28:12 +00:00
PPPD Path = ${pkgs.ppp}/bin/pppd
2016-06-13 11:48:43 +00:00
'';
2016-07-05 07:18:16 +00:00
imp = {
2016-06-13 11:48:43 +00:00
environment.shellAliases = {
umts = "sudo ${umts-bin}/bin/umts";
};
2017-09-19 18:28:12 +00:00
environment.systemPackages = [
pkgs.ppp
];
2016-06-13 11:48:43 +00:00
security.sudo.extraConfig = ''
lass ALL= (root) NOPASSWD: ${umts-bin}/bin/umts
'';
environment.etc = [
{
source = pkgs.writeText "wvdial.conf" wvdial-defaults;
target = "wvdial.conf";
}
{
source = pkgs.writeText "wvdial" cfg.pppDefaults;
target = "ppp/peers/wvdial";
}
];
2016-06-13 11:48:43 +00:00
systemd.services.umts = {
description = "UMTS wvdial Service";
serviceConfig = {
Type = "simple";
Restart = "always";
RestartSec = "10s";
ExecStart = "${wvdial}/bin/wvdial -n";
};
};
};
2016-07-05 07:18:16 +00:00
in out