From 0cb61384e9f20718198a30c76a60851ec87859d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Pluta?= Date: Sat, 9 Dec 2023 18:33:39 +0100 Subject: [PATCH] Migrate Nix shell config to Flake --- .envrc | 2 +- flake.lock | 27 +++++++++++++++++++++++++++ flake.nix | 42 ++++++++++++++++++++++++++++++++++++++++++ gradle.properties | 4 ++-- proto/build.gradle | 10 ++++++++-- shell.nix | 43 ------------------------------------------- 6 files changed, 80 insertions(+), 48 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix delete mode 100644 shell.nix diff --git a/.envrc b/.envrc index 1d953f4b..3550a30f 100644 --- a/.envrc +++ b/.envrc @@ -1 +1 @@ -use nix +use flake diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..c19674c1 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1701952659, + "narHash": "sha256-TJv2srXt6fYPUjxgLAL0cy4nuf1OZD4KuA1TrCiQqg0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b4372c4924d9182034066c823df76d6eaf1f4ec4", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..5de55cbb --- /dev/null +++ b/flake.nix @@ -0,0 +1,42 @@ +{ + description = "BASE engine"; + + inputs = { + nixpkgs.url = github:NixOS/nixpkgs/nixos-23.11; + }; + + outputs = { self, nixpkgs }: + let + pkgs = import nixpkgs { inherit system; }; + system = "x86_64-linux"; + opengl = "/run/opengl-driver"; + in { + devShells.${system}.default = with pkgs; mkShell { + name = "base-editor"; + + buildInputs = [ + xorg.libXtst + alsa-lib + gradle_7 + jdk17 + protobuf + ]; + + shellHook = '' + echo + echo + echo "======================================================================================================" + echo "Welcome to BASE NixOS flake shell environment" + echo "Remember to provide following LD environment variable in order to run application outside this shell:" + echo + echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" + echo "======================================================================================================" + echo + echo + ''; + + LD_LIBRARY_PATH = "${opengl}/lib:${xorg.libXtst}/lib:${alsa-lib}/lib"; + PROTOBUF_EXECUTABLE = "${protobuf}/bin/protoc"; + }; + }; +} diff --git a/gradle.properties b/gradle.properties index 3dab119e..3bf1fa34 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,10 +11,10 @@ javaFxPluginVersion=0.0.10 tornadoFxVersion=2.0.0-SNAPSHOT ikonliVersion=12.2.0 protobufPluginVersion=0.8.18 -protobufVersion=3.19.1 +protobufVersion=3.24.4 richtextfxVersion=0.10.7 janinoVersion=3.1.6 apacheCommonsVersion=3.6.1 h2Version=1.4.200 hikariVersion=5.0.0 -javaPoetVersion=1.13.0 \ No newline at end of file +javaPoetVersion=1.13.0 diff --git a/proto/build.gradle b/proto/build.gradle index f4cb6bfe..f6e9b6ab 100644 --- a/proto/build.gradle +++ b/proto/build.gradle @@ -29,7 +29,13 @@ sourceSets { protobuf { // Fetch protoc compiler protoc { - artifact = "com.google.protobuf:protoc:$protobufVersion" + def protobufExecutable = System.getenv("PROTOBUF_EXECUTABLE") + + if (protobufExecutable == null) { + artifact = "com.google.protobuf:protoc:$protobufVersion" + } else { + path = protobufExecutable + } } generatedFilesBaseDir = "$projectDir/build/proto/" @@ -42,4 +48,4 @@ protobuf { } } } -} \ No newline at end of file +} diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 49599481..00000000 --- a/shell.nix +++ /dev/null @@ -1,43 +0,0 @@ -{ pkgs ? import {} }: - -# Because of high dependency on native libraries like OpenGL and OpenAL -# on the NixOS the BASE engine requires few modifications. -# Basically this shell.nix could be enough, however the OpenGL is highly tied with the hardware, -# so the following change needs to be applied in the configuration.nix (or your flake configuration, whatever): -# hardware.opengl = { -# enable = true; -# extraPackages = with pkgs; [ -# libGL -# ]; -# setLdLibraryPath = true; -# }; -# -# Also for GNOME environments, the Editor requires the libglassgtk3.so library, -# so it is available via xorg.libXtst package mentioned already in the shell definition below. - -let - opengl = "/run/opengl-driver"; -in pkgs.mkShell { - name = "BASE NixOS runtime"; - - buildInputs = [ - pkgs.xorg.libXtst # Required by editor on GNOME environments (due to libglassgtk3.so dependency) - pkgs.alsa-lib # Either alsa or jack or pulseaudio library is required by game engine via OpenAL native library - ]; - - # OpenGL needs to be configured via /etc/nixos/configuration.nix - LD_LIBRARY_PATH = "${opengl}/lib:${pkgs.xorg.libXtst}/lib:${pkgs.alsa-lib}/lib"; - - shellHook = '' - echo - echo - echo "======================================================================================================" - echo "Welcome to BASE NixOS shell environment" - echo "Remember to provide following LD environment variable in order to run application outside this shell:" - echo - echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" - echo "======================================================================================================" - echo - echo - ''; -}