Skip to content
Merged
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
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake .#default
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -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();
5 changes: 1 addition & 4 deletions examples/typescript-flake-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
},
"author": "Jared Pon",
"license": "ISC",
"files":
[ "./dist/**/*"
, "./.extra-dependencies/**/*"
],
"files": ["./dist/**/*", "./.extra-dependencies/**/*"],
"dependencies": {
"typescript": "^5.3.3"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/typescript-flake-project/src/MyLib/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function helloWorld() {
console.log("Hello world!");
console.log("Hello world!");
}
31 changes: 26 additions & 5 deletions flake-lang/build.nix
Original file line number Diff line number Diff line change
@@ -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.<system> = {
Expand All @@ -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.<system>.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 = {
Expand Down Expand Up @@ -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)'';
};

};
Expand Down
19 changes: 19 additions & 0 deletions flake-lang/pre-commit-hooks/rust-monorepo.nix
Original file line number Diff line number Diff line change
@@ -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$";
};

};
};
}
16 changes: 16 additions & 0 deletions flake-lang/pre-commit-hooks/tools.nix
Original file line number Diff line number Diff line change
@@ -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'';
};
};
};
});
};
}
20 changes: 18 additions & 2 deletions pre-commit.nix
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
};
};
};
Expand Down