nixos/services.usbguard: remove `with lib;`

Changed files
+32 -34
nixos
modules
services
security
+32 -34
nixos/modules/services/security/usbguard.nix
···
pkgs,
...
}:
-
-
with lib;
let
cfg = config.services.usbguard;
# valid policy options
policy = (
-
types.enum [
"allow"
"block"
"reject"
···
PresentDevicePolicy=${cfg.presentDevicePolicy}
PresentControllerPolicy=${cfg.presentControllerPolicy}
InsertedDevicePolicy=${cfg.insertedDevicePolicy}
-
RestoreControllerDeviceState=${boolToString cfg.restoreControllerDeviceState}
# this does not seem useful for endusers to change
DeviceManagerBackend=uevent
-
IPCAllowedUsers=${concatStringsSep " " cfg.IPCAllowedUsers}
-
IPCAllowedGroups=${concatStringsSep " " cfg.IPCAllowedGroups}
IPCAccessControlFiles=/var/lib/usbguard/IPCAccessControl.d/
-
DeviceRulesWithPort=${boolToString cfg.deviceRulesWithPort}
# HACK: that way audit logs still land in the journal
AuditFilePath=/dev/null
'';
···
options = {
services.usbguard = {
-
enable = mkEnableOption "USBGuard daemon";
-
package = mkPackageOption pkgs "usbguard" {
extraDescription = ''
If you do not need the Qt GUI, use `pkgs.usbguard-nox` to save disk space.
'';
};
-
ruleFile = mkOption {
-
type = types.nullOr types.path;
default = "/var/lib/usbguard/rules.conf";
example = "/run/secrets/usbguard-rules";
description = ''
···
'';
};
-
rules = mkOption {
-
type = types.nullOr types.lines;
default = null;
example = ''
allow with-interface equals { 08:*:* }
···
'';
};
-
implicitPolicyTarget = mkOption {
-
type = types.enum [
"allow"
"block"
"reject"
···
'';
};
-
presentDevicePolicy = mkOption {
type = policy;
default = "apply-policy";
description = ''
···
'';
};
-
presentControllerPolicy = mkOption {
type = policy;
default = "keep";
description = ''
···
'';
};
-
insertedDevicePolicy = mkOption {
-
type = types.enum [
"block"
"reject"
"apply-policy"
···
'';
};
-
restoreControllerDeviceState = mkOption {
-
type = types.bool;
default = false;
description = ''
The USBGuard daemon modifies some attributes of controller
···
'';
};
-
IPCAllowedUsers = mkOption {
-
type = types.listOf types.str;
default = [ "root" ];
example = [
"root"
···
'';
};
-
IPCAllowedGroups = mkOption {
-
type = types.listOf types.str;
default = [ ];
example = [ "wheel" ];
description = ''
···
'';
};
-
deviceRulesWithPort = mkOption {
-
type = types.bool;
default = false;
description = ''
Generate device specific rules including the "via-port" attribute.
'';
};
-
dbus.enable = mkEnableOption "USBGuard dbus daemon";
};
};
###### implementation
-
config = mkIf cfg.enable {
environment.systemPackages = [ cfg.package ];
···
};
};
-
usbguard-dbus = mkIf cfg.dbus.enable {
description = "USBGuard D-Bus Service";
wantedBy = [ "multi-user.target" ];
···
groupCheck =
(lib.concatStrings (map (g: "subject.isInGroup(\"${g}\") || ") cfg.IPCAllowedGroups)) + "false";
in
-
optionalString cfg.dbus.enable ''
polkit.addRule(function(action, subject) {
if ((action.id == "org.usbguard.Policy1.listRules" ||
action.id == "org.usbguard.Policy1.appendRule" ||
···
'';
};
imports = [
-
(mkRemovedOptionModule [ "services" "usbguard" "IPCAccessControlFiles" ]
"The usbguard module now hardcodes IPCAccessControlFiles to /var/lib/usbguard/IPCAccessControl.d."
)
-
(mkRemovedOptionModule [
"services"
"usbguard"
"auditFilePath"
] "Removed usbguard module audit log files. Audit logs can be found in the systemd journal.")
-
(mkRenamedOptionModule
[ "services" "usbguard" "implictPolicyTarget" ]
[ "services" "usbguard" "implicitPolicyTarget" ]
)
···
pkgs,
...
}:
let
cfg = config.services.usbguard;
# valid policy options
policy = (
+
lib.types.enum [
"allow"
"block"
"reject"
···
PresentDevicePolicy=${cfg.presentDevicePolicy}
PresentControllerPolicy=${cfg.presentControllerPolicy}
InsertedDevicePolicy=${cfg.insertedDevicePolicy}
+
RestoreControllerDeviceState=${lib.boolToString cfg.restoreControllerDeviceState}
# this does not seem useful for endusers to change
DeviceManagerBackend=uevent
+
IPCAllowedUsers=${lib.concatStringsSep " " cfg.IPCAllowedUsers}
+
IPCAllowedGroups=${lib.concatStringsSep " " cfg.IPCAllowedGroups}
IPCAccessControlFiles=/var/lib/usbguard/IPCAccessControl.d/
+
DeviceRulesWithPort=${lib.boolToString cfg.deviceRulesWithPort}
# HACK: that way audit logs still land in the journal
AuditFilePath=/dev/null
'';
···
options = {
services.usbguard = {
+
enable = lib.mkEnableOption "USBGuard daemon";
+
package = lib.mkPackageOption pkgs "usbguard" {
extraDescription = ''
If you do not need the Qt GUI, use `pkgs.usbguard-nox` to save disk space.
'';
};
+
ruleFile = lib.mkOption {
+
type = lib.types.nullOr lib.types.path;
default = "/var/lib/usbguard/rules.conf";
example = "/run/secrets/usbguard-rules";
description = ''
···
'';
};
+
rules = lib.mkOption {
+
type = lib.types.nullOr lib.types.lines;
default = null;
example = ''
allow with-interface equals { 08:*:* }
···
'';
};
+
implicitPolicyTarget = lib.mkOption {
+
type = lib.types.enum [
"allow"
"block"
"reject"
···
'';
};
+
presentDevicePolicy = lib.mkOption {
type = policy;
default = "apply-policy";
description = ''
···
'';
};
+
presentControllerPolicy = lib.mkOption {
type = policy;
default = "keep";
description = ''
···
'';
};
+
insertedDevicePolicy = lib.mkOption {
+
type = lib.types.enum [
"block"
"reject"
"apply-policy"
···
'';
};
+
restoreControllerDeviceState = lib.mkOption {
+
type = lib.types.bool;
default = false;
description = ''
The USBGuard daemon modifies some attributes of controller
···
'';
};
+
IPCAllowedUsers = lib.mkOption {
+
type = lib.types.listOf lib.types.str;
default = [ "root" ];
example = [
"root"
···
'';
};
+
IPCAllowedGroups = lib.mkOption {
+
type = lib.types.listOf lib.types.str;
default = [ ];
example = [ "wheel" ];
description = ''
···
'';
};
+
deviceRulesWithPort = lib.mkOption {
+
type = lib.types.bool;
default = false;
description = ''
Generate device specific rules including the "via-port" attribute.
'';
};
+
dbus.enable = lib.mkEnableOption "USBGuard dbus daemon";
};
};
###### implementation
+
config = lib.mkIf cfg.enable {
environment.systemPackages = [ cfg.package ];
···
};
};
+
usbguard-dbus = lib.mkIf cfg.dbus.enable {
description = "USBGuard D-Bus Service";
wantedBy = [ "multi-user.target" ];
···
groupCheck =
(lib.concatStrings (map (g: "subject.isInGroup(\"${g}\") || ") cfg.IPCAllowedGroups)) + "false";
in
+
lib.optionalString cfg.dbus.enable ''
polkit.addRule(function(action, subject) {
if ((action.id == "org.usbguard.Policy1.listRules" ||
action.id == "org.usbguard.Policy1.appendRule" ||
···
'';
};
imports = [
+
(lib.mkRemovedOptionModule [ "services" "usbguard" "IPCAccessControlFiles" ]
"The usbguard module now hardcodes IPCAccessControlFiles to /var/lib/usbguard/IPCAccessControl.d."
)
+
(lib.mkRemovedOptionModule [
"services"
"usbguard"
"auditFilePath"
] "Removed usbguard module audit log files. Audit logs can be found in the systemd journal.")
+
(lib.mkRenamedOptionModule
[ "services" "usbguard" "implictPolicyTarget" ]
[ "services" "usbguard" "implicitPolicyTarget" ]
)