mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-13 13:15:30 +03:00
sane service: add saned support
This commit is contained in:
parent
4111710b8e
commit
65f9341370
3 changed files with 88 additions and 20 deletions
|
@ -84,7 +84,7 @@
|
||||||
spamd = 56;
|
spamd = 56;
|
||||||
#networkmanager = 57; # unused
|
#networkmanager = 57; # unused
|
||||||
nslcd = 58;
|
nslcd = 58;
|
||||||
#scanner = 59; # unused
|
scanner = 59;
|
||||||
nginx = 60;
|
nginx = 60;
|
||||||
chrony = 61;
|
chrony = 61;
|
||||||
#systemd-journal = 62; # unused
|
#systemd-journal = 62; # unused
|
||||||
|
|
|
@ -7,9 +7,26 @@ let
|
||||||
pkg = if config.hardware.sane.snapshot
|
pkg = if config.hardware.sane.snapshot
|
||||||
then pkgs.sane-backends-git
|
then pkgs.sane-backends-git
|
||||||
else pkgs.sane-backends;
|
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; };
|
saneConfig = pkgs.mkSaneConfig { paths = backends; };
|
||||||
|
|
||||||
|
enabled = config.hardware.sane.enable || config.services.saned.enable;
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -51,27 +68,77 @@ in
|
||||||
|
|
||||||
hardware.sane.configDir = mkOption {
|
hardware.sane.configDir = mkOption {
|
||||||
type = types.string;
|
type = types.string;
|
||||||
|
internal = true;
|
||||||
description = "The value of SANE_CONFIG_DIR.";
|
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
|
###### 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;
|
users.extraGroups."scanner".gid = config.ids.gids.scanner;
|
||||||
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;
|
(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";
|
||||||
|
};
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,25 +4,26 @@
|
||||||
|
|
||||||
with stdenv.lib;
|
with stdenv.lib;
|
||||||
let installSanePath = path: ''
|
let installSanePath = path: ''
|
||||||
if test -e "${path}/lib/sane"; then
|
if [ -e "${path}/lib/sane" ]; then
|
||||||
find "${path}/lib/sane" -maxdepth 1 -not -type d | while read backend; do
|
find "${path}/lib/sane" -maxdepth 1 -not -type d | while read backend; do
|
||||||
ln -s $backend $out/lib/sane/$(basename $backend)
|
ln -s "$backend" "$out/lib/sane/$(basename "$backend")"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test -e "${path}/etc/sane.d"; then
|
if [ -e "${path}/etc/sane.d" ]; then
|
||||||
find "${path}/etc/sane.d" -maxdepth 1 -not -type d | while read conf; do
|
find "${path}/etc/sane.d" -maxdepth 1 -not -type d | while read conf; do
|
||||||
if test $(basename $conf) = "dll.conf"; then
|
name="$(basename $conf)"
|
||||||
cat $conf >> $out/etc/sane.d/dll.conf
|
if [ "$name" = "dll.conf" ] || [ "$name" = "saned.conf" ]; then
|
||||||
|
cat "$conf" >> "$out/etc/sane.d/$name"
|
||||||
else
|
else
|
||||||
ln -s $conf $out/etc/sane.d/$(basename $conf)
|
ln -s "$conf" "$out/etc/sane.d/$name"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test -e "${path}/etc/sane.d/dll.d"; then
|
if [ -e "${path}/etc/sane.d/dll.d" ]; then
|
||||||
find "${path}/etc/sane.d/dll.d" -maxdepth 1 -not -type d | while read conf; do
|
find "${path}/etc/sane.d/dll.d" -maxdepth 1 -not -type d | while read conf; do
|
||||||
ln -s $conf $out/etc/sane.d/dll.d/$(basename $conf)
|
ln -s "$conf" "$out/etc/sane.d/dll.d/$(basename $conf)"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue