nixos/sane: allow to disable enabled-by-default plugins

use case: disabling v4l plugin because I don't use my webcam as a
scanner.

+21 -4
+11 -1
nixos/modules/services/hardware/sane.nix
··· 32 32 }; 33 33 34 34 backends = [ pkg netConf ] ++ optional config.services.saned.enable sanedConf ++ config.hardware.sane.extraBackends; 35 - saneConfig = pkgs.mkSaneConfig { paths = backends; }; 35 + saneConfig = pkgs.mkSaneConfig { paths = backends; inherit (config.hardware.sane) disabledDefaultBackends; }; 36 36 37 37 enabled = config.hardware.sane.enable || config.services.saned.enable; 38 38 ··· 73 73 </para></note> 74 74 ''; 75 75 example = literalExample "[ pkgs.hplipWithPlugin ]"; 76 + }; 77 + 78 + hardware.sane.disabledDefaultBackends = mkOption { 79 + type = types.listOf types.str; 80 + default = []; 81 + example = [ "v4l" ]; 82 + description = '' 83 + Names of backends which are enabled by default but should be disabled. 84 + See <literal>$SANE_CONFIG_DIR/dll.conf</literal> for the list of possible names. 85 + ''; 76 86 }; 77 87 78 88 hardware.sane.configDir = mkOption {
+10 -3
pkgs/applications/graphics/sane/config.nix
··· 1 1 { lib, stdenv }: 2 2 3 - { paths }: 3 + { paths, disabledDefaultBackends ? [] }: 4 4 5 5 with lib; 6 - let installSanePath = path: '' 6 + let 7 + installSanePath = path: '' 7 8 if [ -e "${path}/lib/sane" ]; then 8 9 find "${path}/lib/sane" -maxdepth 1 -not -type d | while read backend; do 9 10 symlink "$backend" "$out/lib/sane/$(basename "$backend")" ··· 27 28 done 28 29 fi 29 30 ''; 31 + disableBackend = backend: '' 32 + grep -q '${backend}' $out/etc/sane.d/dll.conf || { echo '${backend} is not a default plugin in $SANE_CONFIG_DIR/dll.conf'; exit 1; } 33 + substituteInPlace $out/etc/sane.d/dll.conf --replace '${backend}' '# ${backend} disabled in nixos config' 34 + ''; 30 35 in 31 36 stdenv.mkDerivation { 32 37 name = "sane-config"; ··· 42 47 } 43 48 44 49 mkdir -p $out/etc/sane.d $out/etc/sane.d/dll.d $out/lib/sane 45 - '' + concatMapStrings installSanePath paths; 50 + '' 51 + + (concatMapStrings installSanePath paths) 52 + + (concatMapStrings disableBackend disabledDefaultBackends); 46 53 }