Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 89 additions & 5 deletions nix/dart/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
}@args:
importingFlake: {
imports = [
(importApply ./devshell.nix args)
(importApply ./sdk.nix args)
./workflow.nix
];

options.perSystem = flake-parts-lib.mkPerSystemOption ({
Expand All @@ -15,18 +17,100 @@ importingFlake: {
Dart projects in the repository that should be equipped with our
standards.

This must be a relative path starting with `.`. Simply use `.` if the
whole project is a Dart project.
The attribute key is the project's relative path, starting with `.`.
Simply use `.` if the whole repository is a single Dart project.

Setting this generates a `dart-ci` GitHub Actions workflow with a
lint job per project (and optional test/coverage jobs).
'';
default = { };

example = ''
example = lib.literalExpression ''
{
"." = { };
"." = {
sdk = "flutter";
test = true;
coverage = true;
};
}
'';

type = lib.types.attrsOf (lib.types.submodule { });
type = lib.types.attrsOf (
lib.types.submodule (
{ ... }:
{
options = {
sdk = lib.mkOption {
type = lib.types.enum [
"flutter"
"dart"
];
default = "flutter";
description = "Which SDK the CI jobs install and run: `flutter` (default) or `dart`.";
};

importSorter = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Run `import_sorter` to check import ordering.";
};

dependencyValidator = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Run `dependency_validator` to check for unused dependencies.";
};

dartCodeLinter = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Run `dart_code_linter` for code metrics and unused code/files checks.";
};

translationsCleaner = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Run `translations_cleaner` to check for unused translations.";
};

commentedCodeCheck = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Check for commented-out Dart code.";
};

test = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Enable a test job (`dart test` / `flutter test`).";
};

coverage = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Enable a coverage job with Codecov upload.";
};

coverageFlags = lib.mkOption {
type = lib.types.str;
default = "";
description = "Flags to pass to Codecov (e.g. `sdk-tests`).";
};

testInDevShell = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Run the test/coverage commands inside `nix develop`. Enable this
when tests depend on native libraries (e.g. sqlite3 for
sqflite_common_ffi) that the Nix-installed SDK cannot find on its
own.
'';
};
};
}
)
);
};
});
}
29 changes: 29 additions & 0 deletions nix/dart/devshell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{ ... }:
importingFlake: {
perSystem =
{
config,
lib,
self',
...
}:
{
devshells.dart = {
# Ship the same pinned SDK that CI uses, so local and CI builds
# match.
#
# Where Flutter is available we prefer it: the Flutter SDK bundles a
# full Dart SDK, so a single package covers both `flutter` and `dart`
# projects without colliding `dart` binaries. On platforms without an
# upstream Flutter binary (aarch64-linux) we fall back to the
# standalone Dart SDK.
packages = [
(self'.packages.famedly-flutter-sdk or self'.packages.famedly-dart-sdk)
];

# TODO: Find a better way to inherit devshell
# configurations.
commands = lib.filter (command: command.name != "menu") config.devshells.standards.commands;
};
};
}
Loading