Advertisement
evanjs

new-modules/default.nix w/IFD mkPins

Sep 23rd, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. { lib, ... }:
  2.  
  3. with lib;
  4. let
  5. # Recursively constructs an attrset of a given folder, recursing on directories, value of attrs is the filetype
  6. getDir = dir: mapAttrs
  7. (file: type:
  8. if type == "directory" then getDir "${dir}/${file}" else type
  9. )
  10. (builtins.readDir dir);
  11.  
  12. # Collects all files of a directory as a list of strings of paths
  13. files = dir: collect isString (mapAttrsRecursive (path: type: concatStringsSep "/" path) (getDir dir));
  14.  
  15. # Filters out directories that don't end with .nix or are this file, also makes the strings absolute
  16. validFiles = dir: map
  17. (file: ./. + "/${file}")
  18. (filter
  19. (file: hasSuffix ".nix" file && file != "default.nix" &&
  20. ! lib.hasPrefix "x/taffybar/" file &&
  21. ! lib.hasSuffix "-hm.nix" file)
  22. (files dir));
  23.  
  24.  
  25. finalFiles = validFiles ./.;
  26.  
  27. mkPins = inputs:
  28. pkgs.runCommand "ifd-pins" { } ''
  29. mkdir $out
  30. cd $out
  31. ${lib.concatMapStringsSep "\n" (i: "ln -sv ${i.value} ${i.key}")
  32. (lib.attrValues
  33. (lib.mapAttrs (key: value: { inherit key value; }) inputs))}
  34. '';
  35.  
  36. finalImports = builtins.map (i: import i) finalFiles;
  37.  
  38. in
  39. {
  40. #imports = validFiles ./.;
  41. imports = mkPins finalImports;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement