diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 26449f6..a644f79 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,6 +65,17 @@ jobs: - name: build run: bazel --bazelrc=.github/workflows/bazelrc build //:krpc2 + build-krpc2-nix-linux: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v3 + - uses: cachix/install-nix-action@v19 + - run: nix flake check + # TODO: We can add the build to a cache for others (see cachix.org) + # It's free for FOSS. + - run: nix build .#krpc2 + build-krpc2-sln-linux: runs-on: ubuntu-latest container: diff --git a/.gitignore b/.gitignore index 1563a96..73c5260 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,6 @@ __pycache__/ # JetBrains .idea + +# Nix +result diff --git a/README.md b/README.md index cbd1fd6..3424209 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,12 @@ Also check out the [contribution guide](https://github.com/krpc/krpc/blob/main/C * Run `bazel build //:krpc2` * The resulting plugin archive is placed in `bazel-bin/krpc2-VERSION.zip` +### Developing with Nix + +To install dependencies and start a development environment with Nix, run `nix develop`. +This will install all the required programs, from there configure your system to build as on a regular Linux system. +Running `nix build .#krpc2` will build your active source against the stripped compilation libraries used in continuous integration. + ## Building on Windows Using Bazel: diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..52b3a02 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1681037374, + "narHash": "sha256-XL6X3VGbEFJZDUouv2xpKg2Aljzu/etPLv5e1FPt1q0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "033b9f258ca96a10e543d4442071f614dc3f8412", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1681154110, + "narHash": "sha256-OQwWzlzAY1dCqgSsgZzsPIOGmX4pBGaoXOy0rSl4b5Y=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "115a96e2ac1e92937cd47c30e073e16dcaaf6247", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-22.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..62a6abc --- /dev/null +++ b/flake.nix @@ -0,0 +1,83 @@ +{ + description = "Remote Procedure Calls for Kerbal Space Program 2"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + # Flake supports just Linux for now + flake-utils.lib.eachSystem [ "x86_64-linux" ] (system: + let + ksp2-version = "ksp2-0.1.1"; + pkgs = import nixpkgs { + inherit system; + # Required for steam deps. + config.allowUnfree = true; + }; + # We wrap Bazel here for NixOS support which does not have the standard + # FHS. NOTE: This should also act as an environment regularizing command + # on other OSes, but may make inital build times a bit longer. + wrapped-bazel = pkgs.bazel_6.overrideAttrs (old: { + doCheck = false; + doInstallCheck = false; + postFixup = '' + mv $out/bin/bazel $out/bin/bazel-raw + echo '#!${pkgs.stdenv.shell}' > $out/bin/bazel + echo "${pkgs.steam-run}/bin/steam-run $out/bin/bazel-raw \$@" >> $out/bin/bazel + chmod +x $out/bin/bazel + ''; + }); + stripped-krpc = pkgs.fetchzip { + url = "https://github.com/krpc/ksp-lib/raw/main/ksp2/${ksp2-version}.zip"; + sha256 = "sha256-Byyn9CZBO364NIJHeJfeJnM4J11ZY/jDxfQZNdS0CCA="; + }; + in + rec { + devShells.default = with pkgs; + pkgs.mkShell { + packages = [ + # build + dotnet-sdk_6 + jdk11 + wrapped-bazel + # lint + buildifier + # steam + steam + steam-run + ]; + STEAM_RUN_WRAPPER = "${steam-run}/bin/steam-run"; + }; + + packages.krpc2 = pkgs.buildBazelPackage { + name = "krpc2-dev"; + pname = "krpc2"; + bazel = wrapped-bazel; + bazelTarget = ":plugin_files"; + nativeBuildInputs = [ + pkgs.git + ]; + src = ./.; + # NOTE: Update on change to bazel fetch deps. + fetchAttrs = { + sha256 = "sha256-YaT+xVd0ywE4l/ZnI3ZiI+f5NawE161dJdcMAklR80o="; + }; + patchPhase = '' + # Copied directory, so will not influence local symlinks. + ln -sf ${stripped-krpc} lib/ksp2 + mv lib/ksp2 lib/KSP2_x64_Data + mkdir -p lib/ksp2 + mv lib/KSP2_x64_Data lib/ksp2/ + ''; + buildAttrs = { + installPhase = '' + mkdir -p $out/lib + install -Dm0755 bazel-bin/kRPC2/* $out/lib/ + ''; + }; + }; + packages.default = packages.krpc2; + }); +}