Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: standardizes the plugin interface #10

Merged
merged 14 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor: cleans up naming, comments, and structure after overhaul
  • Loading branch information
jmgilman committed Jun 6, 2022
commit bc184dac63dfdf48b917160b2d69ad502c7b24e8
107 changes: 107 additions & 0 deletions .config.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{ tools }:
[
# Conform
{
name = "conform";
configData = {
commit = {
header = { length = 89; };
conventional = {
types = [
"build"
"chore"
"ci"
"docs"
"feat"
"fix"
"perf"
"refactor"
"style"
"test"
];
scopes = [
"conform"
"just"
"lefthook"
"pre-commit"
"prettier"
"core"
"flake"
];
};
};
};
}
# Just
{
name = "just";
configData = {
tasks = {
check = [
"@${tools.nixpkgs-fmt.exe} --check flake.nix $(git ls-files '**/*.nix')"
"@${tools.prettier.exe} --check ."
"@${tools.typos.exe}"
"@nix flake check"
];
check-docs = [
"@${tools.typos.exe}"
];
make-docs = [
"@cd docs && mdbook build"
];
fmt = [
"@${tools.nixpkgs-fmt.exe} flake.nix $(git ls-files '**/*.nix')"
"@${tools.prettier.exe} -w ."
];
};
};
}
# Lefthook
{
name = "lefthook";
configData = {
commit-msg = {
commands = {
conform = {
run = "${tools.conform.exe} enforce --commit-msg-file {1}";
};
};
};
pre-commit = {
commands = {
nixpkgs-fmt = {
run = "${tools.nixpkgs-fmt.exe} --check {staged_files}";
glob = "*.nix";
};
prettier = {
run = "${tools.prettier.exe} --check {staged_files}";
glob = "*.{yaml,yml,md}";
};
typos = {
run = "${tools.typos.exe} {staged_files}";
};
};
};
};
}
# Prettier
{
name = "prettier";
configData = {
proseWrap = "always";
};
}
{
name = "prettier";
type = "ignore";
configData = [
".direnv"
".conform.yaml"
".prettierrc.json"
"tests"
"CHANGELOG.md"
"lefthook.yml"
];
}
]

110 changes: 3 additions & 107 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -59,112 +59,8 @@
pkgs.typos
];

# Define development tool configuration
configurations = [
# Conform configuration
{
name = "conform";
configData = {
commit = {
header = { length = 89; };
conventional = {
types = [
"build"
"chore"
"ci"
"docs"
"feat"
"fix"
"perf"
"refactor"
"style"
"test"
];
scopes = [
"conform"
"just"
"lefthook"
"pre-commit"
"prettier"
"core"
"flake"
];
};
};
};
}
# Just configuration
{
name = "just";
configData = {
tasks = {
check = [
"@${tools.nixpkgs-fmt.exe} --check flake.nix $(git ls-files '**/*.nix')"
"@${tools.prettier.exe} --check ."
"@${tools.typos.exe}"
"@nix flake check"
];
check-docs = [
"@${tools.typos.exe}"
];
make-docs = [
"@cd docs && mdbook build"
];
fmt = [
"@${tools.nixpkgs-fmt.exe} flake.nix $(git ls-files '**/*.nix')"
"@${tools.prettier.exe} -w ."
];
};
};
}
# Lefthook configuration
{
name = "lefthook";
configData = {
commit-msg = {
commands = {
conform = {
run = "${tools.conform.exe} enforce --commit-msg-file {1}";
};
};
};
pre-commit = {
commands = {
nixpkgs-fmt = {
run = "${tools.nixpkgs-fmt.exe} --check {staged_files}";
glob = "*.nix";
};
prettier = {
run = "${tools.prettier.exe} --check {staged_files}";
glob = "*.{yaml,yml,md}";
};
typos = {
run = "${tools.typos.exe} {staged_files}";
};
};
};
};
}
# Prettier
{
name = "prettier";
configData = {
proseWrap = "always";
};
}
{
name = "prettier";
type = "ignore";
configData = [
".direnv"
".conform.yaml"
".prettierrc.json"
"tests"
"CHANGELOG.md"
"lefthook.yml"
];
}
];
# Define development tool configuration (with Nixago!)
configs = import ./.config.nix { inherit tools; };
in
rec {
# Load lib functions
Expand All @@ -179,7 +75,7 @@
# Local development shell
devShells = {
default = pkgs.mkShell {
shellHook = (lib.mkAll configurations).shellHook;
shellHook = (lib.makeAll configs).shellHook;
packages = tools.all;
};
};
Expand Down
18 changes: 0 additions & 18 deletions lib/all.nix

This file was deleted.

19 changes: 16 additions & 3 deletions lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
{ pkgs, lib, plugins }:
with pkgs.lib;
rec {
inherit (import ../modules/default.nix { inherit pkgs lib; }) mkGenRequest;
inherit (import ../modules/default.nix { inherit pkgs lib; }) mkRequest;

eval = import ./eval.nix { inherit pkgs lib plugins; };

/* Filters out "empty" values from an attribute set
*/
filterEmpty = attrs:
filterAttrs (n: v: v != null && v != "" && v != [ ] && v != { }) attrs;

genConfig = import ./generate.nix { inherit pkgs lib plugins; };
generate = import ./generate.nix { inherit pkgs lib plugins; };

make = import ./make.nix { inherit pkgs lib plugins; };

mkAll = import ./all.nix { inherit pkgs lib plugins; };
/** Recursively makes a list of configurations
*/
makeAll = all:
(
let
result = builtins.map lib.make all;
in
{
configs = catAttrs "configFile" result;
shellHook = concatStringsSep "\n" (pkgs.lib.catAttrs "shellHook" result);
}
);

/* Updates the the attribute at `path` in `attrs` with `value`.
*/
Expand Down
23 changes: 7 additions & 16 deletions lib/eval.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
builds the result.
*/
{ pkgs, lib, plugins }:
{ inputFiles
, outputFile
{ files
, output
, postBuild ? ""
, configData ? { }
, flags ? { }
, cue ? pkgs.cue
, ...
}@args:
}:

with pkgs.lib;
let
Expand All @@ -19,17 +19,8 @@ let
outfile = "$out"; # Output the evaluation result to the derivation output
};

# Extra flags are passed via ...
extraFlags = removeAttrs args [
"inputFiles"
"outputFile"
"postBuild"
"configData"
"cue"
];

allFlags = defaultFlags // extraFlags;
allInputs = inputFiles ++ optionals (json != "") [ "json: $jsonPath" ];
allFlags = defaultFlags // flags;
allInputs = files ++ optionals (json != "") [ "json: $jsonPath" ];

# Converts {flagName = "string"; } to --flagName "string" (or empty for bool)
flagsToString = name: value:
Expand All @@ -41,7 +32,7 @@ let
cueEvalCmd = "cue eval ${flagStr} ${inputStr}";

# runCommand does the work of producing the derivation
result = pkgs.runCommand outputFile
result = pkgs.runCommand output
({
inherit json;
buildInputs = [ cue ];
Expand Down
Loading