2016-02-14 12:26:37 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
2016-10-20 18:54:38 +00:00
|
|
|
with import <stockholm/lib>;
|
2016-02-14 12:26:37 +00:00
|
|
|
let
|
|
|
|
cfg = config.krebs.setuid;
|
|
|
|
|
|
|
|
out = {
|
|
|
|
options.krebs.setuid = api;
|
2017-06-24 14:36:37 +00:00
|
|
|
config = mkIf (cfg != {}) imp;
|
2016-02-14 12:26:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
api = mkOption {
|
|
|
|
default = {};
|
|
|
|
type = let
|
|
|
|
# TODO make wrapperDir configurable
|
|
|
|
inherit (config.security) wrapperDir;
|
|
|
|
inherit (config.users) groups users;
|
|
|
|
in types.attrsOf (types.submodule ({ config, ... }: {
|
|
|
|
options = {
|
|
|
|
name = mkOption {
|
|
|
|
type = types.filename;
|
|
|
|
default = config._module.args.name;
|
|
|
|
};
|
2016-06-04 22:31:36 +00:00
|
|
|
envp = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = {};
|
|
|
|
};
|
2016-02-14 12:26:37 +00:00
|
|
|
filename = mkOption {
|
|
|
|
type = mkOptionType {
|
|
|
|
# TODO unyuck string and merge with toC
|
|
|
|
name = "derivation or string";
|
|
|
|
check = x:
|
|
|
|
isDerivation x ||
|
|
|
|
isString x;
|
|
|
|
};
|
|
|
|
apply = toString;
|
|
|
|
};
|
|
|
|
owner = mkOption {
|
|
|
|
default = "root";
|
|
|
|
type = types.enum (attrNames users);
|
|
|
|
};
|
|
|
|
group = mkOption {
|
|
|
|
default = "root";
|
|
|
|
type = types.enum (attrNames groups);
|
|
|
|
};
|
|
|
|
mode = mkOption {
|
|
|
|
default = "4710";
|
|
|
|
type = mkOptionType {
|
|
|
|
# TODO admit symbolic mode
|
|
|
|
name = "octal mode";
|
2017-06-18 13:36:18 +00:00
|
|
|
check = test "[0-7][0-7][0-7][0-7]";
|
2016-02-27 12:10:59 +00:00
|
|
|
merge = mergeOneOption;
|
2016-02-14 12:26:37 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
activate = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
visible = false;
|
|
|
|
readOnly = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
config.activate = let
|
2018-09-15 23:46:46 +00:00
|
|
|
src = pkgs.exec config.name {
|
2016-06-04 22:31:36 +00:00
|
|
|
inherit (config) envp filename;
|
2016-02-14 12:26:37 +00:00
|
|
|
};
|
|
|
|
dst = "${wrapperDir}/${config.name}";
|
|
|
|
in ''
|
|
|
|
cp ${src} ${dst}
|
|
|
|
chown ${config.owner}.${config.group} ${dst}
|
|
|
|
chmod ${config.mode} ${dst}
|
|
|
|
'';
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
imp = {
|
2017-03-02 18:43:10 +00:00
|
|
|
system.activationScripts."krebs.setuid" = stringAfter [ "wrappers" ]
|
2016-02-14 12:26:37 +00:00
|
|
|
(concatMapStringsSep "\n" (getAttr "activate") (attrValues cfg));
|
|
|
|
};
|
|
|
|
|
|
|
|
in out
|