summary refs log tree commit diff
diff options
context:
space:
mode:
authorSymphorien Gibol <symphorien+git@xlumurb.eu>2021-02-19 16:49:49 +0100
committerSymphorien Gibol <symphorien+git@xlumurb.eu>2021-02-19 16:52:26 +0100
commitc64fb5000b8da3ac657ffe5d9c7522e56b8768cd (patch)
tree886638e3ae5747e91afaa5769f73299283cff6a1
parent6b1057b452c55bb3b463f0d7055bc4ec3fd1f381 (diff)
downloadnixpkgs-c64fb5000b8da3ac657ffe5d9c7522e56b8768cd.tar
nixpkgs-c64fb5000b8da3ac657ffe5d9c7522e56b8768cd.tar.gz
nixpkgs-c64fb5000b8da3ac657ffe5d9c7522e56b8768cd.tar.bz2
nixpkgs-c64fb5000b8da3ac657ffe5d9c7522e56b8768cd.tar.lz
nixpkgs-c64fb5000b8da3ac657ffe5d9c7522e56b8768cd.tar.xz
nixpkgs-c64fb5000b8da3ac657ffe5d9c7522e56b8768cd.tar.zst
nixpkgs-c64fb5000b8da3ac657ffe5d9c7522e56b8768cd.zip
nixos/sane: allow to disable enabled-by-default plugins
use case: disabling v4l plugin because I don't use my webcam as a
scanner.
-rw-r--r--nixos/modules/services/hardware/sane.nix12
-rw-r--r--pkgs/applications/graphics/sane/config.nix13
2 files changed, 21 insertions, 4 deletions
diff --git a/nixos/modules/services/hardware/sane.nix b/nixos/modules/services/hardware/sane.nix
index 03070a8f9e7..f0595c43798 100644
--- a/nixos/modules/services/hardware/sane.nix
+++ b/nixos/modules/services/hardware/sane.nix
@@ -32,7 +32,7 @@ let
   };
 
   backends = [ pkg netConf ] ++ optional config.services.saned.enable sanedConf ++ config.hardware.sane.extraBackends;
-  saneConfig = pkgs.mkSaneConfig { paths = backends; };
+  saneConfig = pkgs.mkSaneConfig { paths = backends; inherit (config.hardware.sane) disabledDefaultBackends; };
 
   enabled = config.hardware.sane.enable || config.services.saned.enable;
 
@@ -75,6 +75,16 @@ in
       example = literalExample "[ pkgs.hplipWithPlugin ]";
     };
 
+    hardware.sane.disabledDefaultBackends = mkOption {
+      type = types.listOf types.str;
+      default = [];
+      example = [ "v4l" ];
+      description = ''
+        Names of backends which are enabled by default but should be disabled.
+        See <literal>$SANE_CONFIG_DIR/dll.conf</literal> for the list of possible names.
+      '';
+    };
+
     hardware.sane.configDir = mkOption {
       type = types.str;
       internal = true;
diff --git a/pkgs/applications/graphics/sane/config.nix b/pkgs/applications/graphics/sane/config.nix
index 304df652f15..397e17837bc 100644
--- a/pkgs/applications/graphics/sane/config.nix
+++ b/pkgs/applications/graphics/sane/config.nix
@@ -1,9 +1,10 @@
 { lib, stdenv }:
 
-{ paths }:
+{ paths, disabledDefaultBackends ? [] }:
 
 with lib;
-let installSanePath = path: ''
+let
+installSanePath = path: ''
       if [ -e "${path}/lib/sane" ]; then
         find "${path}/lib/sane" -maxdepth 1 -not -type d | while read backend; do
           symlink "$backend" "$out/lib/sane/$(basename "$backend")"
@@ -27,6 +28,10 @@ let installSanePath = path: ''
         done
       fi
     '';
+    disableBackend = backend: ''
+      grep -q '${backend}' $out/etc/sane.d/dll.conf || { echo '${backend} is not a default plugin in $SANE_CONFIG_DIR/dll.conf'; exit 1; }
+      substituteInPlace $out/etc/sane.d/dll.conf --replace '${backend}' '# ${backend} disabled in nixos config'
+    '';
 in
 stdenv.mkDerivation {
   name = "sane-config";
@@ -42,5 +47,7 @@ stdenv.mkDerivation {
     }
 
     mkdir -p $out/etc/sane.d $out/etc/sane.d/dll.d $out/lib/sane
-  '' + concatMapStrings installSanePath paths;
+  ''
+  + (concatMapStrings installSanePath paths)
+  + (concatMapStrings disableBackend disabledDefaultBackends);
 }