stockholm/lass/2configs/browsers.nix

122 lines
3.1 KiB
Nix
Raw Normal View History

2015-08-28 14:31:05 +00:00
{ config, lib, pkgs, ... }:
2015-07-16 13:51:01 +00:00
2016-10-20 18:54:38 +00:00
with import <stockholm/lib>;
2015-07-16 13:51:01 +00:00
let
2016-02-21 23:50:01 +00:00
2015-07-16 13:51:01 +00:00
mainUser = config.users.extraUsers.mainUser;
2017-12-05 19:03:55 +00:00
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: ''
2017-12-05 19:03:55 +00:00
${n.name})
export BIN=${n.value.path}/bin/${n.name}
;;
2017-12-05 19:03:55 +00:00
'') (sortedPaths)}
esac
$BIN "$@"
'';
2017-12-05 19:03:55 +00:00
createChromiumUser = name: extraGroups: precedence:
let
bin = pkgs.writeScriptBin name ''
2017-02-18 19:39:14 +00:00
/var/run/wrappers/bin/sudo -u ${name} -i ${pkgs.chromium}/bin/chromium $@
'';
in {
2015-10-03 12:37:56 +00:00
users.extraUsers.${name} = {
inherit name;
inherit extraGroups;
home = "/home/${name}";
2016-02-21 23:50:01 +00:00
uid = genid name;
2015-10-03 12:37:56 +00:00
useDefaultShell = true;
createHome = true;
2015-08-28 14:31:05 +00:00
};
2018-01-15 23:06:52 +00:00
lass.browser.paths.${name} = {
path = bin;
inherit precedence;
};
2015-08-28 14:31:05 +00:00
security.sudo.extraConfig = ''
${mainUser.name} ALL=(${name}) NOPASSWD: ALL
'';
environment.systemPackages = [
bin
2015-08-28 14:31:05 +00:00
];
};
2015-07-16 13:51:01 +00:00
2017-12-05 19:03:55 +00:00
createFirefoxUser = name: extraGroups: precedence:
let
bin = pkgs.writeScriptBin name ''
2017-12-13 17:26:49 +00:00
/var/run/wrappers/bin/sudo -u ${name} -i ${pkgs.firefox-devedition-bin}/bin/firefox-devedition $@
'';
in {
2015-10-03 12:37:56 +00:00
users.extraUsers.${name} = {
inherit name;
inherit extraGroups;
home = "/home/${name}";
2016-02-21 23:50:01 +00:00
uid = genid name;
2015-10-03 12:37:56 +00:00
useDefaultShell = true;
createHome = true;
};
2017-12-05 19:03:55 +00:00
lass.browser.paths.${name} = {
path = bin;
inherit precedence;
};
security.sudo.extraConfig = ''
${mainUser.name} ALL=(${name}) NOPASSWD: ALL
'';
environment.systemPackages = [
bin
];
};
2015-09-05 10:13:14 +00:00
#TODO: abstract this
2015-07-16 13:51:01 +00:00
in {
lass.browser.select = browser-select;
2015-09-05 10:13:14 +00:00
environment.systemPackages = [
browser-select
2015-09-05 10:13:14 +00:00
];
2018-01-15 23:07:08 +00:00
programs.chromium = {
enable = true;
extensions = [
"cjpalhdlnbpafiamejdnhcphjbkeiagm" # ublock origin
"dbepggeogbaibhgnhhndojpepiihcmeb" # vimium
];
};
2015-08-28 14:31:05 +00:00
imports = [
{
options.lass.browser.select = mkOption {
type = types.path;
};
options.lass.browser.paths = mkOption {
2017-12-05 19:03:55 +00:00
type = types.attrsOf (types.submodule ({
options = {
path = mkOption {
type = types.path;
};
precedence = mkOption {
type = types.int;
default = 0;
};
};
}));
};
}
2017-12-05 19:03:55 +00:00
( createFirefoxUser "ff" [ "audio" ] 10 )
( createChromiumUser "cr" [ "video" "audio" ] 9 )
( createChromiumUser "gm" [ "video" "audio" ] 8 )
2018-01-15 23:07:29 +00:00
( createChromiumUser "wk" [ "video" "audio" ] 0 )
( createChromiumUser "fb" [ "video" "audio" ] 0 )
( createChromiumUser "com" [ "video" "audio" ] 0 )
( createChromiumUser "fin" [] (-1) )
2015-07-16 13:51:01 +00:00
];
}