Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
65 changes: 65 additions & 0 deletions .github/workflows/buildpkgs.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/target
/result
.direnv
46 changes: 46 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

130 changes: 130 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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";
};
};
}
);
};
}