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.lock b/flake.lock new file mode 100644 index 0000000..2f1a406 --- /dev/null +++ b/flake.lock @@ -0,0 +1,103 @@ +{ + "nodes": { + "crane": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1717025063, + "narHash": "sha256-dIubLa56W9sNNz0e8jGxrX3CAkPXsq7snuFA/Ie6dn8=", + "owner": "ipetkov", + "repo": "crane", + "rev": "480dff0be03dac0e51a8dfc26e882b0d123a450e", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1716769173, + "narHash": "sha256-7EXDb5WBw+d004Agt+JHC/Oyh/KTUglOaQ4MNjBbo5w=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9ca3f649614213b2aaf5f1e16ec06952fe4c2632", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1717035469, + "narHash": "sha256-MzH+yjKULH3HCRj9QCTwBvqq4LZkR0ZqRE/QfGOGC2E=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "095702e63a40e86f339d11864da9dc965b70a01e", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..34ebdcd --- /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 = + [] + ++ 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"