lib.nix 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. deployPkgs = forAllSystems (system: (import inputs.nixpkgs {
  30. inherit system;
  31. overlays = [
  32. inputs.deploy-rs.overlay
  33. (_: prev: {
  34. deploy-rs = {
  35. inherit (import inputs.nixpkgs { inherit system; }) deploy-rs;
  36. inherit (prev.deploy-rs) lib;
  37. };
  38. })
  39. ];
  40. }));
  41. }