Login
4 branches 0 tags
Ben (T14/NixOS) Improved flake 41eb128 11 days ago 252 Commits
rubhub / flake.nix
{
  description = "RubHub";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
  };

  outputs = { self, nixpkgs }:
    let
      # Target system(s) — adjust if you need macOS or other
      systems = [ "x86_64-linux" "aarch64-linux" ];
      forAllSystems = nixpkgs.lib.genAttrs systems;
    in
      {
        packages = forAllSystems (system:
        let
          pkgs = nixpkgs.legacyPackages.${system};
          rustPlatform = pkgs.makeRustPlatform {
            cargo = pkgs.cargo;
            rustc = pkgs.rustc;
          };
        in
        {
          default = rustPlatform.buildRustPackage {
            pname = "rubhub";
            version = "0.1.0";  # You can read this from Cargo.toml if desired

            src = ./.;

            # These are usually auto-detected, but you can specify if needed
            cargoLock = { lockFile = ./Cargo.lock; };

            # Optional: pass nativeBuildInputs if your crate needs them at build time
            nativeBuildInputs = with pkgs; [
              clang
              pkg-config
            ];

            meta = {
              description = "RubHub";
              license = pkgs.lib.licenses.eupl12; # adjust as needed
            };
          };
        });

      # Optional: define checks (e.g., tests, clippy, fmt)
      checks = forAllSystems (system:
        let
          pkgs = nixpkgs.legacyPackages.${system};
          rubhub = self.packages.${system}.rubhub;
        in
        {
          # Basic test suite
          rubhub-tests = pkgs.stdenv.mkDerivation {
            name = "rubhub-tests";
            src = ./.;
            nativeBuildInputs = with pkgs; [ cargo rustc ];
            buildPhase = ''
              runHook preBuild
              cargo test --locked --release
              runHook postBuild
            '';
            installPhase = "touch $out";
          };

          # Optional: clippy check
          rubhub-clippy = pkgs.stdenv.mkDerivation {
            name = "rubhub-clippy";
            src = ./.;
            nativeBuildInputs = with pkgs; [ cargo rustc clippy ];
            buildPhase = ''
              cargo clippy --locked -- -D warnings
            '';
            installPhase = "touch $out";
          };
        });

        # So you can do `nix run .`
        apps = forAllSystems (system: {
          default = {
            type = "app";
            program = "${self.packages.${system}.rubhub}/bin/rubhub";
          };
        });

        devShells = forAllSystems (system:
          let
            pkgs = nixpkgs.legacyPackages.${system};
          in
            {
              default = pkgs.mkShell {
                strictDeps = true;
                nativeBuildInputs = with pkgs; [
                  rustc
                  cargo
                  rustfmt
                  clippy
                  rust-analyzer
                  clang

                  bacon
                  mold
                  cargo-nextest

                  nodejs_24
                  typescript-language-server
                  biome

                  tokei
                ];

                RUSTFLAGS = "-C link-arg=-fuse-ld=mold";
                LD = "${pkgs.mold}/bin/mold";
                CC = "${pkgs.llvmPackages.clang}/bin/clang";
                CXX = "${pkgs.llvmPackages.clang}/bin/clang++";
              };
            });
      };
}