flake.nix 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. {
  2. description = "Crush is a tool for building software with AI";
  3. inputs = {
  4. nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  5. };
  6. outputs =
  7. { self, nixpkgs, ... }:
  8. let
  9. allSystems = [
  10. "x86_64-linux" # 64-bit Intel/AMD Linux
  11. "aarch64-linux" # 64-bit ARM Linux
  12. "x86_64-darwin" # 64-bit Intel macOS
  13. "aarch64-darwin" # 64-bit ARM macOS
  14. ];
  15. forAllSystems =
  16. f:
  17. nixpkgs.lib.genAttrs allSystems (
  18. system:
  19. f {
  20. pkgs = import nixpkgs { inherit system; };
  21. }
  22. );
  23. in
  24. {
  25. nixosModules.default =
  26. {
  27. config,
  28. lib,
  29. pkgs,
  30. ...
  31. }:
  32. let
  33. crushOptions = import ./nix/options.nix { inherit lib; };
  34. in
  35. {
  36. options = {
  37. programs.crush = {
  38. enable = lib.mkEnableOption "Enable crush";
  39. settings = crushOptions;
  40. };
  41. };
  42. config = lib.mkIf config.programs.crush.enable {
  43. environment.systemPackages = [ self.packages.${pkgs.system}.default ];
  44. environment.etc."crush/crush.json" = lib.mkIf (config.programs.crush.settings != { }) {
  45. text = builtins.toJSON config.programs.crush.settings;
  46. mode = "0644";
  47. };
  48. };
  49. };
  50. homeManagerModules.default =
  51. {
  52. config,
  53. lib,
  54. pkgs,
  55. ...
  56. }:
  57. let
  58. crushOptions = import ./nix/options.nix { inherit lib; };
  59. in
  60. {
  61. options = {
  62. programs.crush = {
  63. enable = lib.mkEnableOption "Enable crush";
  64. settings = crushOptions;
  65. };
  66. };
  67. config = lib.mkIf config.programs.crush.enable {
  68. home.packages = [ self.packages.${pkgs.system}.default ];
  69. home.file.".config/crush/crush.json" = lib.mkIf (config.programs.crush.settings != { }) {
  70. text = builtins.toJSON config.programs.crush.settings;
  71. };
  72. };
  73. };
  74. packages = forAllSystems (
  75. { pkgs }:
  76. let
  77. version = if self ? rev then self.rev else "dirty";
  78. crush = pkgs.buildGoModule {
  79. pname = "crush";
  80. inherit version;
  81. subPackages = [ "." ]; # Build from root directory
  82. src = self;
  83. vendorHash = "sha256-DoOYptWZvhAHPT9/m3jAui5KMDdZpIChJboRktM/D9U=";
  84. ldflags = [
  85. "-s"
  86. "-w"
  87. "-X github.com/charmbracelet/crush/internal/version.Version=${version}"
  88. ];
  89. nativeBuildInputs = [ pkgs.installShellFiles ];
  90. postInstall = ''
  91. installShellCompletion --cmd crush \
  92. --bash <($out/bin/crush completion bash) \
  93. --fish <($out/bin/crush completion fish) \
  94. --zsh <($out/bin/crush completion zsh)
  95. # Generate and install man page
  96. $out/bin/crush man > crush.1
  97. installManPage crush.1
  98. '';
  99. meta = with pkgs.lib; {
  100. description = "A tool for building software with AI";
  101. homepage = "https://github.com/charmbracelet/crush";
  102. license = licenses.mit;
  103. maintainers = with maintainers; [ taciturnaxolotl ];
  104. platforms = platforms.linux ++ platforms.darwin;
  105. };
  106. };
  107. in
  108. {
  109. default = crush;
  110. }
  111. );
  112. apps = forAllSystems (
  113. { pkgs }:
  114. {
  115. default = {
  116. type = "app";
  117. program = "${self.packages.${pkgs.system}.default}/bin/crush";
  118. };
  119. }
  120. );
  121. formatter = forAllSystems ({ pkgs }: pkgs.nixfmt-tree);
  122. };
  123. }