summaryrefslogtreecommitdiffstats
path: root/lass/3modules
diff options
context:
space:
mode:
Diffstat (limited to 'lass/3modules')
-rw-r--r--lass/3modules/autowifi.nix38
-rw-r--r--lass/3modules/browsers.nix87
-rw-r--r--lass/3modules/default.nix2
3 files changed, 127 insertions, 0 deletions
diff --git a/lass/3modules/autowifi.nix b/lass/3modules/autowifi.nix
new file mode 100644
index 000000000..9aa1a2d28
--- /dev/null
+++ b/lass/3modules/autowifi.nix
@@ -0,0 +1,38 @@
+{ config, lib, pkgs, ... }:
+with import <stockholm/lib>;
+let
+
+ cfg = config.lass.autowifi;
+
+in {
+ options.lass.autowifi = {
+ enable = mkEnableOption "automatic wifi connector";
+ knownWifisFile = mkOption {
+ type = types.str;
+ default = "/etc/wifis";
+ };
+ enablePrisonBreak = mkOption {
+ type = types.bool;
+ default = false;
+ };
+ };
+
+ config = lib.mkIf cfg.enable {
+ systemd.services.autowifi = {
+ description = "Automatic wifi connector";
+ wantedBy = [ "multi-user.target" ];
+ path = [ pkgs.networkmanager ];
+ serviceConfig = {
+ Type = "simple";
+ Restart = "always";
+ RestartSec = "10s";
+ ExecStart = "${autowifi}/bin/autowifi";
+ };
+ };
+
+ networking.networkmanager.dispatcherScripts = mkIf cfg.enablePrisonBreak [
+ { source = "${pkgs.callPackage <stockholm/makefu/5pkgs/prison-break}/bin/prison-break"; }
+ ];
+ };
+}
+
diff --git a/lass/3modules/browsers.nix b/lass/3modules/browsers.nix
new file mode 100644
index 000000000..0c77d4da8
--- /dev/null
+++ b/lass/3modules/browsers.nix
@@ -0,0 +1,87 @@
+{ config, lib, pkgs, ... }:
+with import <stockholm/lib>;
+let
+
+ cfg = config.lass.browser;
+
+ browserScripts = {
+ chromium = "${pkgs.chromium}/bin/chromium";
+ firefox = "${pkgs.firefox.override {
+ extraNativeMessagingHosts = [ pkgs.tridactyl-native ];
+ }}/bin/firefox";
+ qutebrowser = "${pkgs.qutebrowser}/bin/qutebrowser";
+ };
+
+ browser-select = let
+ sortedPaths = sort (a: b: a.value.precedence > b.value.precedence)
+ (mapAttrsToList (name: value: { inherit name value; })
+ cfg.config);
+ in if (lib.length sortedPaths) > 1 then
+ pkgs.writeScriptBin "browser-select" ''
+ BROWSER=$(echo -e "${concatStringsSep "\\n" (map (getAttr "name") sortedPaths)}" | ${pkgs.dmenu}/bin/dmenu)
+ case $BROWSER in
+ ${concatMapStringsSep "\n" (n: ''
+ ${n.name})
+ export BIN=${config.lass.xjail-bins.${n.name}}/bin/${n.name}
+ ;;
+ '') (sortedPaths)}
+ esac
+ $BIN "$@"
+ ''
+ else
+ let
+ name = (lib.head sortedPaths).name;
+ in pkgs.writeScriptBin "browser-select" ''
+ ${config.lass.xjail-bins.${name}}/bin/${name} "$@"
+ ''
+ ;
+
+in {
+ options.lass.browser = {
+ select = mkOption {
+ type = types.path;
+ };
+ config = mkOption {
+ type = types.attrsOf (types.submodule ({ config, ... }: {
+ options = {
+ name = mkOption {
+ type = types.str;
+ default = config._module.args.name;
+ };
+ precedence = mkOption {
+ type = types.int;
+ default = 0;
+ };
+ user = mkOption {
+ type = types.str;
+ default = config._module.args.name;
+ };
+ browser = mkOption {
+ type = types.enum (attrNames browserScripts);
+ default = "chromium";
+ };
+ groups = mkOption {
+ type = types.listOf types.str;
+ default = [];
+ };
+ };
+ }));
+ default = {};
+ };
+ };
+
+ config = (mkIf (cfg.config != {}) {
+ lass.xjail = mapAttrs' (name: browser:
+ nameValuePair name {
+ script = browserScripts.${browser.browser};
+ groups = browser.groups;
+ }
+ ) cfg.config;
+ environment.systemPackages = (map (browser:
+ config.lass.xjail-bins.${browser.name}
+ ) (attrValues cfg.config)) ++ [
+ browser-select
+ ];
+ lass.browser.select = browser-select;
+ });
+}
diff --git a/lass/3modules/default.nix b/lass/3modules/default.nix
index 613c7c8ac..90dcb9d9c 100644
--- a/lass/3modules/default.nix
+++ b/lass/3modules/default.nix
@@ -14,5 +14,7 @@ _:
./umts.nix
./usershadow.nix
./xjail.nix
+ ./autowifi.nix
+ ./browsers.nix
];
}