summaryrefslogtreecommitdiffstats
path: root/makefu/3modules/sane-extra.nix
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2017-08-02 01:08:12 +0200
committerlassulus <lassulus@lassul.us>2017-08-04 11:06:00 +0200
commit37373468839e8b734d0ea9ddabb49d2196206d4f (patch)
treebdac8c6c15dc9a27af5fcf87189e160feabada53 /makefu/3modules/sane-extra.nix
parent87c7d8dcf933c2de783098dfe9b6f1b383062daf (diff)
ma sane-extra: init
Diffstat (limited to 'makefu/3modules/sane-extra.nix')
-rw-r--r--makefu/3modules/sane-extra.nix45
1 files changed, 45 insertions, 0 deletions
diff --git a/makefu/3modules/sane-extra.nix b/makefu/3modules/sane-extra.nix
new file mode 100644
index 000000000..2e0ce8f2f
--- /dev/null
+++ b/makefu/3modules/sane-extra.nix
@@ -0,0 +1,45 @@
+{ config, lib, pkgs, ... }:
+# https://github.com/michalrus/dotfiles/blob/d943be3089aa436e07cea5f22d829402936a9229/.nixos-config.symlink/modules/sane-extra-config.nix
+# via https://github.com/NixOS/nixpkgs/issues/17411
+# via https://unix.stackexchange.com/questions/321954/install-epson-v39-on-nixos
+with lib;
+
+let
+
+ cfg = config.hardware.sane;
+
+ pkg = if cfg.snapshot
+ then pkgs.sane-backends-git
+ else pkgs.sane-backends;
+
+ backends = [ pkg ] ++ cfg.extraBackends;
+
+ saneConfig = pkgs.mkSaneConfig { paths = backends; };
+
+ saneExtraConfig = pkgs.runCommand "sane-extra-config" {} ''
+ cp -Lr '${pkgs.mkSaneConfig { paths = [ pkgs.sane-backends ]; }}'/etc/sane.d $out
+ chmod +w $out
+ ${concatMapStrings (c: ''
+ f="$out/${c.name}.conf"
+ [ ! -e "$f" ] || chmod +w "$f"
+ cat ${builtins.toFile "" (c.value + "\n")} >>"$f"
+ chmod -w "$f"
+ '') (mapAttrsToList nameValuePair cfg.extraConfig)}
+ chmod -w $out
+ '';
+
+in
+
+{
+ options = {
+ hardware.sane.extraConfig = mkOption {
+ type = types.attrsOf types.lines;
+ default = {};
+ example = { "some-backend" = "# some lines to add to its .conf"; };
+ };
+ };
+
+ config = mkIf (cfg.enable && cfg.extraConfig != {}) {
+ hardware.sane.configDir = saneExtraConfig.outPath;
+ };
+}