diff --git a/.envrc b/.envrc new file mode 100644 index 000000000..e7d458b18 --- /dev/null +++ b/.envrc @@ -0,0 +1,10 @@ +if ! has nix_direnv_version || ! nix_direnv_version 3.0.5; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.5/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs=" +fi + +watch_file flake.nix +watch_file flake.lock +if ! use flake . --impure +then + echo "Flake could not be used... something is broken :(" >&2 +fi diff --git a/.gitignore b/.gitignore index d49a8b533..56cf95e80 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .gradle build .idea +.direnv diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..e0920ed39 --- /dev/null +++ b/flake.lock @@ -0,0 +1,64 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": [ + "systems" + ] + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1723362943, + "narHash": "sha256-dFZRVSgmJkyM0bkPpaYRtG/kRMRTorUIDj8BxoOt1T4=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "a58bc8ad779655e790115244571758e8de055e3d", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..9c49c0d2d --- /dev/null +++ b/flake.nix @@ -0,0 +1,29 @@ +{ + description = "Minimal example of building Kotlin with Gradle and Nix"; + + inputs = {nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";}; + + inputs.systems.url = "github:nix-systems/default"; + + inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs.flake-utils.inputs.systems.follows = "systems"; + + outputs = { + nixpkgs, + flake-utils, + ... + }: + flake-utils.lib.eachDefaultSystem (system: let + pkgs = import nixpkgs {inherit system;}; + updateLocks = pkgs.callPackage ./update-locks.nix {}; + in { + devShells.default = pkgs.mkShell { + buildInputs = with pkgs; [ + gradle_8 + temurin-bin-21 + updateLocks + ktlint + ]; + }; + }); +} diff --git a/update-locks.nix b/update-locks.nix new file mode 100644 index 000000000..62d81458e --- /dev/null +++ b/update-locks.nix @@ -0,0 +1,17 @@ +{ + writeShellScriptBin, + gradle, + yq, +}: +writeShellScriptBin "update-locks" '' + set -eu -o pipefail + ${gradle}/bin/gradle dependencies --write-locks + ${gradle}/bin/gradle --write-verification-metadata sha256 dependencies + ${yq}/bin/xq ' + ."verification-metadata".components.component | + map({ group: ."@group", name: ."@name", version: ."@version", + artifacts: [([.artifact] | flatten | .[] | {(."@name"): .sha256."@value"})] | add + }) + ' gradle/verification-metadata.xml > deps.json + rm gradle/verification-metadata.xml +''