diff --git a/examples/build.nix b/examples/build.nix index d40ecb8..27898b3 100644 --- a/examples/build.nix +++ b/examples/build.nix @@ -5,7 +5,6 @@ _: { imports = [ - ./pre-commit.nix ./haskell-flake-project/build.nix ./rust-flake-project/build.nix ./typescript-flake-project/build.nix diff --git a/examples/pre-commit.nix b/examples/pre-commit.nix deleted file mode 100644 index 3e69b14..0000000 --- a/examples/pre-commit.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ inputs, config, ... }: { - imports = [ - inputs.pre-commit-hooks.flakeModule - config.flake-lang.rustMonorepoPreCommit - config.flake-lang.denoPreCommit - ]; - perSystem = _: { - pre-commit.settings = { - hooks = { - rust-monorepo.enable = true; - my-deno.enable = true; - }; - }; - }; -} 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 155fe8c..5d7b815 100644 --- a/flake-lang/build.nix +++ b/flake-lang/build.nix @@ -7,6 +7,9 @@ # typescriptFlake = ... # ... # }; +# flakeModule = { +# rustMonorepoPreCommit = ... +# }; # ``` # This is unfortunately not super easy to do with flake-parts! Some useful # links + examples are as follows. @@ -16,11 +19,31 @@ { 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 + # ``` + # flakeModule.rustMonorepoPreCommit = .. + # ``` + flakeModule = { + rustMonorepoPreCommit = lib.mkOption { + type = lib.types.lazyAttrsOf lib.types.unspecified; + default = ./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 = { @@ -81,22 +104,6 @@ example = lib.mdDoc ''TODO(jaredponn)''; }; - rustMonorepoPreCommit = lib.mkOption { - type = lib.types.flakeModule; - default = ./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)''; - }; - - denoPreCommit = lib.mkOption { - type = lib.types.flakeModule; - default = ./pre-commit-hooks/deno.nix; - readOnly = true; - description = lib.mdDoc ''pre-commit-hooks.nix hook for Deno in a monorepo setting''; - example = lib.mdDoc ''TODO(bladyjoker)''; - }; - }; }; }); diff --git a/flake-lang/pre-commit-hooks/deno.nix b/flake-lang/pre-commit-hooks/deno.nix deleted file mode 100644 index ee32178..0000000 --- a/flake-lang/pre-commit-hooks/deno.nix +++ /dev/null @@ -1,33 +0,0 @@ -{ inputs, ... }: { - imports = [ - inputs.pre-commit-hooks.flakeModule # Adds perSystem.pre-commit options - ./tools.nix - ]; - perSystem = { config, ... }: - { - pre-commit.settings.hooks = { - # TODO(jaredponn): Why do we use our strange version of `denofmt` and - # `denolint`? The default implemented version in `pre-commit-hooks.nix` - # is a bit buggy (see - # https://github.com/cachix/pre-commit-hooks.nix/issues/374), and the - # latest version of `deno` on nix doesn't allow explicitly applying - # the formatter to specific files - my-denofmt = - { - name = "denofmt"; - description = "Format Typescript code."; - entry = "${config.flake-lang.pre-commit-hooks.tools.deno}/bin/deno fmt"; - files = "(\\.m?ts$)|(^tsconfig?(-base)\\.json$)"; - }; - - my-denolint = - { - name = "denolint"; - description = "Lint Typescript code."; - entry = "${config.flake-lang.pre-commit-hooks.tools.deno}/bin/deno lint"; - files = "\\.m?ts$"; - }; - - }; - }; -} diff --git a/flake-lang/pre-commit-hooks/tools.nix b/flake-lang/pre-commit-hooks/tools.nix index 9962e62..c4d473d 100644 --- a/flake-lang/pre-commit-hooks/tools.nix +++ b/flake-lang/pre-commit-hooks/tools.nix @@ -1,23 +1,16 @@ { flake-parts-lib, lib, ... }: { - perSystem = flake-parts-lib.mkPerSystemOption ({ pkgs, pkgsForRust, ... }: { - options = { - flake-lang.pre-commit-hooks.tools = { - - rustfmt = lib.mkOption { - type = lib.types.derivation; - default = pkgsForRust.rustfmt; - readOnly = false; - description = lib.mdDoc ''Rust formatter to use for pre-commit hooks''; + 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''; + }; }; - - deno = lib.mkOption { - type = lib.types.derivation; - default = pkgs.deno; - readOnly = false; - description = lib.mdDoc ''Deno tool to use for pre-commit hooks''; - }; - }; - }; - }); + }); + }; } diff --git a/pre-commit.nix b/pre-commit.nix index 6e75ce9..0a9560a 100644 --- a/pre-commit.nix +++ b/pre-commit.nix @@ -1,6 +1,7 @@ { inputs, ... }: { imports = [ inputs.pre-commit-hooks.flakeModule + ./flake-lang/pre-commit-hooks/rust-monorepo.nix ]; perSystem = { config, ... }: { devShells.default = config.pre-commit.devShell; @@ -20,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; }; }; };