From dace93eca983c5eb34b457fd2d0763c5110c602a Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Sun, 24 Sep 2023 15:08:48 +0200 Subject: [PATCH] Add Nix Flake (#1) * Add Nix Flake for development builds Signed-off-by: Sefa Eyeoglu * Add Nix formatter Ensure Nix code style is formatted using Alejandra. https://github.com/kamadorueda/alejandra Signed-off-by: Sefa Eyeoglu * Add garnix CI config https://garnix.io/ Signed-off-by: Sefa Eyeoglu * Add Nix info to README.md Signed-off-by: Sefa Eyeoglu * Add GitHub Action for Flake updates Signed-off-by: Sefa Eyeoglu * Add Nix overlay Signed-off-by: Sefa Eyeoglu * Add info about Nix outputs to README.md Signed-off-by: Sefa Eyeoglu --------- Signed-off-by: Sefa Eyeoglu --- .github/workflows/update-flake.yml | 26 +++++++++++ .gitignore | 2 + README.md | 6 +++ flake.lock | 48 ++++++++++++++++++++ flake.nix | 21 +++++++++ garnix.yaml | 5 +++ nix/derivation.nix | 70 ++++++++++++++++++++++++++++++ nix/dev.nix | 5 +++ nix/packages.nix | 18 ++++++++ 9 files changed, 201 insertions(+) create mode 100644 .github/workflows/update-flake.yml create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 garnix.yaml create mode 100644 nix/derivation.nix create mode 100644 nix/dev.nix create mode 100644 nix/packages.nix diff --git a/.github/workflows/update-flake.yml b/.github/workflows/update-flake.yml new file mode 100644 index 0000000..fad3acf --- /dev/null +++ b/.github/workflows/update-flake.yml @@ -0,0 +1,26 @@ +name: Update Flake Lockfile + +on: + schedule: + # run weekly at noon on sundays + - cron: "0 12 * * 0" + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + +jobs: + update-flake: + if: github.owner == 'galister' + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@main + - name: Update flake.lock + uses: DeterminateSystems/update-flake-lock@main + with: + pr-title: "Update flake.lock" diff --git a/.gitignore b/.gitignore index 265b7f5..eaf8d2e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /target .gdb_history +result +reuslt-* diff --git a/README.md b/README.md index 0ab33bf..ebddf4d 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,12 @@ Move screen: Grab using grip. Adjust distace using stick up/down while gripping. Resize screen: Same as Move screen but turn your controller to get the yellow laser. +## Nix Flake + +A Nix Flake is availabe as `github:galister/wlx-overlay-x`. Cached builds are available using [garnix](https://garnix.io/). See [garnix docs](https://garnix.io/docs/caching) to see how to utilize this binary cache. + +Run `nix flake show github:galister/wlx-overlay-x` to see all outputs of this flake. + # Known Issues StereoKit fails to build with OpenXR version 1.0.29. You can downgrade your OpenXR syetem package to fix this. diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..25e057c --- /dev/null +++ b/flake.lock @@ -0,0 +1,48 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1693611461, + "narHash": "sha256-aPODl8vAgGQ0ZYFIRisxYG5MOGSkIczvu2Cd8Gb9+1Y=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "7f53fdb7bdc5bb237da7fefef12d099e4fd611ca", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1695360818, + "narHash": "sha256-JlkN3R/SSoMTa+CasbxS1gq+GpGxXQlNZRUh9+LIy/0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e35dcc04a3853da485a396bdd332217d0ac9054f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..b6f51f8 --- /dev/null +++ b/flake.nix @@ -0,0 +1,21 @@ +{ + description = "A lightweight OpenXR overlay for Wayland desktops, inspired by XSOverlay"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-parts = { + url = "github:hercules-ci/flake-parts"; + inputs.nixpkgs-lib.follows = "nixpkgs"; + }; + }; + + outputs = inputs @ { + self, + flake-parts, + ... + }: + flake-parts.lib.mkFlake {inherit inputs;} { + systems = ["x86_64-linux" "aarch64-linux"]; + imports = [./nix/packages.nix ./nix/dev.nix]; + }; +} diff --git a/garnix.yaml b/garnix.yaml new file mode 100644 index 0000000..619bfff --- /dev/null +++ b/garnix.yaml @@ -0,0 +1,5 @@ +builds: + exclude: [] + include: + - "checks.*.*" + - "packages.*.*" diff --git a/nix/derivation.nix b/nix/derivation.nix new file mode 100644 index 0000000..a2b8540 --- /dev/null +++ b/nix/derivation.nix @@ -0,0 +1,70 @@ +{ + lib, + rustPlatform, + alsa-lib, + cmake, + cpm-cmake, + fontconfig, + freetype, + libglvnd, + libxkbcommon, + mesa, + openxr-loader, + pipewire, + pkg-config, + wayland, + xorg, + # flake + self, + version, +}: +rustPlatform.buildRustPackage { + pname = "wlx-overlay-x"; + inherit version; + + src = lib.cleanSource self; + + cargoLock = { + lockFile = ../Cargo.lock; + allowBuiltinFetchGit = true; + }; + + nativeBuildInputs = [ + cmake + pkg-config + rustPlatform.bindgenHook + ]; + + buildInputs = [ + alsa-lib + fontconfig + freetype + libglvnd + libxkbcommon + mesa + openxr-loader + pipewire + wayland + xorg.libX11 + ]; + + # From https://github.com/StardustXR/server/blob/0dc5b1a92f5707efa16c251602935bdfc47ee7f0/nix/stardust-xr-server.nix + CPM_SOURCE_CACHE = "./build"; + postPatch = '' + sk=$(echo $cargoDepsCopy/stereokit-sys-*/StereoKit) + mkdir -p $sk/build/cpm + + # This is not ideal, the original approach was to fetch the exact cmake + # file version that was wanted from GitHub directly, but at least this way it comes from Nixpkgs.. so meh + cp ${cpm-cmake}/share/cpm/CPM.cmake $sk/build/cpm/CPM_0.32.2.cmake + ''; + + meta = with lib; { + description = "WlxOverlay for OpenXR, written in Rust"; + homepage = "https://github.com/galister/wlx-overlay-x"; + license = licenses.gpl3Only; + platforms = platforms.linux; + maintainers = with maintainers; [Scrumplex]; + mainProgram = "wlx-overlay-x"; + }; +} diff --git a/nix/dev.nix b/nix/dev.nix new file mode 100644 index 0000000..84c51af --- /dev/null +++ b/nix/dev.nix @@ -0,0 +1,5 @@ +{ + perSystem = {pkgs, ...}: { + formatter = pkgs.alejandra; + }; +} diff --git a/nix/packages.nix b/nix/packages.nix new file mode 100644 index 0000000..7a7a816 --- /dev/null +++ b/nix/packages.nix @@ -0,0 +1,18 @@ +{self, ...}: let + version = builtins.substring 0 8 self.lastModifiedDate or "dirty"; +in { + perSystem = { + config, + pkgs, + ... + }: { + packages = { + default = config.packages.wlx-overlay-x; + wlx-overlay-x = pkgs.callPackage ./derivation.nix {inherit self version;}; + }; + }; + + flake.overlays.default = final: _: { + wlx-overlay-x = final.callPackage ./derivation.nix {inherit self version;}; + }; +}