fork/nix-minecraft
git clone https://git.julia.blue/fork/nix-minecraft
e857551
master
1{ lib } : 2lib . makeExtensible ( 3self : 4let 5inherit ( lib ) 6attrNames 7concatLines 8concatStrings 9concatStringsSep 10drop 11filter 12filterAttrs 13hasSuffix 14id 15isList 16last 17mapAttrs' 18removePrefix 19removeSuffix 20sort 21splitString 22stringToCharacters 23take 24versionOlder 25nameValuePair 26; 27inherit ( builtins ) 28match 29pathExists 30readDir 31replaceStrings 32typeOf 33; 34in 35rec { 36chain = { 37func = id ; 38__functor = 39self :input : 40if ( typeOf input ) == "lambda" then self // { func = e :input ( self . func e ); } else self . func input ; 41}; 42 43isNormalVersion = v :isList ( match "([[:digit:]]+\.[[:digit:]]+(\.[[:digit:]]+)?)" v ); 44 45latestVersion = 46versions :chain ( filter isNormalVersion ) ( sort versionOlder ) last ( attrNames versions ); 47 48escapeVersion = replaceStrings [ "." " " ] [ "_" "_" ]; 49 50removeVanilla = n :escapeVersion ( removePrefix "vanilla-" n ); 51 52# Stolen from digga: https://github.com/divnix/digga/blob/587013b2500031b71959496764b6fdd1b2096f9a/src/importers.nix#L61-L114 53rakeLeaves = 54dirPath : 55let 56seive = 57file :type : 58# Only rake `.nix` files or directories 59( type == "regular" && hasSuffix ".nix" file ) || ( type == "directory" ); 60 61collect = file :type :{ 62name = removeSuffix ".nix" file ; 63value = 64let 65path = dirPath + "/ ${ file } " ; 66in 67if ( type == "regular" ) || ( type == "directory" && pathExists ( path + "/default.nix" )) then 68path 69# recurse on directories that don't contain a `default.nix` 70else 71rakeLeaves path ; 72}; 73 74files = filterAttrs seive ( readDir dirPath ); 75in 76filterAttrs ( n :v :v != { }) ( mapAttrs' collect files ); 77 78# Same as collectFiles, but only gathers files from a specific subdirectory 79# (e.g. "config") 80collectFilesAt = 81path :subdir :mapAttrs' ( n :nameValuePair ( " ${ subdir } / ${ n } " )) ( collectFiles " ${ path } / ${ subdir } " ); 82 83# Get all files from a path (e.g. a modpack derivation) and return them in the 84# format expected by the files/symlinks module options. 85collectFiles = 86let 87mapListToAttrs = 88fn :fv :list : 89lib . listToAttrs ( map ( x :nameValuePair ( fn x ) ( fv x )) list ); 90in 91path : 92mapListToAttrs ( x :builtins . unsafeDiscardStringContext ( lib . removePrefix " ${ path } /" x )) ( lib . id ) ( 93lib . filesystem . listFilesRecursive " ${ path } " 94); 95 96wrapJarManifest = 97manifestText : 98let 99chunkCharacters' = 100characters :chunks : 101if 102characters != [ ] # 71 characters plus space prefix = 72 line length 103then 104chunkCharacters' ( drop 71 characters ) ( chunks ++ [ ( take 71 characters ) ]) 105else 106chunks ; 107 108chunkCharacters = 109characters :# First line gets 72 due to not having space prefix 110chunkCharacters' ( drop 72 characters ) [ ( take 72 characters ) ]; 111 112wrapLine = chain stringToCharacters chunkCharacters ( map concatStrings ) ( concatStringsSep "\n " ); 113in 114chain ( splitString "\n" ) ( map wrapLine ) concatLines manifestText ; 115} 116)