Skip to content

Commit

Permalink
feat: add nix flake (#631)
Browse files Browse the repository at this point in the history
  • Loading branch information
brizzbuzz committed Aug 15, 2024
1 parent 01c4e05 commit ee56c80
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.gradle
build
.idea
.direnv
64 changes: 64 additions & 0 deletions flake.lock

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

29 changes: 29 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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
];
};
});
}
17 changes: 17 additions & 0 deletions update-locks.nix
Original file line number Diff line number Diff line change
@@ -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
''

0 comments on commit ee56c80

Please sign in to comment.