diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..21fdc40 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1713725259, + "narHash": "sha256-9ZR/Rbx5/Z/JZf5ehVNMoz/s5xjpP0a22tL6qNvLt5E=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a5e4bbcb4780c63c79c87d29ea409abf097de3f7", + "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 0000000..4055adf --- /dev/null +++ b/flake.nix @@ -0,0 +1,45 @@ +{ + # Adapted from: https://github.com/the-nix-way/dev-templates/blob/main/kotlin/flake.nix + description = "A Nix-flake-based Kotlin development environment"; + + inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; }; + + outputs = { self, nixpkgs }: + let + javaVersion = 20; + # Some overlay to inject your dependencies (pkgs.jdk, pkgs.gradle, pkgs.kotlin) should be defined + overlays = [ + (final: prev: rec { + jdk = prev."jdk${toString javaVersion}"; + gradle = prev.gradle.override { java = jdk; }; + kotlin = prev.kotlin.override { jre = jdk; }; + }) + ]; + supportedSystems = + [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; + forEachSupportedSystem = f: + nixpkgs.lib.genAttrs supportedSystems + (system: f { pkgs = import nixpkgs { inherit system; }; }); + in { + devShells = forEachSupportedSystem ({ pkgs }: { + # https://ryantm.github.io/nixpkgs/builders/special/fhs-environments/#sec-fhs-environments + # WARNING! As I understand, with this configuration your shell will be running in a namespace. + # It isolates the filesystem (or at least a part of the filesystem) to behave as a standard + # FHS system. gradlew should work normally, thus handling all your dependencies by itself. + # With this configuration, your only required dependency is the jdk17. + # Thus it is not a packaging flake, but rather a flake to enable development for your tool. + default = (pkgs.buildFHSUserEnv { + name = "java-dev-env"; + targetPkgs = pkgs: + with pkgs; [ + jdk17 + # Gradle for building containers + gradle + # For the cli + docker-compose + ]; + runScript = "bash"; + }).env; + }); + }; +}