| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- {
- description = "Crush is a tool for building software with AI";
- inputs = {
- nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
- };
- outputs =
- { self, nixpkgs, ... }:
- let
- allSystems = [
- "x86_64-linux" # 64-bit Intel/AMD Linux
- "aarch64-linux" # 64-bit ARM Linux
- "x86_64-darwin" # 64-bit Intel macOS
- "aarch64-darwin" # 64-bit ARM macOS
- ];
- forAllSystems =
- f:
- nixpkgs.lib.genAttrs allSystems (
- system:
- f {
- pkgs = import nixpkgs { inherit system; };
- }
- );
- in
- {
- nixosModules.default =
- {
- config,
- lib,
- pkgs,
- ...
- }:
- let
- crushOptions = import ./nix/options.nix { inherit lib; };
- in
- {
- options = {
- programs.crush = {
- enable = lib.mkEnableOption "Enable crush";
- settings = crushOptions;
- };
- };
- config = lib.mkIf config.programs.crush.enable {
- environment.systemPackages = [ self.packages.${pkgs.system}.default ];
- environment.etc."crush/crush.json" = lib.mkIf (config.programs.crush.settings != { }) {
- text = builtins.toJSON config.programs.crush.settings;
- mode = "0644";
- };
- };
- };
- homeManagerModules.default =
- {
- config,
- lib,
- pkgs,
- ...
- }:
- let
- crushOptions = import ./nix/options.nix { inherit lib; };
- in
- {
- options = {
- programs.crush = {
- enable = lib.mkEnableOption "Enable crush";
- settings = crushOptions;
- };
- };
- config = lib.mkIf config.programs.crush.enable {
- home.packages = [ self.packages.${pkgs.system}.default ];
- home.file.".config/crush/crush.json" = lib.mkIf (config.programs.crush.settings != { }) {
- text = builtins.toJSON config.programs.crush.settings;
- };
- };
- };
- packages = forAllSystems (
- { pkgs }:
- let
- version = if self ? rev then self.rev else "dirty";
- crush = pkgs.buildGoModule {
- pname = "crush";
- inherit version;
- subPackages = [ "." ]; # Build from root directory
- src = self;
- vendorHash = "sha256-DoOYptWZvhAHPT9/m3jAui5KMDdZpIChJboRktM/D9U=";
- ldflags = [
- "-s"
- "-w"
- "-X github.com/charmbracelet/crush/internal/version.Version=${version}"
- ];
- nativeBuildInputs = [ pkgs.installShellFiles ];
- postInstall = ''
- installShellCompletion --cmd crush \
- --bash <($out/bin/crush completion bash) \
- --fish <($out/bin/crush completion fish) \
- --zsh <($out/bin/crush completion zsh)
- # Generate and install man page
- $out/bin/crush man > crush.1
- installManPage crush.1
- '';
- meta = with pkgs.lib; {
- description = "A tool for building software with AI";
- homepage = "https://github.com/charmbracelet/crush";
- license = licenses.mit;
- maintainers = with maintainers; [ taciturnaxolotl ];
- platforms = platforms.linux ++ platforms.darwin;
- };
- };
- in
- {
- default = crush;
- }
- );
- apps = forAllSystems (
- { pkgs }:
- {
- default = {
- type = "app";
- program = "${self.packages.${pkgs.system}.default}/bin/crush";
- };
- }
- );
- formatter = forAllSystems ({ pkgs }: pkgs.nixfmt-tree);
- };
- }
|