diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6095d275..347d8713 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -72,6 +72,9 @@ jobs: - name: Run tests run: nix develop -c $SHELL -c "npm t" + - name: Build trycp-server package + run: nix build .#trycp-server + - name: Setup tmate session if build or test run failed if: ${{ failure() }} uses: mxschmitt/action-tmate@v3 diff --git a/flake.lock b/flake.lock index 706ec98a..8a1834c4 100644 --- a/flake.lock +++ b/flake.lock @@ -35,6 +35,26 @@ } }, "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" + } + }, + "crane_2": { "inputs": { "nixpkgs": [ "holonix", @@ -138,6 +158,24 @@ "type": "github" } }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "holochain": { "flake": false, "locked": { @@ -159,7 +197,7 @@ "inputs": { "cargo-chef": "cargo-chef", "cargo-rdme": "cargo-rdme", - "crane": "crane", + "crane": "crane_2", "crate2nix": "crate2nix", "empty": "empty", "flake-compat": "flake-compat", @@ -315,11 +353,13 @@ }, "root": { "inputs": { + "crane": "crane", "holonix": "holonix", "nixpkgs": [ "holonix", "nixpkgs" ], + "rust-overlay": "rust-overlay_2", "versions": "versions" } }, @@ -345,6 +385,27 @@ "type": "github" } }, + "rust-overlay_2": { + "inputs": { + "flake-utils": "flake-utils_2", + "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" + } + }, "scaffolding": { "flake": false, "locked": { @@ -377,6 +438,21 @@ "type": "github" } }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, "versions": { "inputs": { "holochain": "holochain", diff --git a/flake.nix b/flake.nix index da817626..c7411d01 100644 --- a/flake.nix +++ b/flake.nix @@ -5,15 +5,29 @@ versions.url = "github:holochain/holochain?dir=versions/0_3_rc"; holonix.url = "github:holochain/holochain"; holonix.inputs.versions.follows = "versions"; + + # lib to build a nix package from a rust crate + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + # Rust toolchain + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; - outputs = inputs@{ holonix, ... }: + outputs = inputs@{ nixpkgs, holonix, crane, rust-overlay, ... }: holonix.inputs.flake-parts.lib.mkFlake { inherit inputs; } { # provide a dev shell for all systems that the holonix flake supports systems = builtins.attrNames holonix.devShells; - perSystem = { config, system, pkgs, ... }: + perSystem = { config, system, pkgs, lib, ... }: { + formatter = pkgs.nixpkgs-fmt; + devShells.default = pkgs.mkShell { inputsFrom = [ holonix.devShells.${system}.holochainBinaries ]; packages = with pkgs; [ @@ -21,6 +35,33 @@ nodejs ]; }; + + packages.trycp-server = + let + pkgs = import nixpkgs { + inherit system; + overlays = [ (import rust-overlay) ]; + }; + + rustToolchain = pkgs.rust-bin.stable."1.78.0".minimal; + + craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; + + crateInfo = craneLib.crateNameFromCargoToml { cargoToml = ./crates/trycp_server/Cargo.toml; }; + in + craneLib.buildPackage { + pname = "trycp-server"; + version = crateInfo.version; + src = craneLib.cleanCargoSource (craneLib.path ./.); + doCheck = false; + + buildInputs = [ ] + ++ (lib.optionals pkgs.stdenv.isDarwin + (with pkgs.darwin.apple_sdk_11_0.frameworks; [ + CoreFoundation + Security + ])); + }; }; }; }