default.nix 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. { inputs
  2. , outputs
  3. ,
  4. }:
  5. let
  6. inherit (inputs) darwin devenv home-manager nixpkgs;
  7. inherit (nixpkgs) lib;
  8. # Helper to determine if a system is Darwin
  9. isDarwin = system: builtins.elem "darwin" (builtins.split "-" system);
  10. # Helper to get the appropriate nixpkgs for a system
  11. getPkgsForSystem = system:
  12. if isDarwin system
  13. then inputs.nixpkgs-darwin.legacyPackages.${system}
  14. else inputs.nixpkgs.legacyPackages.${system};
  15. in
  16. rec {
  17. mkSystem =
  18. { system
  19. , modules ? [ ]
  20. ,
  21. }:
  22. lib.nixosSystem {
  23. inherit system modules;
  24. specialArgs = { inherit inputs outputs; };
  25. };
  26. mkDarwin =
  27. { system
  28. , modules ? [ ]
  29. ,
  30. }:
  31. darwin.lib.darwinSystem {
  32. inherit system modules;
  33. specialArgs = { inherit inputs outputs; };
  34. };
  35. mkHome =
  36. { system
  37. , modules ? [ ]
  38. ,
  39. }:
  40. home-manager.lib.homeManagerConfiguration {
  41. inherit modules;
  42. pkgs = getPkgsForSystem system;
  43. extraSpecialArgs = {
  44. inherit inputs outputs;
  45. isDarwin = isDarwin system;
  46. };
  47. };
  48. mkDevenvShell = config:
  49. eachSystemWithPkgs (
  50. { pkgs }:
  51. lib.mapAttrs
  52. (
  53. _name: module:
  54. devenv.lib.mkShell {
  55. inherit inputs pkgs;
  56. modules = [ module ];
  57. }
  58. )
  59. config
  60. );
  61. eachSystem = lib.genAttrs [
  62. "x86_64-linux"
  63. "x86_64-darwin"
  64. "aarch64-linux"
  65. "aarch64-darwin"
  66. ];
  67. eachSystemWithPkgs = f:
  68. eachSystem (
  69. system:
  70. f {
  71. pkgs = getPkgsForSystem system;
  72. }
  73. );
  74. print = text:
  75. let
  76. json = builtins.toJSON text;
  77. in
  78. builtins.trace (builtins.fromJSON json) (builtins.fromJSON json);
  79. }