diff --git a/Cargo.toml b/Cargo.toml index 70d78c4..9a40a00 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,12 @@ members = ["hac-config", "hac-core", "hac-client", "hac-colors", "hac-cli"] default-members = ["hac-client"] resolver = "2" +[workspace.metadata.crane] +name = "hac" + +[workspace.package] +version = "0.1.0" + [workspace.dependencies] hac-config = { path = "hac-config" } hac-core = { path = "hac-core" } diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..1965fa5 --- /dev/null +++ b/flake.nix @@ -0,0 +1,75 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + outputs = { + nixpkgs, + rust-overlay, + crane, + ... + }: let + inherit (nixpkgs) lib; + withSystem = f: + lib.fold lib.recursiveUpdate {} + (map f ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"]); + in + withSystem ( + system: let + pkgs = import nixpkgs { + inherit system; + overlays = [rust-overlay.overlays.default]; + }; + inherit (pkgs) stdenv lib; + toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + craneLib = (crane.mkLib pkgs).overrideToolchain toolchain; + buildDeps = + [pkgs.openssl] + ++ lib.optionals stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [ + SystemConfiguration + ]); + crate = craneLib.buildPackage { + # Filter src to only .rs, .toml, and .scm files to avoid needless recompiles + src = let + schemeFilter = path: _type: builtins.match ".*scm$" path != null; + schemeOrCargo = path: type: + (schemeFilter path type) || (craneLib.filterCargoSources path type); + in + lib.cleanSourceWith { + src = craneLib.path ./.; + filter = schemeOrCargo; + }; + strictDeps = true; + buildInputs = buildDeps; + nativeBuildInputs = lib.optionals stdenv.isLinux [pkgs.pkg-config]; + doNotSign = stdenv.isDarwin; # Build seems to break when this is true on Darwin + }; + in { + apps.${system}.default = let + name = crate.pname or crate.name; + exe = crate.passthru.exePath or "/bin/${name}"; + in { + type = "app"; + program = "${crate}${exe}"; + }; + packages.${system}.default = crate; + checks.${system} = {inherit crate;}; + devShells.${system}.default = pkgs.mkShell { + packages = with pkgs; + [ + toolchain + rust-analyzer-unwrapped + ] + ++ buildDeps; + RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library"; + }; + } + ); +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..90e92de --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "stable" +components = ["rust-src"] +profile = "default"