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 . nnn ; 7 8renderSetting = key :value :" ${ key } : ${ value } " ; 9 10renderSettings = settings : 11concatStringsSep ";" ( mapAttrsToList renderSetting settings ); 12 13pluginModule = types . submodule ({ ...} :{ 14options = { 15src = mkOption { 16type = with types ; nullOr path ; 17example = literalExpression '' 18(pkgs.fetchFromGitHub { 19owner = "jarun"; 20repo = "nnn"; 21rev = "v4.0"; 22sha256 = "sha256-Hpc8YaJeAzJoEi7aJ6DntH2VLkoR6ToP6tPYn3llR7k="; 23}) + "/plugins"; 24'' ; 25default = null ; 26description = '' 27Path to the plugin folder. 28'' ; 29}; 30 31mappings = mkOption { 32type = with types ; attrsOf str ; 33description = '' 34Key mappings to the plugins. 35'' ; 36default = { }; 37example = literalExpression '' 38{ 39c = "fzcd"; 40f = "finder"; 41v = "imgview"; 42}; 43'' ; 44}; 45}; 46}); 47in { 48meta . maintainers = with maintainers ; [ thiagokokada ]; 49 50options = { 51programs . nnn = { 52enable = mkEnableOption "nnn" ; 53 54package = mkOption { 55type = types . package ; 56default = pkgs . nnn ; 57defaultText = literalExpression "pkgs.nnn" ; 58example = 59literalExpression "pkgs.nnn.override ({ withNerdIcons = true; });" ; 60description = '' 61Package containing the {command}`nnn` program. 62'' ; 63}; 64 65finalPackage = mkOption { 66type = types . package ; 67readOnly = true ; 68visible = false ; 69description = '' 70Resulting nnn package. 71'' ; 72}; 73 74bookmarks = mkOption { 75type = with types ; attrsOf str ; 76description = '' 77Directory bookmarks. 78'' ; 79example = literalExpression '' 80{ 81d = "~/Documents"; 82D = "~/Downloads"; 83p = "~/Pictures"; 84v = "~/Videos"; 85}; 86'' ; 87default = { }; 88}; 89 90extraPackages = mkOption { 91type = with types ; listOf package ; 92example = 93literalExpression "with pkgs; [ ffmpegthumbnailer mediainfo sxiv ]" ; 94description = '' 95Extra packages available to nnn. 96'' ; 97default = [ ]; 98}; 99 100plugins = mkOption { 101type = pluginModule ; 102description = '' 103Manage nnn plugins. 104'' ; 105default = { }; 106}; 107}; 108}; 109 110config = let 111nnnPackage = cfg . package . overrideAttrs ( oldAttrs :{ 112nativeBuildInputs = ( oldAttrs . nativeBuildInputs or [ ]) 113++ [ pkgs . makeWrapper ]; 114postInstall = '' 115${ oldAttrs . postInstall or "" } 116 117wrapProgram $ out /bin/nnn \ 118--prefix PATH : " ${ makeBinPath cfg . extraPackages } " \ 119--prefix NNN_BMS : " ${ renderSettings cfg . bookmarks } " \ 120--prefix NNN_PLUG : " ${ renderSettings cfg . plugins . mappings } " 121'' ; 122}); 123in mkIf cfg . enable { 124programs . nnn . finalPackage = nnnPackage ; 125home . packages = [ nnnPackage ]; 126xdg . configFile . "nnn/plugins" = 127mkIf ( cfg . plugins . src != null ) { source = cfg . plugins . src ; }; 128}; 129}