Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reproducible dev environment with Nix #40

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
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
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ __pycache__/

# JetBrains
.idea

# Nix
result
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
61 changes: 61 additions & 0 deletions flake.lock

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

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