From db6cb63065990fd5944050a70d14e3316a39f116 Mon Sep 17 00:00:00 2001 From: dylan madisetti Date: Wed, 5 Apr 2023 23:11:33 -0400 Subject: [PATCH 1/8] Added Nix flake for dev --- README.md | 4 ++++ flake.nix | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 flake.nix diff --git a/README.md b/README.md index cbd1fd6..197fc57 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,10 @@ 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. + ## Building on Windows Using Bazel: diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..e191a62 --- /dev/null +++ b/flake.nix @@ -0,0 +1,53 @@ +{ + description = "Remote Procedure Calls for Kerbal Space Program 2"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/master"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + config.allowUnfree = true; + }; + bazel = pkgs.bazel_5; + wrapped-bazel = pkgs.writeShellScriptBin "bazel" '' + ${pkgs.steam-run}/bin/steam-run ${bazel}/bin/bazel $@ + ''; + in + rec { + devShells.default = with pkgs; + pkgs.mkShell { + packages = [ + # build + wrapped-bazel + jdk11 + # lint + buildifier + dotnet-sdk_7 + # steam + steam + steam-run + ]; + STEAM_RUN_WRAPPER = "${steam-run}/bin/steam-run"; + }; + + packages.krpc = pkgs.buildBazelPackage { + name = "krpc2-dev"; + pname = "krpc"; + bazel = wrapped-bazel; + nativeBuildInputs = [ + pkgs.git + ]; + bazelTarget = ":plugin_files"; + src = ./.; + fetchAttrs = { + sha256 = "sha256-0TynZKODPXK5DZwB8bNWX8vDSyFi5syWVB0QZIue92E="; + }; + }; + packages.default = packages.krpc; + }); +} From da0eb44c9ff45f473245e09ad4f01baad712d710 Mon Sep 17 00:00:00 2001 From: dylan madisetti Date: Mon, 10 Apr 2023 19:07:36 -0400 Subject: [PATCH 2/8] Added CI for Nix --- .github/workflows/ci.yml | 11 +++++++ .gitignore | 4 +++ README.md | 4 ++- flake.nix | 66 ++++++++++++++++++++++++++++------------ 4 files changed, 65 insertions(+), 20 deletions(-) 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..0c19d2a 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,7 @@ __pycache__/ # JetBrains .idea + +# Nix +result +flake.lock diff --git a/README.md b/README.md index 197fc57..3424209 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,9 @@ Also check out the [contribution guide](https://github.com/krpc/krpc/blob/main/C ### Developing with Nix -To install dependencies and start a development environment with Nix, run `nix develop`. This will install all the required programs. +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 diff --git a/flake.nix b/flake.nix index e191a62..cd1252f 100644 --- a/flake.nix +++ b/flake.nix @@ -7,27 +7,41 @@ }; outputs = { self, nixpkgs, flake-utils }: - flake-utils.lib.eachDefaultSystem (system: + # 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; }; - bazel = pkgs.bazel_5; - wrapped-bazel = pkgs.writeShellScriptBin "bazel" '' - ${pkgs.steam-run}/bin/steam-run ${bazel}/bin/bazel $@ + # 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: { + postInstall = '' + 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 - wrapped-bazel + dotnet-sdk_6 jdk11 + wrapped-bazel # lint buildifier - dotnet-sdk_7 # steam steam steam-run @@ -35,19 +49,33 @@ STEAM_RUN_WRAPPER = "${steam-run}/bin/steam-run"; }; - packages.krpc = pkgs.buildBazelPackage { - name = "krpc2-dev"; - pname = "krpc"; - bazel = wrapped-bazel; - nativeBuildInputs = [ - pkgs.git - ]; - bazelTarget = ":plugin_files"; - src = ./.; - fetchAttrs = { - sha256 = "sha256-0TynZKODPXK5DZwB8bNWX8vDSyFi5syWVB0QZIue92E="; - }; + packages.krpc2 = pkgs.buildBazelPackage { + name = "krpc2-dev"; + pname = "krpc2"; + bazel = wrapped-bazel; + bazelTarget = ":plugin_files"; + src = ./.; + # NOTE: Update on change to bazel fetch deps. + fetchAttrs = { + sha256 = "sha256-5cw0OjkrfoYwtC1rOnBtapqvigUSb7MT1Z+SFGcEtk4="; }; - packages.default = packages.krpc; + 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 = { + dontUseCmakeConfigure = true; + dontUseGnConfigure = true; + dontUseNinjaInstall = true; + installPhase = '' + mkdir -p $out/lib + install -Dm0755 bazel-bin/kRPC2/* $out/lib/ + ''; + }; + }; + packages.default = packages.krpc2; }); } From 1305d89098e3532e9a73e67c937d7f6b1f7a546d Mon Sep 17 00:00:00 2001 From: dylan madisetti Date: Mon, 10 Apr 2023 19:10:01 -0400 Subject: [PATCH 3/8] Remove flake.lock from .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0c19d2a..73c5260 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,3 @@ __pycache__/ # Nix result -flake.lock From 8f7a3609fa36cbacec2074b5d736210302e5e52b Mon Sep 17 00:00:00 2001 From: dylan madisetti Date: Mon, 10 Apr 2023 19:16:22 -0400 Subject: [PATCH 4/8] Pin pkgs to 22.11 --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index cd1252f..03b4fbf 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,7 @@ description = "Remote Procedure Calls for Kerbal Space Program 2"; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/master"; + nixpkgs.url = "github:NixOS/nixpkgs/22.11"; flake-utils.url = "github:numtide/flake-utils"; }; From a540a4262b422c3f626543c72ed258eb6f8e0cb5 Mon Sep 17 00:00:00 2001 From: dylan madisetti Date: Mon, 10 Apr 2023 22:29:49 -0400 Subject: [PATCH 5/8] Added back git dependency --- flake.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 03b4fbf..d9455cb 100644 --- a/flake.nix +++ b/flake.nix @@ -20,7 +20,7 @@ # 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: { - postInstall = '' + 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 @@ -54,6 +54,9 @@ pname = "krpc2"; bazel = wrapped-bazel; bazelTarget = ":plugin_files"; + nativeBuildInputs = [ + pkgs.git + ]; src = ./.; # NOTE: Update on change to bazel fetch deps. fetchAttrs = { From cee6c46cd797c6cf3f44f9b16e9c1ef52ed0b51b Mon Sep 17 00:00:00 2001 From: dylan madisetti Date: Wed, 12 Apr 2023 00:24:51 -0400 Subject: [PATCH 6/8] Added lock file to commit to stable bazel --- flake.lock | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 11 +++++----- 2 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 flake.lock 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 index d9455cb..ff8b101 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,7 @@ description = "Remote Procedure Calls for Kerbal Space Program 2"; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/22.11"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11"; flake-utils.url = "github:numtide/flake-utils"; }; @@ -19,7 +19,9 @@ # 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: { + wrapped-bazel = pkgs.bazel_5.overrideAttrs (old: { + doCheck = false; + doInstallCheck = false; postFixup = '' mv $out/bin/bazel $out/bin/bazel-raw echo '#!${pkgs.stdenv.shell}' > $out/bin/bazel @@ -60,7 +62,7 @@ src = ./.; # NOTE: Update on change to bazel fetch deps. fetchAttrs = { - sha256 = "sha256-5cw0OjkrfoYwtC1rOnBtapqvigUSb7MT1Z+SFGcEtk4="; + sha256 = "sha256-ce20qIEBO0JyQWvOrt/mLGSH0PLIHtdGjdMJkBG13Ws="; }; patchPhase = '' # Copied directory, so will not influence local symlinks. @@ -70,9 +72,6 @@ mv lib/KSP2_x64_Data lib/ksp2/ ''; buildAttrs = { - dontUseCmakeConfigure = true; - dontUseGnConfigure = true; - dontUseNinjaInstall = true; installPhase = '' mkdir -p $out/lib install -Dm0755 bazel-bin/kRPC2/* $out/lib/ From 8592a73d1237abfec2fee4e22e525babbdde5e0a Mon Sep 17 00:00:00 2001 From: dylan madisetti Date: Wed, 12 Apr 2023 00:42:20 -0400 Subject: [PATCH 7/8] Bumpt o bazel 6 --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index ff8b101..018981f 100644 --- a/flake.nix +++ b/flake.nix @@ -19,7 +19,7 @@ # 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_5.overrideAttrs (old: { + wrapped-bazel = pkgs.bazel_6.overrideAttrs (old: { doCheck = false; doInstallCheck = false; postFixup = '' From 547335863a456fed1fa84ae2e992b10a4fb5d9d6 Mon Sep 17 00:00:00 2001 From: dylan madisetti Date: Wed, 12 Apr 2023 01:12:24 -0400 Subject: [PATCH 8/8] update hash --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 018981f..62a6abc 100644 --- a/flake.nix +++ b/flake.nix @@ -62,7 +62,7 @@ src = ./.; # NOTE: Update on change to bazel fetch deps. fetchAttrs = { - sha256 = "sha256-ce20qIEBO0JyQWvOrt/mLGSH0PLIHtdGjdMJkBG13Ws="; + sha256 = "sha256-YaT+xVd0ywE4l/ZnI3ZiI+f5NawE161dJdcMAklR80o="; }; patchPhase = '' # Copied directory, so will not influence local symlinks.