mirror of
https://github.com/HendrikRauh/inventree-app.git
synced 2026-02-04 05:43:18 +00:00
Add Nix configuration files and script for Flutter version management
This commit is contained in:
parent
ae457e8235
commit
8f18e328e0
5 changed files with 247 additions and 0 deletions
4
.envrc
Normal file
4
.envrc
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# When nix is available, use the flake for environment management
|
||||
if command -v nix &> /dev/null; then
|
||||
use flake
|
||||
fi
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -6,8 +6,10 @@
|
|||
.DS_Store
|
||||
.atom/
|
||||
.buildlog/
|
||||
.direnv
|
||||
.history
|
||||
.svn/
|
||||
flake.nix.bak
|
||||
|
||||
coverage/*
|
||||
|
||||
|
|
|
|||
78
flake.lock
generated
Normal file
78
flake.lock
generated
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1769170682,
|
||||
"narHash": "sha256-oMmN1lVQU0F0W2k6OI3bgdzp2YOHWYUAw79qzDSjenU=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "c5296fdd05cfa2c187990dd909864da9658df755",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-flutter": {
|
||||
"locked": {
|
||||
"lastModified": 1751285371,
|
||||
"narHash": "sha256-/hDU+2AUeFFu5qGHO/UyFMc4UG/x5Cw5uXO36KGTk6c=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "b9c03fbbaf84d85bb28eee530c7e9edc4021ca1b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "b9c03fbbaf84d85bb28eee530c7e9edc4021ca1b",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"nixpkgs-flutter": "nixpkgs-flutter"
|
||||
}
|
||||
},
|
||||
"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
|
||||
}
|
||||
109
flake.nix
Normal file
109
flake.nix
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
{
|
||||
description = "InvenTree App Development Environment";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
nixpkgs-flutter.url = "github:NixOS/nixpkgs/b9c03fbbaf84d85bb28eee530c7e9edc4021ca1b";
|
||||
};
|
||||
|
||||
outputs =
|
||||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
flake-utils,
|
||||
nixpkgs-flutter,
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (
|
||||
system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
config = {
|
||||
allowUnfree = true;
|
||||
android_sdk.accept_license = true;
|
||||
};
|
||||
overlays = [
|
||||
(final: prev: {
|
||||
flutter-pkg = import (self.inputs.nixpkgs-flutter) { inherit system; };
|
||||
})
|
||||
];
|
||||
};
|
||||
|
||||
androidSdk =
|
||||
(pkgs.androidenv.composeAndroidPackages {
|
||||
platformVersions = [
|
||||
"35"
|
||||
"34"
|
||||
];
|
||||
buildToolsVersions = [
|
||||
"35.0.0"
|
||||
"34.0.0"
|
||||
];
|
||||
includeNDK = true;
|
||||
ndkVersions = [ "26.1.10909125" ];
|
||||
cmakeVersions = [ "3.22.1" ];
|
||||
}).androidsdk;
|
||||
|
||||
linuxOptionals = with pkgs; [
|
||||
gtk3
|
||||
glib
|
||||
pcre
|
||||
libepoxy
|
||||
libxkbcommon
|
||||
dbus
|
||||
at-spi2-core
|
||||
file
|
||||
];
|
||||
|
||||
fvmScript = ''
|
||||
case "$1" in
|
||||
use)
|
||||
echo "✓ Using Flutter from Nix ($(flutter --version | head -n1))"
|
||||
exit 0
|
||||
;;
|
||||
flutter)
|
||||
shift
|
||||
exec flutter "$@"
|
||||
;;
|
||||
*)
|
||||
echo "fvm wrapper: command '$1' not implemented (using Nix-managed Flutter)" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
'';
|
||||
fvm-wrapper = pkgs.writeShellScriptBin "fvm" fvmScript;
|
||||
in
|
||||
{
|
||||
devShells.default = pkgs.mkShell {
|
||||
buildInputs =
|
||||
with pkgs;
|
||||
[
|
||||
flutter-pkg.flutter
|
||||
fvm-wrapper
|
||||
jdk17
|
||||
android-tools
|
||||
gradle
|
||||
python3
|
||||
python3Packages.invoke
|
||||
jq
|
||||
git
|
||||
curl
|
||||
unzip
|
||||
which
|
||||
]
|
||||
++ lib.optionals stdenv.isLinux linuxOptionals;
|
||||
|
||||
shellHook = ''
|
||||
export ANDROID_HOME="${androidSdk}/libexec/android-sdk"
|
||||
export ANDROID_SDK_ROOT="$ANDROID_HOME"
|
||||
export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools/bin:$PATH"
|
||||
export JAVA_HOME="${pkgs.jdk17}"
|
||||
export GRADLE_OPTS="-Dorg.gradle.project.android.aapt2FromMavenOverride=$ANDROID_HOME/build-tools/35.0.0/aapt2"
|
||||
'';
|
||||
|
||||
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath (with pkgs; linuxOptionals);
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
54
update-flutter-nix.sh
Executable file
54
update-flutter-nix.sh
Executable file
|
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# This script adjusts flake.nix to use the flutter version
|
||||
# pinned in .fvmrc. It fetches the appropriate commit hash.
|
||||
|
||||
set -e
|
||||
|
||||
for cmd in jq curl sed nix; do
|
||||
command -v $cmd >/dev/null 2>&1 || { echo "Error: $cmd is not installed!"; exit 1; }
|
||||
done
|
||||
|
||||
if [ ! -f .fvmrc ]; then
|
||||
echo ".fvmrc file not found!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
FLUTTER_VERSION=$(jq -r .flutter .fvmrc)
|
||||
echo "Requested Flutter version: $FLUTTER_VERSION"
|
||||
|
||||
API_URL="https://search.devbox.sh/v2/pkg?name=flutter"
|
||||
RELEASES_JSON=$(curl -s "$API_URL")
|
||||
|
||||
ALL_VERSIONS=$(echo "$RELEASES_JSON" | jq -r '.releases[].version' | sort -V)
|
||||
|
||||
FOUND_VERSION=$(echo "$ALL_VERSIONS" | awk -v v="$FLUTTER_VERSION" '$0 >= v { print; exit }')
|
||||
|
||||
if [ -z "$FOUND_VERSION" ]; then
|
||||
echo "Error: No matching Flutter version found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$FOUND_VERSION" != "$FLUTTER_VERSION" ]; then
|
||||
echo "Note: Exact version not found, using version $FOUND_VERSION instead."
|
||||
fi
|
||||
|
||||
COMMIT=$(echo "$RELEASES_JSON" | jq -r --arg v "$FOUND_VERSION" '.releases[] | select(.version==$v) | .platforms[] | select(.system=="x86_64-linux") | .commit_hash' | head -n 1)
|
||||
|
||||
if [ -z "$COMMIT" ] || [ "$COMMIT" == "null" ]; then
|
||||
echo "Error: No commit hash found for version $FOUND_VERSION and platform x86_64-linux."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Found commit: $COMMIT (Version: $FOUND_VERSION)"
|
||||
|
||||
|
||||
sed -i.bak "s|nixpkgs-flutter.url = \"github:NixOS/nixpkgs/[a-f0-9]*\";|nixpkgs-flutter.url = \"github:NixOS/nixpkgs/$COMMIT\";|" flake.nix
|
||||
|
||||
nix flake update nixpkgs-flutter
|
||||
|
||||
if command -v direnv >/dev/null 2>&1; then
|
||||
direnv reload
|
||||
fi
|
||||
|
||||
echo "Success! flake.nix now uses the commit for Flutter $FLUTTER_VERSION (or higher)."
|
||||
Loading…
Add table
Add a link
Reference in a new issue