Skip to content

Commit

Permalink
wip: integrate some initial nixago standard pebbles
Browse files Browse the repository at this point in the history
  • Loading branch information
blaggacao committed Jul 28, 2022
1 parent 24540c4 commit 7063ff2
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 59 deletions.
71 changes: 12 additions & 59 deletions cells/std/devshellProfiles.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ in {
default = {config, ...}: let
cfg = config.std;
in {
options.std = {
adr.enable = (l.mkEnableOption "Enable ADR nudging") // {default = true;};
docs.enable = (l.mkEnableOption "Enable Docs nudging") // {default = true;};
};
imports = [
(nixpkgs.path + "/nixos/modules/misc/assertions.nix")
(l.mkRemovedOptionModule ["std" "adr" "enable"] ''
The std.adr.enable option has been removed from the std shell.
Please look for something like "adr.enable = false" and drop it.
'')
(l.mkRemovedOptionModule ["std" "docs" "enable"] ''
The std.docs.enable option has been removed from the std shell.
Please look for something like "docs.enable = false" and drop it.
'')
];
config = {
motd = ''
Expand All @@ -22,61 +29,7 @@ in {
$(type -p menu &>/dev/null && menu)
'';
packages = l.optionals (cfg.docs.enable && nixpkgs.stdenv.isLinux) [cell.packages.mdbook-kroki-preprocessor];
commands =
[
{package = cell.cli.default;}
]
++ l.optionals cfg.adr.enable [
{package = cell.packages.adrgen;}
]
++ l.optionals cfg.docs.enable [
{package = cell.packages.mdbook;}
];
devshell.startup.init-adrgen = l.mkIf cfg.adr.enable (l.stringsWithDeps.noDepEntry ''
if [ ! -d "docs/architecture-decisions" ]; then
${l.getExe cell.packages.adrgen} init "docs/architecture-decisions"
fi
'');
devshell.startup.init-mdbook =
l.mkIf (cfg.docs.enable && nixpkgs.stdenv.isLinux)
(l.stringsWithDeps.noDepEntry ''
if [ ! -f "book.toml" ]; then
mkdir -p docs
cat << EOF > book.toml
[book]
language = "en"
multilingual = false
src = "docs"
title = "Documentation"
[build]
build-dir = "docs/book"
[preprocessor.kroki-preprocessor]
command = "${l.getExe cell.packages.mdbook-kroki-preprocessor}"
EOF
cat << EOF > docs/SUMMARY.md
# Summary
EOF
fi
if [ ! -f "docs/.gitignore" ]; then
cat << EOF > docs/.gitignore
# mdbook build
book/**
EOF
fi
if ! grep -qF 'book/' docs/.gitignore; then
cat << EOF >> docs/.gitignore
# mdbook build
book/**
EOF
fi
'');
commands = [{package = cell.cli.default;}];
};
};
}
106 changes: 106 additions & 0 deletions cells/std/nixago.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
inputs,
cell,
}: let
inherit (inputs) nixpkgs;
l = nixpkgs.lib // builtins;
in
l.mapAttrs (_: cell.lib.mkNixago) {
treefmt = {
configData = import ./nixago/treefmt.nix;
output = "treefmt.toml";
format = "toml";
packages = [
nixpkgs.alejandra
nixpkgs.nodePackages.prettier
nixpkgs.nodePackages.prettier-plugin-toml
nixpkgs.shfmt
nixpkgs.treefmt
];
commands = [{package = nixpkgs.treefmt;}];
devshell.startup.prettier-plugin-toml = l.stringsWithDeps.noDepEntry ''
export NODE_PATH=${nixpkgs.nodePackages.prettier-plugin-toml}/lib/node_modules:$NODE_PATH
'';
};
editorconfig = {
configData = import ./nixago/editorconfig.nix;
output = ".editorconfig";
format = "ini";
hook.mode = "copy"; # already useful before entering the devshell
packages = [nixpkgs.editorconfig-checker];
};
conform = {
configData = import ./nixago/conform.nix;
format = "yaml";
output = ".conform.yaml";
packages = [nixpkgs.conform];
apply = d: {
policies =
[]
++ (l.optional (d ? commit) {
type = "commit";
spec = d.commit;
})
++ (l.optional (d ? license) {
type = "license";
spec = d.license;
});
};
};
lefthook = {
configData = import ./nixago/lefthook.nix;
format = "yaml";
output = "lefthook.yml";
packages = [nixpkgs.lefthook];
hook.extra = d: let
# Add an extra hook for adding required stages whenever the file changes
skip_attrs = [
"colors"
"extends"
"skip_output"
"source_dir"
"source_dir_local"
];
stages = l.attrNames (l.removeAttrs d skip_attrs);
stagesStr = l.concatStringsSep " " stages;
in ''
# Install configured hooks
for stage in ${stagesStr}; do
${nixpkgs.lefthook}/bin/lefthook add -a "$stage"
done
'';
};
mdbook = {
configData = import ./nixago/mdbook.nix;
output = "book.toml";
format = "toml";
hook.mode = "copy"; # let CI pick it up outside of devshell
hook.extra = let
sentinel = "nixago-auto-created: mdbook-build-folder";
file = "docs/.gitignore";
str = ''
# mdbook build folder; ${sentinel}
book/**
'';
in ''
# Configure gitignore
create () { echo -n "$str" > "${file}" }
append () { echo -en "\n$str" >> "${file}" }
if ! test -f "${file}"
then
create
else if ! grep -qF "${sentinel}" "${file}"
then
append
fi
'';
packages = [cell.packages.mdbook-kroki-preprocessor];
commands = [{package = nixpkgs.mdbook;}];
};
adrgen = {
configData = import ./nixago/adrgen.nix;
output = "treefmt.toml";
format = "yaml";
commands = [{package = cell.packages.adrgen;}];
};
}
15 changes: 15 additions & 0 deletions cells/std/nixago/adrgen.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
default_meta = [];
default_status = "proposed";
directory = "docs/explain/architecture-decision-records";
id_digit_number = 4;
supported_statuses = [
"proposed"
"accepted"
"rejected"
"superseded"
"amended"
"deprecated"
];
template_file = "docs/explain/architecture-decision-records/template.md";
}
20 changes: 20 additions & 0 deletions cells/std/nixago/conform.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
commit = {
header = {length = 89;};
conventional = {
types = [
"build"
"chore"
"ci"
"docs"
"feat"
"fix"
"perf"
"refactor"
"style"
"test"
];
scopes = [];
};
};
}
24 changes: 24 additions & 0 deletions cells/std/nixago/editorconfig.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
# root = true;

"*" = {
end_of_line = "lf";
insert_final_newline = true;
trim_trailing_whitespace = true;
charset = "utf-8";
indent_style = "space";
indent_size = 2;
};

"*.{diff,patch}" = {
end_of_line = "unset";
insert_final_newline = "unset";
trim_trailing_whitespace = "unset";
indent_size = "unset";
};

"*.md" = {
max_line_length = "off";
trim_trailing_whitespace = false;
};
}
17 changes: 17 additions & 0 deletions cells/std/nixago/lefthook.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
commit-msg = {
commands = {
conform = {
run = "conform enforce --commit-msg-file {1}";
};
};
};
pre-commit = {
commands = {
treefmt = {
run = "treefmt {staged_files}";
glob = "*";
};
};
};
}
16 changes: 16 additions & 0 deletions cells/std/nixago/mdbook.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
book = {
language = "en";
multilingual = false;
src = "docs";
title = "Documentation";
};
build = {
build-dir = "docs/book";
};
preprocessor = {
kroki-preprocessor = {
command = "mdbook-kroki-preprocessor";
};
};
}
30 changes: 30 additions & 0 deletions cells/std/nixago/treefmt.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
formatter = {
nix = {
command = "alejandra";
includes = ["*.nix"];
};
prettier = {
command = "prettier";
options = ["--plugin" "prettier-plugin-toml" "--write"];
includes = [
"*.css"
"*.html"
"*.js"
"*.json"
"*.jsx"
"*.md"
"*.mdx"
"*.scss"
"*.ts"
"*.yaml"
"*.toml"
];
};
shell = {
command = "shfmt";
options = ["-i" "2" "-s" "-w"];
includes = ["*.sh"];
};
};
}
1 change: 1 addition & 0 deletions dogfood.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ growOn {
(clades.functions "devshellProfiles")
(clades.devshells "devshells")
(clades.installables "packages")
(clades.nixago "nixago")
(clades.data "data")
(clades.files "files")
];
Expand Down

0 comments on commit 7063ff2

Please sign in to comment.