2019-10-14 11:15:32 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
with import <stockholm/lib>;
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.lass.browser;
|
|
|
|
|
|
|
|
browserScripts = {
|
2021-06-05 12:51:50 +00:00
|
|
|
brave = "${pkgs.brave}/bin/brave";
|
|
|
|
chrome = "${pkgs.google-chrome}/bin/chrome";
|
|
|
|
chromium = "${pkgs.ungoogled-chromium}/bin/chromium";
|
2019-10-14 11:15:32 +00:00
|
|
|
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)
|
2021-06-05 12:51:50 +00:00
|
|
|
(filter (x: ! x.value.hidden)
|
2019-10-14 11:15:32 +00:00
|
|
|
(mapAttrsToList (name: value: { inherit name value; })
|
2021-06-05 12:51:50 +00:00
|
|
|
cfg.config));
|
2019-10-14 11:15:32 +00:00
|
|
|
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;
|
2019-10-16 09:52:05 +00:00
|
|
|
in pkgs.writeScriptBin "browser-select" ''
|
2019-10-14 11:15:32 +00:00
|
|
|
${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;
|
|
|
|
};
|
2021-06-05 12:51:50 +00:00
|
|
|
hidden = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
};
|
2019-10-14 11:15:32 +00:00
|
|
|
precedence = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 0;
|
|
|
|
};
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = config._module.args.name;
|
|
|
|
};
|
|
|
|
browser = mkOption {
|
|
|
|
type = types.enum (attrNames browserScripts);
|
2021-06-05 12:51:50 +00:00
|
|
|
default = "brave";
|
2019-10-14 11:15:32 +00:00
|
|
|
};
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
}
|