Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
khaneliman committed Jan 3, 2025
1 parent f732b90 commit e3b1767
Show file tree
Hide file tree
Showing 16 changed files with 483 additions and 120 deletions.
2 changes: 0 additions & 2 deletions checks/deploy/default.nix

This file was deleted.

20 changes: 20 additions & 0 deletions flake-modules/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{ inputs, ... }:
{
imports = [
./dev
./lib.nix
./packages.nix
./templates.nix
];

perSystem =
{ system, ... }:
{
_module.args = {
pkgs = import inputs.nixpkgs {
inherit system;
config.allowUnfree = true;
};
};
};
}
88 changes: 88 additions & 0 deletions flake-modules/dev/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{ lib, inputs, ... }:
{
imports =
[ ./devshell.nix ]
++ lib.optional (inputs.git-hooks-nix ? flakeModule) inputs.git-hooks-nix.flakeModule
++ lib.optional (inputs.treefmt-nix ? flakeModule) inputs.treefmt-nix.flakeModule;

perSystem =
{
lib,
pkgs,
...
}:
lib.optionalAttrs (inputs.treefmt-nix ? flakeModule) {
treefmt.config = {
projectRootFile = "flake.nix";
flakeCheck = true;

programs = {
actionlint.enable = true;
clang-format.enable = true;
isort.enable = true;
nixfmt = {
enable = true;
package = pkgs.nixfmt-rfc-style;
};
prettier = {
enable = true;

excludes = [ "**.md" ];
};
ruff = {
check = true;
format = true;
};
statix.enable = true;
stylua.enable = true;
shfmt.enable = true;
taplo.enable = true;
};

settings = {
global.excludes = [
".editorconfig"
".envrc"
".git-blame-ignore-revs"
".gitignore"
"LICENSE"
"flake.lock"
"**.md"
"**.scm"
"**.svg"
"**/man/*.5"
];
formatter.ruff-format.options = [ "--isolated" ];
};
};
}
// lib.optionalAttrs (inputs.pre-commit-hooks-nix ? flakeModule) {
pre-commit = {
check.enable = false;

settings.hooks = {
actionlint.enable = true;
clang-tidy.enable = true;
deadnix = {
enable = true;

settings = {
edit = true;
};
};
eslint = {
enable = true;
package = pkgs.eslint_d;
};
luacheck.enable = true;
pre-commit-hook-ensure-sops.enable = true;
statix.enable = true;
treefmt.enable = true;
typos = {
enable = true;
excludes = [ "generated/*" ];
};
};
};
};
}
60 changes: 60 additions & 0 deletions flake-modules/dev/devshell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{ lib, inputs, ... }:
{
imports = lib.optional (inputs.devshell ? flakeModule) inputs.devshell.flakeModule;

perSystem =
{
lib,
pkgs,
config,
self',
system,
...
}:
lib.optionalAttrs (inputs.devshell ? flakeModule) {
devshells.default = {
devshell.startup.pre-commit.text = config.pre-commit.installationScript;

commands = [
{
name = "checks";
help = "Run all checks";
command = ''
echo "=> Running all checks..."
nix flake check "$@"
'';
}
{
name = "format";
help = "Format the entire codebase";
command = "nix fmt";
}
{
name = "docs";
help = "Build khanelinix documentation";
command = ''
echo "=> Building khanelinix documentation..."
${pkgs.lib.getExe pkgs.nix-output-monitor} build .#docs "$@"
'';
}
{
name = "serve-docs";
help = "Build and serve documentation locally";
command = ''
echo -e "=> Building khanelinix documentation...\n"
doc_derivation=$(${pkgs.lib.getExe pkgs.nix-output-monitor} build .#docs --no-link --print-out-paths)
echo -e "\n=> Documentation successfully built ('$doc_derivation')"
echo -e "\n=> You can then open your browser to view the doc\n"
(cd "$doc_derivation"/share/doc && ${pkgs.lib.getExe pkgs.python3} ${./server.py})
'';
}
];
};
};
}
16 changes: 16 additions & 0 deletions flake-modules/dev/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import http.server

PORT = 8000


class UncachedHTTPHandler(http.server.SimpleHTTPRequestHandler):
def end_headers(self):
self.send_header("Cache-Control", "no-cache, no-store, must-revalidate")
self.send_header("Pragma", "no-cache")
self.send_header("Expires", "0")
super().end_headers()


with http.server.HTTPServer(("", PORT), UncachedHTTPHandler) as httpd:
print(f"Serving documentation at http://localhost:{PORT}/nixvim")
httpd.serve_forever()
19 changes: 19 additions & 0 deletions flake-modules/lib.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
config,
lib,
withSystem,
...
}:
{
_module.args.helpers = import ../lib { inherit lib; };

flake.lib = lib.genAttrs config.systems (
lib.flip withSystem (
{ pkgs, ... }:
{
check = import ../lib/tests.nix { inherit lib pkgs; };
helpers = import ../lib { inherit lib pkgs; };
}
)
);
}
19 changes: 19 additions & 0 deletions flake-modules/packages.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{ inputs, ... }:
{
perSystem =
{
config,
inputs',
system,
...
}:
{
# packages = import ../docs {
# inherit system;
# inherit (inputs) nixpkgs;
# };

# Test that all packages build fine when running `nix flake check`.
checks = config.packages;
};
}
66 changes: 66 additions & 0 deletions flake-modules/templates.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{ self, inputs, ... }:
let
templatesDir = ../templates;
templates = builtins.attrNames (builtins.readDir templatesDir);
generateTemplate = name: {
description = "${name} template";
path = "${templatesDir}/${name}";
};
in
{
flake.templates = builtins.listToAttrs (
map (name: {
name = name;
value = generateTemplate name;
}) templates
);

# The following adds the template flake's checks to the main (current) flake's checks.
# It ensures that the template's own checks are successful.
perSystem =
{
pkgs,
system,
lib,
...
}:
{
checks =
let
callFlake =
args@{
inputs,
outputs,
sourceInfo,
}:
let
result = {
outputs = args.outputs (inputs // { self = result; });
};
in
result;

templateFlakeOutputs = map (
template:
callFlake {
inputs = {
inherit (inputs) flake-parts nixpkgs;
};
# Import and read the `outputs` field of the template flake.
outputs = import (templatesDir + "/${template}/flake.nix");
sourceInfo = { };
}
) templates;

templateChecks = lib.concatMap (
templateOutput: templateOutput.checks.${system} or [ ]
) templateFlakeOutputs;
in
lib.listToAttrs (
map (check: {
name = "template-${check.name}";
value = check;
}) templateChecks
);
};
}
Loading

0 comments on commit e3b1767

Please sign in to comment.