lib.nix 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. { inputs, ... }:
  2. rec {
  3. specialArgs = { inherit inputs; };
  4. forAllSystems = inputs.nixpkgs.lib.genAttrs inputs.nixpkgs.lib.systems.flakeExposed;
  5. match' = regex: builtins.match ("(.*)" + regex);
  6. endsWith = regex: str: match' regex (if builtins.isPath str then
  7. builtins.baseNameOf str else str) != null;
  8. desuffix = regex: str: if (endsWith regex str) then
  9. (builtins.head (match' regex str)) else str;
  10. isDir = path: builtins.readFileType path == "directory";
  11. listDir = path: builtins.concatMap (n: [ (path + "/${n}") ])
  12. (builtins.attrNames (if isDir path then builtins.readDir path else {}));
  13. recListDir = path: builtins.concatMap (n:
  14. if isDir n then recListDir n else [ n ]) (listDir path);
  15. asAttrs = regex: path: builtins.listToAttrs
  16. (builtins.map (n: {
  17. name = desuffix regex (builtins.baseNameOf n);
  18. value = n;
  19. }) (builtins.filter (s: endsWith regex s && !isDir s) (listDir path)));
  20. mkSystem = system: conf: inputs.nixpkgs.lib.nixosSystem {
  21. inherit system specialArgs;
  22. modules = [
  23. inputs.agenix.nixosModules.age
  24. inputs.flake-programs-sqlite.nixosModules.programs-sqlite
  25. inputs.home-manager.nixosModules.home-manager
  26. inputs.impermanence.nixosModules.impermanence
  27. ] ++ (builtins.filter (endsWith "\\.nix") (recListDir ./nixos)) ++ conf;
  28. };
  29. }