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 0c658a2 commit 503cfc3
Show file tree
Hide file tree
Showing 19 changed files with 650 additions and 274 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;
};
};
};
}
7 changes: 7 additions & 0 deletions flake-modules/dev/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
imports = [
./devshell.nix
./git-hooks.nix
./treefmt.nix
];
}
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})
'';
}
];
};
};
}
40 changes: 40 additions & 0 deletions flake-modules/dev/git-hooks.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{ lib, inputs, ... }:
{
imports = lib.optional (inputs.git-hooks-nix ? flakeModule) inputs.git-hooks-nix.flakeModule;

perSystem =
{
lib,
pkgs,
...
}:
lib.optionalAttrs (inputs.git-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/*" ];
};
};
};
};
}
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()
109 changes: 109 additions & 0 deletions flake-modules/dev/treefmt.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{ lib, inputs, ... }:
{
imports = lib.optional (inputs.treefmt-nix ? flakeModule) inputs.treefmt-nix.flakeModule;

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

programs = {
actionlint.enable = true;
biome = {
enable = true;
settings.formatter.formatWithErrors = true;
};
clang-format.enable = true;
deadnix = {
enable = true;
};
deno = {
enable = true;
# Using biome for these
excludes = [
"*.ts"
"*.js"
"*.json"
"*.jsonc"
];
};
fantomas.enable = true;
fish_indent.enable = true;
gofmt.enable = true;
isort.enable = true;
nixfmt.enable = true;
nufmt.enable = true;
ruff-check.enable = true;
ruff-format.enable = true;
rustfmt.enable = true;
shfmt = {
enable = true;
indent_size = 4;
};
statix.enable = true;
stylua.enable = true;
taplo.enable = true;
yamlfmt.enable = true;
};

settings = {
global.excludes = [
"*.editorconfig"
"*.envrc"
"*.gitconfig"
"*.git-blame-ignore-revs"
"*.gitignore"
"*.gitattributes"
"*.luacheckrc"
"*CODEOWNERS"
"*LICENSE"
"*flake.lock"
"*.svg"
"*.png"
"*.gif"
"*.ico"
# TODO: formatters?
"*Makefile"
"*makefile"
"*.xml"
"*.zsh"
"*.rasi"
"*.kdl"

# TODO: exceptions
# WARN no formatter for path: homes/x86_64-linux/nixos@CORE-PW00LM92/git/windows-compat-config
# WARN no formatter for path: modules/darwin/desktop/wms/yabai/extraConfig
# WARN no formatter for path: modules/home/programs/graphical/addons/electron-support/electron-flags.conf
# WARN no formatter for path: modules/home/programs/graphical/addons/kanshi/config
# WARN no formatter for path: modules/home/programs/graphical/addons/mako/config
# WARN no formatter for path: modules/home/programs/graphical/addons/swappy/config
# WARN no formatter for path: modules/home/programs/graphical/bars/sketchybar/dynamic-island-sketchybar/helper/islandhelper
# WARN no formatter for path: modules/home/programs/graphical/bars/sketchybar/dynamic-island-sketchybar/scripts/islands/music/cava.conf
# WARN no formatter for path: modules/home/programs/graphical/bars/sketchybar/dynamic-island-sketchybar/scripts/islands/music/get_artwork.scpt
# WARN no formatter for path: modules/home/programs/graphical/bars/sketchybar/dynamic-island-sketchybar/scripts/islands/volume/data/cache
# WARN no formatter for path: modules/home/programs/graphical/bars/sketchybar/dynamic-island-sketchybar/sketchybarrc
# WARN no formatter for path: modules/home/programs/graphical/launchers/wofi/config
# WARN no formatter for path: modules/home/programs/terminal/editors/micro/catppuccin-macchiato.micro
# WARN no formatter for path: modules/home/programs/terminal/tools/tmux/config/general.tmux
# WARN no formatter for path: modules/home/theme/qt/Kvantum/Catppuccin-Macchiato-Blue/Catppuccin-Macchiato-Blue.kvconfig
# WARN no formatter for path: modules/home/theme/qt/Kvantum/kvantum.kvconfig
# WARN no formatter for path: modules/nixos/programs/graphical/addons/looking-glass-client/client.ini
# WARN no formatter for path: systems/x86_64-linux/khanelinix/hyprlandOutput
# WARN no formatter for path: systems/x86_64-linux/khanelinix/swayOutput
# WARN no formatter for path: templates/c/Makefile.in
# WARN no formatter for path: templates/c/configure.ac
# WARN no formatter for path: templates/dotnetf/HelloWorld.Test/HelloWorld.Test.fsproj
# WARN no formatter for path: templates/dotnetf/HelloWorld.sln
# WARN no formatter for path: templates/dotnetf/HelloWorld/HelloWorld.fsproj
];

formatter.ruff-format.options = [ "--isolated" ];
};
};
};
}
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; };
}
)
);
}
23 changes: 23 additions & 0 deletions flake-modules/packages.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{ inputs, ... }:
{
perSystem =
{
config,
inputs',
system,
...
}:
{
imports = [
# ../packages/default.nix
];

# 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 503cfc3

Please sign in to comment.