diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.github/workflows/buildpkgs.yml b/.github/workflows/buildpkgs.yml new file mode 100644 index 0000000..a9adbc8 --- /dev/null +++ b/.github/workflows/buildpkgs.yml @@ -0,0 +1,65 @@ +name: build client,server binaries +on: + pull_request: + paths: + - "flake.nix" + - "flake.lock" + - "client/src/**" + - "server/src/**" + push: + paths: + - "flake.nix" + - "flake.lock" + - "client/src/**" + - "server/src/**" + workflow_dispatch: +permissions: + id-token: write + contents: write + packages: write +jobs: + build-all: + runs-on: ubuntu-latest + permissions: + id-token: write + contents: write + packages: write + steps: + - uses: actions/checkout@v4 + - uses: wimpysworld/nothing-but-nix@main + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@main + - name: build client + id: build-client + run: | + nix --version + nix build + - name: release client + env: + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} + run: | + ls -la result/bin + pwd + if [ -f "result/bin/client" ]; then + gh release create "${GITHUB_RUN_ID}" --draft=false --generate-notes || true + cp result/bin/.client-wrapped ../client + gh release upload "${GITHUB_RUN_ID}" "../client" --clobber || true + else + echo "No client found, failing job" + exit 1 + fi + - name: build server + id: build-server + run: | + nix build .#server + - name: release server + env: + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} + run: | + if [ -f "result/bin/server" ]; then + gh release create "${GITHUB_RUN_ID}" --draft=false --generate-notes || true + gh release upload "${GITHUB_RUN_ID}" "result/bin/server" --clobber || true + else + echo "No client found, failing job" + exit 1 + fi diff --git a/.gitignore b/.gitignore index ea8c4bf..a40496e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /target +/result +.direnv \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..c04bb03 --- /dev/null +++ b/flake.lock @@ -0,0 +1,46 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1746904237, + "narHash": "sha256-3e+AVBczosP5dCLQmMoMEogM57gmZ2qrVSrmq9aResQ=", + "rev": "d89fc19e405cb2d55ce7cc114356846a0ee5e956", + "revCount": 797896, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.797896%2Brev-d89fc19e405cb2d55ce7cc114356846a0ee5e956/0196c1a7-7ad3-74a9-9d50-1b854aca6d6c/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/NixOS/nixpkgs/0.1" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1747017456, + "narHash": "sha256-C/U12fcO+HEF071b5mK65lt4XtAIZyJSSJAg9hdlvTk=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "5b07506ae89b025b14de91f697eba23b48654c52", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..2c6a221 --- /dev/null +++ b/flake.nix @@ -0,0 +1,130 @@ +{ + description = "A Nix-flake-based Rust development environment"; + + inputs = { + nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = + inputs: + let + supportedSystems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + forEachSupportedSystem = + f: + inputs.nixpkgs.lib.genAttrs supportedSystems ( + system: + f { + pkgs = import inputs.nixpkgs { + inherit system; + overlays = [ + inputs.rust-overlay.overlays.default + inputs.self.overlays.default + ]; + }; + } + ); + in + { + overlays.default = final: prev: { + rustToolchain = + let + rust = prev.rust-bin; + in + if builtins.pathExists ./rust-toolchain.toml then + rust.fromRustupToolchainFile ./rust-toolchain.toml + else if builtins.pathExists ./rust-toolchain then + rust.fromRustupToolchainFile ./rust-toolchain + else + rust.stable.latest.default.override { + extensions = [ + "rust-src" + "rustfmt" + ]; + }; + }; + packages = forEachSupportedSystem ( + { pkgs }: + let + runtime-stuff = with pkgs; [ + vulkan-loader + libGL + libxkbcommon + wayland + ]; + libpath = pkgs.lib.makeLibraryPath runtime-stuff; + in + rec { + client = pkgs.rustPlatform.buildRustPackage { + pname = "client"; + version = "0.1.0"; + src = ./.; + cargoLock.lockFile = ./Cargo.lock; + buildInputs = runtime-stuff; + nativeBuildInputs = [ pkgs.makeWrapper ]; + postInstall = '' + wrapProgram $out/bin/client --set LD_LIBRARY_PATH ${libpath} + ''; + }; + default = client; + server = pkgs.rustPlatform.buildRustPackage { + pname = "server"; + version = "0.1.0"; + src = ./.; + cargoBuildFlags = [ + "--package" + "server" + ]; + cargoLock.lockFile = ./Cargo.lock; + buildInputs = runtime-stuff; + }; + + } + ); + + devShells = forEachSupportedSystem ( + { pkgs }: + { + default = pkgs.mkShell { + packages = with pkgs; [ + rustToolchain + openssl + pkg-config + cargo-deny + cargo-edit + cargo-watch + rust-analyzer + ]; + + env = + let + libPath = + with pkgs; + lib.makeLibraryPath [ + libGL + libxkbcommon + wayland + vulkan-tools + vulkan-loader + vulkan-validation-layers + vulkan-extension-layer + ]; + in + { + # Required by rust-analyzer + LD_LIBRARY_PATH = libPath; + RUST_SRC_PATH = "${pkgs.rustToolchain}/lib/rustlib/src/rust/library"; + }; + }; + } + ); + }; +}