overlays.nix (2002B)
1 overlayDir: { 2 config, 3 lib, 4 inputs, 5 ... 6 }: let 7 date = inputs.self.lastModifiedDate or "19700101000000"; 8 year = lib.substring 0 4 date; 9 monthNum = lib.substring 4 2 date; 10 month = lib.elemAt [ 11 "january" 12 "february" 13 "march" 14 "april" 15 "may" 16 "june" 17 "july" 18 "august" 19 "september" 20 "october" 21 "november" 22 "december" 23 ] (lib.toInt (lib.removePrefix "0" monthNum) - 1); 24 25 tmplArgs = { 26 inherit year month; 27 homeDir = config.home.homeDirectory; 28 }; 29 30 mkMapping = path: prefix: let 31 scan = dir: rel: 32 lib.concatLists (lib.mapAttrsToList (name: type: let 33 newRel = 34 if rel == "" 35 then name 36 else "${rel}/${name}"; 37 newPath = dir + "/${name}"; 38 in 39 if type == "directory" 40 then scan newPath newRel 41 else [ 42 { 43 name = newRel; 44 path = newPath; 45 } 46 ]) 47 (builtins.readDir dir)); 48 in 49 builtins.listToAttrs (map (file: let 50 isNix = lib.hasSuffix ".nix" file.name; 51 target = prefix + (lib.removeSuffix ".nix" file.name); 52 in 53 lib.nameValuePair target ( 54 if isNix 55 then { 56 text = import file.path tmplArgs; 57 force = true; 58 } 59 else { 60 source = file.path; 61 force = true; 62 } 63 )) (scan path "")); 64 in { 65 config = { 66 home.file = lib.mapAttrs (_: lib.mkForce) ( 67 lib.optionalAttrs (builtins.pathExists (overlayDir + "/home")) (mkMapping (overlayDir + "/home") ".") 68 // lib.optionalAttrs (builtins.pathExists (overlayDir + "/bin")) (lib.mapAttrs (_: v: v // {executable = true;}) (mkMapping (overlayDir + "/bin") "bin/")) 69 // lib.optionalAttrs (builtins.pathExists (overlayDir + "/local")) (mkMapping (overlayDir + "/local") ".local/") 70 ); 71 72 xdg.configFile = lib.mapAttrs (_: lib.mkForce) ( 73 lib.optionalAttrs (builtins.pathExists (overlayDir + "/config")) (mkMapping (overlayDir + "/config") "") 74 ); 75 }; 76 }