buildDartApplication: Allow reading pubspec.lock with IFD
This commit is contained in:
parent
cf53751a16
commit
778cefd464
2 changed files with 23 additions and 3 deletions
|
@ -11,6 +11,18 @@ If you are packaging a Flutter desktop application, use [`buildFlutterApplicatio
|
||||||
`pubspecLock` is the parsed pubspec.lock file. pub2nix uses this to download required packages.
|
`pubspecLock` is the parsed pubspec.lock file. pub2nix uses this to download required packages.
|
||||||
This can be converted to JSON from YAML with something like `yq . pubspec.lock`, and then read by Nix.
|
This can be converted to JSON from YAML with something like `yq . pubspec.lock`, and then read by Nix.
|
||||||
|
|
||||||
|
Alternatively, `autoPubspecLock` can be used instead, and set to a path to a regular `pubspec.lock` file. This relies on import-from-derivation, and is not permitted in Nixpkgs, but can be useful at other times.
|
||||||
|
|
||||||
|
::: {.warning}
|
||||||
|
When using `autoPubspecLock` with a local source directory, make sure to use a
|
||||||
|
concatenation operator (e.g. `autoPubspecLock = ${src} + "/pubspec.lock";`), and
|
||||||
|
not string interpolation.
|
||||||
|
|
||||||
|
String interpolation will copy your entire source directory to the Nix store and
|
||||||
|
use its store path, meaning that unrelated changes to your source tree will
|
||||||
|
cause the generated `pubspec.lock` derivation to rebuild!
|
||||||
|
:::
|
||||||
|
|
||||||
If the package has Git package dependencies, the hashes must be provided in the `gitHashes` set. If a hash is missing, an error message prompting you to add it will be shown.
|
If the package has Git package dependencies, the hashes must be provided in the `gitHashes` set. If a hash is missing, an error message prompting you to add it will be shown.
|
||||||
|
|
||||||
The `dart` commands run can be overridden through `pubGetScript` and `dartCompileCommand`, you can also add flags using `dartCompileFlags` or `dartJitFlags`.
|
The `dart` commands run can be overridden through `pubGetScript` and `dartCompileCommand`, you can also add flags using `dartCompileFlags` or `dartJitFlags`.
|
||||||
|
@ -101,8 +113,8 @@ flutter.buildFlutterApplication {
|
||||||
|
|
||||||
pubspecLock = lib.importJSON ./pubspec.lock.json;
|
pubspecLock = lib.importJSON ./pubspec.lock.json;
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Usage with nix-shell {#ssec-dart-flutter-nix-shell}
|
### Usage with nix-shell {#ssec-dart-flutter-nix-shell}
|
||||||
|
|
||||||
See the [Dart documentation](#ssec-dart-applications-nix-shell) nix-shell instructions.
|
See the [Dart documentation](#ssec-dart-applications-nix-shell) for nix-shell instructions.
|
||||||
```
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{ lib
|
{ lib
|
||||||
, stdenv
|
, stdenv
|
||||||
, callPackage
|
, callPackage
|
||||||
|
, runCommand
|
||||||
, writeText
|
, writeText
|
||||||
, pub2nix
|
, pub2nix
|
||||||
, dartHooks
|
, dartHooks
|
||||||
|
@ -9,6 +10,7 @@
|
||||||
, nodejs
|
, nodejs
|
||||||
, darwin
|
, darwin
|
||||||
, jq
|
, jq
|
||||||
|
, yq
|
||||||
}:
|
}:
|
||||||
|
|
||||||
{ src
|
{ src
|
||||||
|
@ -44,7 +46,13 @@
|
||||||
|
|
||||||
, runtimeDependencies ? [ ]
|
, runtimeDependencies ? [ ]
|
||||||
, extraWrapProgramArgs ? ""
|
, extraWrapProgramArgs ? ""
|
||||||
, pubspecLock
|
|
||||||
|
, autoPubspecLock ? null
|
||||||
|
, pubspecLock ? if autoPubspecLock == null then
|
||||||
|
throw "The pubspecLock argument is required. If import-from-derivation is allowed (it isn't in Nixpkgs), you can set autoPubspecLock to the path to a pubspec.lock instead."
|
||||||
|
else
|
||||||
|
assert lib.assertMsg (builtins.pathExists autoPubspecLock) "The pubspec.lock file could not be found!";
|
||||||
|
lib.importJSON (runCommand "${lib.getName args}-pubspec-lock-json" { nativeBuildInputs = [ yq ]; } ''yq . '${autoPubspecLock}' > "$out"'')
|
||||||
, ...
|
, ...
|
||||||
}@args:
|
}@args:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue