summaryrefslogtreecommitdiffstats
path: root/lass
diff options
context:
space:
mode:
authorlassulus <lassulus@lassul.us>2019-10-14 13:15:32 +0200
committerlassulus <lassulus@lassul.us>2019-10-14 13:15:32 +0200
commitea2c783e1409ed4861c4373164c62fdba8a5870d (patch)
tree97fd865ca6a52da993631de2af879ed7d51e9d35 /lass
parent2a40b6c342b5b12ebdb45b27eca945b9de730c33 (diff)
l browser: refactor into browsers module
Diffstat (limited to 'lass')
-rw-r--r--lass/2configs/browsers.nix97
-rw-r--r--lass/3modules/browsers.nix87
-rw-r--r--lass/3modules/default.nix1
3 files changed, 93 insertions, 92 deletions
diff --git a/lass/2configs/browsers.nix b/lass/2configs/browsers.nix
index c0085995d..eafab400c 100644
--- a/lass/2configs/browsers.nix
+++ b/lass/2configs/browsers.nix
@@ -1,100 +1,13 @@
{ config, lib, pkgs, ... }:
-
-with import <stockholm/lib>;
-let
-
- mainUser = config.users.extraUsers.mainUser;
-
- browser-select = let
- sortedPaths = sort (a: b: a.value.precedence > b.value.precedence)
- (mapAttrsToList (name: value: { inherit name value; })
- config.lass.browser.paths);
- in 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=${n.value.path}/bin/${n.name}
- ;;
- '') (sortedPaths)}
- esac
- $BIN "$@"
- '';
-
- createUser = script: name: groups: precedence: dpi:
- {
- lass.xjail.${name} = {
- inherit script groups dpi;
- };
- environment.systemPackages = [
- config.lass.xjail-bins.${name}
- (pkgs.writeDashBin "cx-${name}" ''
- DISPLAY=:${toString (genid_uint31 name)} ${pkgs.xclip}/bin/xclip -o | DISPLAY=:0 ${pkgs.xclip}/bin/xclip
- '')
- ];
- lass.browser.paths.${name} = {
- path = config.lass.xjail-bins.${name};
- inherit precedence;
- };
- };
-
- createChromiumUser = name: groups: precedence:
- createUser (pkgs.writeDash name ''
- ${pkgs.chromium}/bin/chromium "$@"
- '') name groups precedence 80;
-
- createFirefoxUser = name: groups: precedence:
- createUser (pkgs.writeDash name ''
- ${pkgs.firefox}/bin/firefox "$@"
- '') name groups precedence 80;
-
- createQuteUser = name: groups: precedence:
- createUser (pkgs.writeDash name ''
- ${pkgs.qutebrowser}/bin/qutebrowser "$@"
- '') name groups precedence 60;
-
-in {
-
- lass.browser.select = browser-select;
-
- environment.systemPackages = [
- browser-select
- ];
-
+{
+ lass.browser.config = {
+ cr = { groups = [ "audio" "video" ]; precedence = 9; };
+ };
programs.chromium = {
enable = true;
extensions = [
"cjpalhdlnbpafiamejdnhcphjbkeiagm" # ublock origin
- "dbepggeogbaibhgnhhndojpepiihcmeb" # vimium
+ "ihlenndgcmojhcghmfjfneahoeklbjjh" #cVim
];
};
-
- imports = [
- {
- options.lass.browser.select = mkOption {
- type = types.path;
- };
- options.lass.browser.paths = mkOption {
- type = types.attrsOf (types.submodule ({
- options = {
- path = mkOption {
- type = types.path;
- };
- precedence = mkOption {
- type = types.int;
- default = 0;
- };
- };
- }));
- };
- }
- ( createFirefoxUser "ff" [ "audio" ] 11 )
- ( createQuteUser "qb" [ "audio" ] 10 )
- ( createChromiumUser "cr" [ "audio" "video" ] 9 )
- ( createChromiumUser "gm" [ "video" "audio" ] 8 )
- ( createChromiumUser "wk" [ "audio" ] 0 )
- ( createChromiumUser "fb" [ "audio" ] 0 )
- ( createChromiumUser "com" [ "audio" ] 0 )
- ( createChromiumUser "fin" [] (-1) )
- ];
}
diff --git a/lass/3modules/browsers.nix b/lass/3modules/browsers.nix
new file mode 100644
index 000000000..ccb108f8a
--- /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-select2" ''
+ ${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 1195cd3d4..90dcb9d9c 100644
--- a/lass/3modules/default.nix
+++ b/lass/3modules/default.nix
@@ -15,5 +15,6 @@ _:
./usershadow.nix
./xjail.nix
./autowifi.nix
+ ./browsers.nix
];
}