Skip to content

Commit

Permalink
build: add flake (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
adfaure authored Apr 30, 2024
1 parent 017ea90 commit 249ec7f
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
27 changes: 27 additions & 0 deletions flake.lock

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

45 changes: 45 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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;
});
};
}

0 comments on commit 249ec7f

Please sign in to comment.