From 058a7d7a7d3ee5f7df29f31753a84fc26c027013 Mon Sep 17 00:00:00 2001 From: B10P0K3 <44468142+h1sk1@users.noreply.github.com> Date: Fri, 19 Jul 2024 11:48:30 +0800 Subject: [PATCH] Add nix flake build script (#322) --- flake.nix | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 flake.nix diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..e42683b5d --- /dev/null +++ b/flake.nix @@ -0,0 +1,47 @@ +{ + description = "A Scala project with SBT"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + }; + sbt = pkgs.sbt; + jdk = pkgs.jdk21; + scala = pkgs.scala; + in { + devShell = pkgs.mkShell { + buildInputs = [ sbt jdk scala ]; + shellHook = '' + echo "SBT and Scala environment ready!" + ''; + }; + + packages.default = pkgs.stdenv.mkDerivation { + name = "flake-vsys-build-with-sbt"; + src = ./.; + buildInputs = [ sbt jdk scala ]; + buildPhase = '' + echo "Building with SBT..." + + sed -i 's/scalaVersion in ThisBuild := "2.12.6"/scalaVersion in ThisBuild := "2.12.18"/' build.sbt + sed -i 's/sbt.version=1.1.1/sbt.version=1.9.9/' project/build.properties + + export HOME=~ + + sbt packageAll + ''; + installPhase = '' + mkdir -p $out + cp -r target $out + ''; + }; + } + ); +}