sane service: add saned support
This commit is contained in:
@@ -7,9 +7,26 @@ let
|
||||
pkg = if config.hardware.sane.snapshot
|
||||
then pkgs.sane-backends-git
|
||||
else pkgs.sane-backends;
|
||||
backends = [ pkg ] ++ config.hardware.sane.extraBackends;
|
||||
|
||||
sanedConf = pkgs.writeTextFile {
|
||||
name = "saned.conf";
|
||||
destination = "/etc/sane.d/saned.conf";
|
||||
text = ''
|
||||
localhost
|
||||
${config.services.saned.extraConfig}
|
||||
'';
|
||||
};
|
||||
|
||||
env = {
|
||||
SANE_CONFIG_DIR = config.hardware.sane.configDir;
|
||||
LD_LIBRARY_PATH = [ "${saneConfig}/lib/sane" ];
|
||||
};
|
||||
|
||||
backends = [ pkg ] ++ optional config.services.saned.enable sanedConf ++ config.hardware.sane.extraBackends;
|
||||
saneConfig = pkgs.mkSaneConfig { paths = backends; };
|
||||
|
||||
enabled = config.hardware.sane.enable || config.services.saned.enable;
|
||||
|
||||
in
|
||||
|
||||
{
|
||||
@@ -51,27 +68,77 @@ in
|
||||
|
||||
hardware.sane.configDir = mkOption {
|
||||
type = types.string;
|
||||
internal = true;
|
||||
description = "The value of SANE_CONFIG_DIR.";
|
||||
};
|
||||
|
||||
services.saned.enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Enable saned network daemon for remote connection to scanners.
|
||||
|
||||
saned would be runned from <literal>scanner</literal> user; to allow
|
||||
access to hardware that doesn't have <literal>scanner</literal> group
|
||||
you should add needed groups to this user.
|
||||
'';
|
||||
};
|
||||
|
||||
services.saned.extraConfig = mkOption {
|
||||
type = types.lines;
|
||||
default = "";
|
||||
example = "192.168.0.0/24";
|
||||
description = ''
|
||||
Extra saned configuration lines.
|
||||
'';
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
###### implementation
|
||||
|
||||
config = mkIf config.hardware.sane.enable {
|
||||
config = mkMerge [
|
||||
(mkIf enabled {
|
||||
hardware.sane.configDir = mkDefault "${saneConfig}/etc/sane.d";
|
||||
|
||||
hardware.sane.configDir = mkDefault "${saneConfig}/etc/sane.d";
|
||||
environment.systemPackages = backends;
|
||||
environment.sessionVariables = env;
|
||||
services.udev.packages = backends;
|
||||
|
||||
environment.systemPackages = backends;
|
||||
environment.sessionVariables = {
|
||||
SANE_CONFIG_DIR = config.hardware.sane.configDir;
|
||||
LD_LIBRARY_PATH = [ "${saneConfig}/lib/sane" ];
|
||||
};
|
||||
services.udev.packages = backends;
|
||||
users.extraGroups."scanner".gid = config.ids.gids.scanner;
|
||||
})
|
||||
|
||||
users.extraGroups."scanner".gid = config.ids.gids.scanner;
|
||||
(mkIf config.services.saned.enable {
|
||||
networking.firewall.connectionTrackingModules = [ "sane" ];
|
||||
|
||||
};
|
||||
systemd.services."saned@" = {
|
||||
description = "Scanner Service";
|
||||
environment = mapAttrs (name: val: toString val) env;
|
||||
serviceConfig = {
|
||||
User = "scanner";
|
||||
Group = "scanner";
|
||||
ExecStart = "${pkg}/bin/saned";
|
||||
};
|
||||
};
|
||||
|
||||
systemd.sockets.saned = {
|
||||
description = "saned incoming socket";
|
||||
wantedBy = [ "sockets.target" ];
|
||||
listenStreams = [ "0.0.0.0:6566" "[::]:6566" ];
|
||||
socketConfig = {
|
||||
# saned needs to distinguish between IPv4 and IPv6 to open matching data sockets.
|
||||
BindIPv6Only = "ipv6-only";
|
||||
Accept = true;
|
||||
MaxConnections = 1;
|
||||
};
|
||||
};
|
||||
|
||||
users.extraUsers."scanner" = {
|
||||
uid = config.ids.uids.scanner;
|
||||
group = "scanner";
|
||||
};
|
||||
})
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user