dotfiles

My PC Dotfiles & Website

modules/lib/_build.nix (1884B)


  1## Builder Functions ##
  2lib: let
  3  inherit
  4    (builtins)
  5    concatStringsSep
  6    filter
  7    hasAttr
  8    listToAttrs
  9    map
 10    readFile
 11    ;
 12
 13  inherit
 14    (lib)
 15    flatten
 16    hasPrefix
 17    mapAttrsToList
 18    nameValuePair
 19    replaceStrings
 20    splitString
 21    ;
 22in {
 23  # Mime Types Handler
 24  mime = option:
 25    listToAttrs (
 26      flatten (
 27        mapAttrsToList (
 28          name: types:
 29            if hasAttr name option
 30            then map (type: nameValuePair type option."${name}") types
 31            else []
 32        ) (import ./_mime.nix)
 33      )
 34    );
 35
 36  # Script Builder
 37  script = file:
 38    concatStringsSep "\n" (
 39      (filter (line: line != "" && !(hasPrefix "#!" line))) (splitString "\n" (readFile file))
 40    );
 41
 42  # Theme Substituter
 43  theme = {
 44    accent ? "base0D",
 45    colors ? null,
 46    fonts ? null,
 47    file,
 48  }: let
 49    color = [
 50      "@accent"
 51      "@white"
 52      "@base00"
 53      "@base01"
 54      "@base02"
 55      "@base03"
 56      "@base04"
 57      "@base05"
 58      "@base06"
 59      "@base07"
 60      "@base08"
 61      "@base09"
 62      "@base0A"
 63      "@base0B"
 64      "@base0C"
 65      "@base0D"
 66      "@base0E"
 67      "@base0F"
 68    ];
 69
 70    color' = with colors; [
 71      colors."${accent}"
 72      "FFFFFF"
 73      base00
 74      base01
 75      base02
 76      base03
 77      base04
 78      base05
 79      base06
 80      base07
 81      base08
 82      base09
 83      base0A
 84      base0B
 85      base0C
 86      base0D
 87      base0E
 88      base0F
 89    ];
 90
 91    font = [
 92      "@font"
 93      "@monospace"
 94    ];
 95
 96    font' = with fonts; [
 97      sansSerif.name
 98      monospace.name
 99    ];
100  in
101    if (colors != null && fonts != null)
102    then replaceStrings (color ++ font) (color' ++ font') file
103    else if (colors != null)
104    then replaceStrings color color' file
105    else if (fonts != null)
106    then replaceStrings font font' file
107    else throw "One of 'colors' or 'fonts' must be declared";
108}