feat: add Nix flake for dev environment
Provide a reproducible dev shell with JDK 17 and Maven 3.9.x. JDK 17 (LTS) is used since JDK 16 (project target) is non-LTS and unavailable in nixpkgs; it is fully backward-compatible with --source 16 --target 16. Maven is overridden via overlay to use the same JDK.
This commit is contained in:
48
flake.nix
Normal file
48
flake.nix
Normal file
@@ -0,0 +1,48 @@
|
||||
{
|
||||
description = "new-shapes - Java Swing shape editor";
|
||||
|
||||
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
|
||||
outputs = { self, nixpkgs }:
|
||||
let
|
||||
# JDK 16 (project target) is non-LTS and unavailable in nixpkgs.
|
||||
# JDK 17 (LTS) is fully backward-compatible with --source 16 --target 16.
|
||||
javaVersion = 17;
|
||||
|
||||
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
|
||||
|
||||
forEachSystem = f:
|
||||
nixpkgs.lib.genAttrs supportedSystems (system: f {
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [ self.overlays.default ];
|
||||
};
|
||||
});
|
||||
in
|
||||
{
|
||||
overlays.default = final: prev:
|
||||
let
|
||||
jdk = prev."jdk${toString javaVersion}";
|
||||
in
|
||||
{
|
||||
inherit jdk;
|
||||
# Override Maven to use the same JDK version
|
||||
maven = prev.maven.override { jdk_headless = jdk; };
|
||||
};
|
||||
|
||||
devShells = forEachSystem ({ pkgs }: {
|
||||
default = pkgs.mkShell {
|
||||
packages = with pkgs; [
|
||||
jdk
|
||||
maven
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
echo "new-shapes dev shell"
|
||||
echo " Java: $(java -version 2>&1 | head -1)"
|
||||
echo " Maven: $(mvn -version 2>&1 | head -1)"
|
||||
'';
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user