fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6cfg = config . programs . pistol ; 7 8configFile = concatStringsSep "\n" ( map ({ fpath , mime , command } : 9if fpath == "" then " ${ mime } ${ command } " else "fpath ${ fpath } ${ command } " ) 10cfg . associations ); 11 12association = types . submodule { 13options = { 14command = mkOption { 15type = types . str ; 16description = "Preview command for files matched by this association." ; 17}; 18 19fpath = mkOption { 20type = types . str ; 21default = "" ; 22description = "File path regex that this association should match." ; 23}; 24 25mime = mkOption { 26type = types . str ; 27default = "" ; 28description = "Mime type regex that this association should match." ; 29}; 30}; 31}; 32in { 33imports = [ 34( mkRemovedOptionModule [ "programs" "pistol" "config" ] 35"Pistol is now configured with programs.pistol.associations." ) 36]; 37 38meta . maintainers = [ hm . maintainers . mtoohey ]; 39 40options . programs . pistol = { 41enable = mkEnableOption "file previewer for terminal file managers" ; 42 43associations = mkOption { 44type = types . listOf association ; 45default = [ ]; 46example = literalExpression '' 47[ 48{ mime = "application/json"; command = "bat %pistol-filename%"; } 49{ mime = "application/*"; command = "hexyl %pistol-filename%"; } 50{ fpath = ".*.md$"; command = "sh: bat --paging=never --color=always %pistol-filename% | head -8"; } 51] 52'' ; 53description = '' 54Associations written to the Pistol configuration at 55{file}`$XDG_CONFIG_HOME/pistol/pistol.conf`. 56'' ; 57}; 58 59}; 60 61config = mkIf cfg . enable ( mkMerge [ 62{ 63assertions = [{ 64assertion = all ({ fpath , mime , ...} : 65( fpath != "" && mime == "" ) || ( fpath == "" && mime != "" )) 66cfg . associations ; 67message = '' 68Each entry in programs.pistol.associations must contain exactly one 69of fpath or mime. 70'' ; 71}]; 72 73home . packages = [ pkgs . pistol ]; 74} 75 76( mkIf ( cfg . associations != [ ] && pkgs . stdenv . hostPlatform . isDarwin ) { 77home . file . "Library/Application Support/pistol/pistol.conf" . text = 78configFile ; 79}) 80 81( mkIf ( cfg . associations != [ ] && ! pkgs . stdenv . hostPlatform . isDarwin ) { 82xdg . configFile . "pistol/pistol.conf" . text = configFile ; 83}) 84]); 85}