···7 pkg = if config.hardware.sane.snapshot
8 then pkgs.sane-backends-git
9 else pkgs.sane-backends;
10+11+ sanedConf = pkgs.writeTextFile {
12+ name = "saned.conf";
13+ destination = "/etc/sane.d/saned.conf";
14+ text = ''
15+ localhost
16+ ${config.services.saned.extraConfig}
17+ '';
18+ };
19+20+ env = {
21+ SANE_CONFIG_DIR = config.hardware.sane.configDir;
22+ LD_LIBRARY_PATH = [ "${saneConfig}/lib/sane" ];
23+ };
24+25+ backends = [ pkg ] ++ optional config.services.saned.enable sanedConf ++ config.hardware.sane.extraBackends;
26 saneConfig = pkgs.mkSaneConfig { paths = backends; };
27+28+ enabled = config.hardware.sane.enable || config.services.saned.enable;
2930in
31···6869 hardware.sane.configDir = mkOption {
70 type = types.string;
71+ internal = true;
72 description = "The value of SANE_CONFIG_DIR.";
73 };
7475+ services.saned.enable = mkOption {
76+ type = types.bool;
77+ default = false;
78+ description = ''
79+ Enable saned network daemon for remote connection to scanners.
80+81+ saned would be runned from <literal>scanner</literal> user; to allow
82+ access to hardware that doesn't have <literal>scanner</literal> group
83+ you should add needed groups to this user.
84+ '';
85+ };
86+87+ services.saned.extraConfig = mkOption {
88+ type = types.lines;
89+ default = "";
90+ example = "192.168.0.0/24";
91+ description = ''
92+ Extra saned configuration lines.
93+ '';
94+ };
95+96 };
979899 ###### implementation
100101+ config = mkMerge [
102+ (mkIf enabled {
103+ hardware.sane.configDir = mkDefault "${saneConfig}/etc/sane.d";
104+105+ environment.systemPackages = backends;
106+ environment.sessionVariables = env;
107+ services.udev.packages = backends;
108109+ users.extraGroups."scanner".gid = config.ids.gids.scanner;
110+ })
111112+ (mkIf config.services.saned.enable {
113+ networking.firewall.connectionTrackingModules = [ "sane" ];
0000114115+ systemd.services."saned@" = {
116+ description = "Scanner Service";
117+ environment = mapAttrs (name: val: toString val) env;
118+ serviceConfig = {
119+ User = "scanner";
120+ Group = "scanner";
121+ ExecStart = "${pkg}/bin/saned";
122+ };
123+ };
124125+ systemd.sockets.saned = {
126+ description = "saned incoming socket";
127+ wantedBy = [ "sockets.target" ];
128+ listenStreams = [ "0.0.0.0:6566" "[::]:6566" ];
129+ socketConfig = {
130+ # saned needs to distinguish between IPv4 and IPv6 to open matching data sockets.
131+ BindIPv6Only = "ipv6-only";
132+ Accept = true;
133+ MaxConnections = 1;
134+ };
135+ };
136+137+ users.extraUsers."scanner" = {
138+ uid = config.ids.uids.scanner;
139+ group = "scanner";
140+ };
141+ })
142+ ];
143144}
+9-8
pkgs/applications/graphics/sane/config.nix
···45with stdenv.lib;
6let installSanePath = path: ''
7- if test -e "${path}/lib/sane"; then
8 find "${path}/lib/sane" -maxdepth 1 -not -type d | while read backend; do
9- ln -s $backend $out/lib/sane/$(basename $backend)
10 done
11 fi
1213- if test -e "${path}/etc/sane.d"; then
14 find "${path}/etc/sane.d" -maxdepth 1 -not -type d | while read conf; do
15- if test $(basename $conf) = "dll.conf"; then
16- cat $conf >> $out/etc/sane.d/dll.conf
017 else
18- ln -s $conf $out/etc/sane.d/$(basename $conf)
19 fi
20 done
21 fi
2223- if test -e "${path}/etc/sane.d/dll.d"; then
24 find "${path}/etc/sane.d/dll.d" -maxdepth 1 -not -type d | while read conf; do
25- ln -s $conf $out/etc/sane.d/dll.d/$(basename $conf)
26 done
27 fi
28 '';
···45with stdenv.lib;
6let installSanePath = path: ''
7+ if [ -e "${path}/lib/sane" ]; then
8 find "${path}/lib/sane" -maxdepth 1 -not -type d | while read backend; do
9+ ln -s "$backend" "$out/lib/sane/$(basename "$backend")"
10 done
11 fi
1213+ if [ -e "${path}/etc/sane.d" ]; then
14 find "${path}/etc/sane.d" -maxdepth 1 -not -type d | while read conf; do
15+ name="$(basename $conf)"
16+ if [ "$name" = "dll.conf" ] || [ "$name" = "saned.conf" ]; then
17+ cat "$conf" >> "$out/etc/sane.d/$name"
18 else
19+ ln -s "$conf" "$out/etc/sane.d/$name"
20 fi
21 done
22 fi
2324+ if [ -e "${path}/etc/sane.d/dll.d" ]; then
25 find "${path}/etc/sane.d/dll.d" -maxdepth 1 -not -type d | while read conf; do
26+ ln -s "$conf" "$out/etc/sane.d/dll.d/$(basename $conf)"
27 done
28 fi
29 '';