stockholm/lass/2configs/browsers.nix

93 lines
2.3 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
with config.krebs.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;
browser-select = pkgs.writeScriptBin "browser-select" ''
BROWSER=$(echo -e "${concatStringsSep "\\n" (attrNames config.lass.browser.paths)}" | ${pkgs.dmenu}/bin/dmenu)
case $BROWSER in
${concatMapStringsSep "\n" (n: ''
${n})
export BIN=${config.lass.browser.paths.${n}}/bin/${n}
;;
'') (attrNames config.lass.browser.paths)}
esac
$BIN "$@"
'';
createChromiumUser = name: extraGroups:
let
bin = pkgs.writeScriptBin name ''
/var/setuid-wrappers/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
};
lass.browser.paths.${name} = bin;
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
createFirefoxUser = name: extraGroups:
let
bin = pkgs.writeScriptBin name ''
/var/setuid-wrappers/sudo -u ${name} -i ${pkgs.firefox}/bin/firefox $@
'';
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;
};
lass.browser.paths.${name} = bin;
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
];
2015-08-28 14:31:05 +00:00
imports = [
{
options.lass.browser.select = mkOption {
type = types.path;
};
options.lass.browser.paths = mkOption {
type = with types; attrsOf path;
};
}
( createFirefoxUser "ff" [ "audio" ] )
( createChromiumUser "cr" [ "video" "audio" ] )
( createChromiumUser "wk" [ "video" "audio" ] )
( createChromiumUser "fb" [ "video" "audio" ] )
( createChromiumUser "gm" [ "video" "audio" ] )
( createChromiumUser "com" [ "video" "audio" ] )
2015-07-16 13:51:01 +00:00
];
}