diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..11f188f --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake .#default diff --git a/examples/typescript-flake-project-with-extra-dependency/package.json b/examples/typescript-flake-project-with-extra-dependency/package.json index d02a1e3..4c4ca15 100644 --- a/examples/typescript-flake-project-with-extra-dependency/package.json +++ b/examples/typescript-flake-project-with-extra-dependency/package.json @@ -18,10 +18,7 @@ }, "author": "Jared Pon", "license": "ISC", - "files": - [ "./dist/**/*" - , "./.extra-dependencies/**/*" - ], + "files": ["./dist/**/*", "./.extra-dependencies/**/*"], "dependencies": { "typescript": "^5.3.3", "typescript-flake-project": "file:.extra-dependencies/typescript-flake-project-1.0.0.tgz" diff --git a/examples/typescript-flake-project-with-extra-dependency/src/MyLib/index.ts b/examples/typescript-flake-project-with-extra-dependency/src/MyLib/index.ts index d96af6b..ab7f0ed 100644 --- a/examples/typescript-flake-project-with-extra-dependency/src/MyLib/index.ts +++ b/examples/typescript-flake-project-with-extra-dependency/src/MyLib/index.ts @@ -1,5 +1,5 @@ -import * as TsFlakeProject from 'typescript-flake-project' +import * as TsFlakeProject from "typescript-flake-project"; export function helloWorld() { - TsFlakeProject.helloWorld(); + TsFlakeProject.helloWorld(); } diff --git a/examples/typescript-flake-project-with-transitive-extra-dependency/src/MyLib/index.ts b/examples/typescript-flake-project-with-transitive-extra-dependency/src/MyLib/index.ts index a87341a..ce636fe 100644 --- a/examples/typescript-flake-project-with-transitive-extra-dependency/src/MyLib/index.ts +++ b/examples/typescript-flake-project-with-transitive-extra-dependency/src/MyLib/index.ts @@ -1,9 +1,7 @@ -import * as TsFlakeProject from 'typescript-flake-project' +import * as TsFlakeProject from "typescript-flake-project"; export function helloWorld() { - TsFlakeProject.helloWorld(); + TsFlakeProject.helloWorld(); } - - helloWorld(); diff --git a/examples/typescript-flake-project/package.json b/examples/typescript-flake-project/package.json index 12fdb58..72743de 100644 --- a/examples/typescript-flake-project/package.json +++ b/examples/typescript-flake-project/package.json @@ -18,10 +18,7 @@ }, "author": "Jared Pon", "license": "ISC", - "files": - [ "./dist/**/*" - , "./.extra-dependencies/**/*" - ], + "files": ["./dist/**/*", "./.extra-dependencies/**/*"], "dependencies": { "typescript": "^5.3.3" } diff --git a/examples/typescript-flake-project/src/MyLib/index.ts b/examples/typescript-flake-project/src/MyLib/index.ts index 10b9730..5117dc2 100644 --- a/examples/typescript-flake-project/src/MyLib/index.ts +++ b/examples/typescript-flake-project/src/MyLib/index.ts @@ -1,3 +1,3 @@ export function helloWorld() { - console.log("Hello world!"); + console.log("Hello world!"); } diff --git a/flake-lang/build.nix b/flake-lang/build.nix index 4bbd084..68f6321 100644 --- a/flake-lang/build.nix +++ b/flake-lang/build.nix @@ -1,5 +1,4 @@ -# Note(jaredponn): - +# NOTE(jaredponn): # Loosely, the key idea is that in this flake we want to have an attribute like # ``` # lib. = { @@ -8,20 +7,43 @@ # typescriptFlake = ... # ... # }; +# flakeModules = { +# rustMonorepoPreCommit = ... +# }; # ``` # This is unfortunately not super easy to do with flake-parts! Some useful -# links + examples are as follows. +# links + examples are as follows. # - [1] https://github.com/hercules-ci/flake-parts/blob/main/lib.nix # - [2] https://github.com/hercules-ci/flake-parts/pull/63/files # - [3] https://github.com/hercules-ci/flake-parts/blob/main/modules/formatter.nix { config, inputs, flake-parts-lib, lib, ... }: { options = { flake = flake-parts-lib.mkSubmoduleOptions { + # Expose attributes which are generated by the `perSystem` `lib` options + # e.g. it gives an option for things like + # ``` + # lib..haskellFlake = .. + # ``` lib = lib.mkOption { type = lib.types.lazyAttrsOf (lib.types.lazyAttrsOf (lib.types.functionTo lib.types.attrs)); default = { }; visible = false; }; + + # Expose attributes like + # ``` + # flakeModules.rustMonorepoPreCommit = .. + # ``` + flakeModules = { + rustMonorepoPreCommit = lib.mkOption { + type = lib.types.deferredModule; + default = import ./pre-commit-hooks/rust-monorepo.nix; + readOnly = true; + description = lib.mdDoc ''pre-commit-hooks.nix hook for Rust in a monorepo setting''; + example = lib.mdDoc ''TODO(bladyjoker)''; + }; + + }; }; perSystem = flake-parts-lib.mkPerSystemOption ({ pkgs, pkgsForCtl, pkgsForHaskellNix, pkgsForRust, ... }: { options = { @@ -95,8 +117,7 @@ default = import ./typescript/flake-typescript.nix pkgs; readOnly = true; description = lib.mdDoc builtins.readFile ./typescript/description.md; - # TODO(jaredponn): add an example - # example = lib.mdDoc '' ''; + example = lib.mdDoc ''TODO(jaredponn)''; }; }; diff --git a/flake-lang/pre-commit-hooks/rust-monorepo.nix b/flake-lang/pre-commit-hooks/rust-monorepo.nix new file mode 100644 index 0000000..c8efa6a --- /dev/null +++ b/flake-lang/pre-commit-hooks/rust-monorepo.nix @@ -0,0 +1,19 @@ +{ inputs, ... }: { + imports = [ + inputs.pre-commit-hooks.flakeModule # Adds perSystem.pre-commit options + ./tools.nix + ]; + perSystem = { config, ... }: + { + pre-commit.settings.hooks = { + rustfmt-monorepo = + { + name = "rustfmt"; + description = "Format Rust code."; + entry = "${config.flake-lang.pre-commit-hooks.tools.rustfmt}/bin/rustfmt --color always"; + files = "\\.rs$"; + }; + + }; + }; +} diff --git a/flake-lang/pre-commit-hooks/tools.nix b/flake-lang/pre-commit-hooks/tools.nix new file mode 100644 index 0000000..c4d473d --- /dev/null +++ b/flake-lang/pre-commit-hooks/tools.nix @@ -0,0 +1,16 @@ +{ flake-parts-lib, lib, ... }: { + options = { + perSystem = flake-parts-lib.mkPerSystemOption ({ pkgsForRust, ... }: { + options = { + flake-lang.pre-commit-hooks.tools = { + rustfmt = lib.mkOption { + type = lib.types.package; + default = pkgsForRust.rustfmt; + readOnly = false; + description = lib.mdDoc ''Rust formatter to use for pre-commit hooks''; + }; + }; + }; + }); + }; +} diff --git a/pre-commit.nix b/pre-commit.nix index 6d3db92..0a9560a 100644 --- a/pre-commit.nix +++ b/pre-commit.nix @@ -1,7 +1,10 @@ { inputs, ... }: { - imports = [ inputs.pre-commit-hooks.flakeModule ]; + imports = [ + inputs.pre-commit-hooks.flakeModule + ./flake-lang/pre-commit-hooks/rust-monorepo.nix + ]; perSystem = { config, ... }: { - devShells.dev-pre-commit = config.pre-commit.devShell; + devShells.default = config.pre-commit.devShell; pre-commit.settings = { hooks = { # Typos @@ -18,6 +21,19 @@ cabal-fmt.enable = true; hlint.enable = true; fourmolu.enable = true; + + # Typescript + denofmt = { + enable = true; + # NOTE(jaredponn): We follow the default files deno formats, except + # we exclude markdown files. See: + # [1] https://docs.deno.com/runtime/manual/tools/formatter + files = ''^.*\.(js|ts|jsx|tsx|json|jsonc)$''; + }; + denolint.enable = true; + + # Rust + rustfmt-monorepo.enable = true; }; }; };