Skip to content

Commit

Permalink
feat: add nix dev environment
Browse files Browse the repository at this point in the history
  • Loading branch information
oddlama committed May 13, 2024
1 parent 35d887d commit 0e84be3
Show file tree
Hide file tree
Showing 6 changed files with 279 additions and 5 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
env.sh
.gradle
.classpath
.direnv
.project
.settings
.idea
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
196 changes: 196 additions & 0 deletions flake.lock

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

69 changes: 69 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
inputs = {
devshell = {
url = "github:numtide/devshell";
inputs.nixpkgs.follows = "nixpkgs";
};

flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
};

outputs = {
self,
devshell,
flake-utils,
nixpkgs,
pre-commit-hooks,
}:
flake-utils.lib.eachDefaultSystem (
localSystem: let
pkgs = import nixpkgs {
inherit localSystem;
overlays = [devshell.overlays.default];
};
in {
checks.pre-commit = pre-commit-hooks.lib.${localSystem}.run {
src = ./.;
hooks = {
alejandra.enable = true;
statix.enable = true;
};
};

# `nix develop`
devShells.default = pkgs.devshell.mkShell {
name = "vane";

commands = [
{
package = pkgs.alejandra;
help = "Format nix code";
}
{
package = pkgs.statix;
help = "Lint nix code";
}
{
package = pkgs.deadnix;
help = "Find unused expressions in nix code";
}
];

devshell.startup.pre-commit.text = self.checks.${localSystem}.pre-commit.shellHook;
packages = [
pkgs.temurin-bin-17
(pkgs.gradle.override {java = pkgs.temurin-bin-17;})
];
};

formatter = pkgs.alejandra; # `nix fmt`
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -103,7 +104,7 @@ public ProxyServer get_proxy() {
}

public void try_start_server(ManagedServer server) {
// FIXME: this is not async-safe and there might be conditions where two start commands can be executed
// FIXME: this is not async-safe and there might be conditions where two start commands can be executed
// simultaneously. Don't rely on this as a user - instead use a start command that is atomic.
if (server_starting) return;

Expand All @@ -113,18 +114,23 @@ public void try_start_server(ManagedServer server) {
() -> {
try {
server_starting = true;
get_logger().log(Level.INFO, "Running start command for server " + server.id());
System.out.println("run start cmd for " + server.id() + ": " + server.start_cmd());
get_logger().log(Level.INFO, "Running start command for server '" + server.id() + "': " + Arrays.toString(server.start_cmd()));
final var timeout = server.command_timeout();
final var process = Runtime.getRuntime().exec(server.start_cmd());

final var processBuilder = new ProcessBuilder(server.start_cmd());
processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
final var process = processBuilder.start();

if (!process.waitFor(timeout, TimeUnit.SECONDS)) {
get_logger().log(
Level.SEVERE,
"Server '"
+ server.id()
+ "'s start command timed out!");
} else if (process.exitValue() != 0) {
}

if (process.exitValue() != 0) {
get_logger().log(
Level.SEVERE,
"Server '"
Expand Down

0 comments on commit 0e84be3

Please sign in to comment.