From b3be60ea8d8da901a101ed3b59d5d8e704653da5 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Fri, 16 May 2025 09:22:33 -0500 Subject: [PATCH] chore: Add Nix-based build and CI configuration. --- .envrc | 1 + .gitea/workflows/test.yml | 13 ++---- .gitignore | 3 +- flake.lock | 97 +++++++++++++++++++++++++++++++++++++++ flake.nix | 55 ++++++++++++++++++++++ 5 files changed, 160 insertions(+), 9 deletions(-) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix 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/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index 51a9d6e..e13c931 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -26,12 +26,9 @@ jobs: ~/.cargo/git/db/ target/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable - components: rustfmt, clippy - - name: install Linux build dependencies - run: sudo apt-get update; sudo apt-get install -y --no-install-recommends libasound2-dev libudev-dev libwayland-dev libclang-dev libspeechd-dev + - name: Install Nix + uses: https://github.com/cachix/install-nix-action@v31 + if: runner.os == 'linux' + - name: Test + run: nix develop --command pre-commit run -a if: runner.os == 'linux' - - uses: actions/setup-python@v3 - - uses: pre-commit/action@v3.0.1 diff --git a/.gitignore b/.gitignore index b354aec..ba06ef7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ Cargo.lock -target/ \ No newline at end of file +target/ +.direnv \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a6658a4 --- /dev/null +++ b/flake.lock @@ -0,0 +1,97 @@ +{ + "nodes": { + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1745925850, + "narHash": "sha256-cyAAMal0aPrlb1NgzMxZqeN1mAJ2pJseDhm2m6Um8T0=", + "owner": "nix-community", + "repo": "naersk", + "rev": "38bc60bbc157ae266d4a0c96671c6c742ee17a5f", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "master", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1747312588, + "narHash": "sha256-MmJvj6mlWzeRwKGLcwmZpKaOPZ5nJb/6al5CXqJsgjo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b1bebd0fe266bbd1820019612ead889e96a8fa2d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1747312588, + "narHash": "sha256-MmJvj6mlWzeRwKGLcwmZpKaOPZ5nJb/6al5CXqJsgjo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b1bebd0fe266bbd1820019612ead889e96a8fa2d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "naersk": "naersk", + "nixpkgs": "nixpkgs_2", + "utils": "utils" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..61ae0be --- /dev/null +++ b/flake.nix @@ -0,0 +1,55 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + utils.url = "github:numtide/flake-utils"; + naersk.url = "github:nix-community/naersk/master"; + }; + + outputs = + { + self, + nixpkgs, + utils, + naersk, + }: + utils.lib.eachDefaultSystem ( + system: + let + pkgs = import nixpkgs { inherit system; }; + naersk-lib = pkgs.callPackage naersk { }; + in + { + devShell = + with pkgs; + mkShell.override { stdenv = pkgs.clangStdenv; } rec { + nativeBuildInputs = [ + cargo + rustc + rustfmt + rustPackages.clippy + pkg-config + pre-commit + git-cliff + ]; + buildInputs = [ + speechd + udev + alsa-lib + vulkan-loader + xorg.libX11 + xorg.libXcursor + xorg.libXi + xorg.libXrandr + libxkbcommon + wayland + ]; + shellHook = '' + export LIBCLANG_PATH="${pkgs.libclang.lib}/lib" + export RUSTFLAGS="-C link-arg=-Wl,-rpath,${lib.makeLibraryPath buildInputs}" + pre-commit install + ''; + RUST_SRC_PATH = rustPlatform.rustLibSrc; + }; + } + ); +}