feat: format via 'ls **/*.nix | each { |it| nixfmt $it.name }'

This commit is contained in:
Ryan Yin
2025-07-30 12:17:24 +08:00
parent d10b30b06b
commit 13bb77108c
219 changed files with 2103 additions and 1728 deletions
+92 -72
View File
@@ -3,14 +3,16 @@
nixpkgs,
pre-commit-hooks,
...
} @ inputs: let
}@inputs:
let
inherit (inputs.nixpkgs) lib;
mylib = import ../lib {inherit lib;};
myvars = import ../vars {inherit lib;};
mylib = import ../lib { inherit lib; };
myvars = import ../vars { inherit lib; };
# Add my custom lib, vars, nixpkgs instance, and all the inputs to specialArgs,
# so that I can use them in all my nixos/home-manager/darwin modules.
genSpecialArgs = system:
genSpecialArgs =
system:
inputs
// {
inherit mylib myvars;
@@ -36,16 +38,24 @@
};
# This is the args for all the haumea modules in this folder.
args = {inherit inputs lib mylib myvars genSpecialArgs;};
args = {
inherit
inputs
lib
mylib
myvars
genSpecialArgs
;
};
# modules for each supported system
nixosSystems = {
x86_64-linux = import ./x86_64-linux (args // {system = "x86_64-linux";});
aarch64-linux = import ./aarch64-linux (args // {system = "aarch64-linux";});
x86_64-linux = import ./x86_64-linux (args // { system = "x86_64-linux"; });
aarch64-linux = import ./aarch64-linux (args // { system = "aarch64-linux"; });
# riscv64-linux = import ./riscv64-linux (args // {system = "riscv64-linux";});
};
darwinSystems = {
aarch64-darwin = import ./aarch64-darwin (args // {system = "aarch64-darwin";});
aarch64-darwin = import ./aarch64-darwin (args // { system = "aarch64-darwin"; });
};
allSystems = nixosSystems // darwinSystems;
allSystemNames = builtins.attrNames allSystems;
@@ -55,86 +65,98 @@
# Helper function to generate a set of attributes for each system
forAllSystems = func: (nixpkgs.lib.genAttrs allSystemNames func);
in {
in
{
# Add attribute sets into outputs, for debugging
debugAttrs = {inherit nixosSystems darwinSystems allSystems allSystemNames;};
debugAttrs = {
inherit
nixosSystems
darwinSystems
allSystems
allSystemNames
;
};
# NixOS Hosts
nixosConfigurations =
lib.attrsets.mergeAttrsList (map (it: it.nixosConfigurations or {}) nixosSystemValues);
nixosConfigurations = lib.attrsets.mergeAttrsList (
map (it: it.nixosConfigurations or { }) nixosSystemValues
);
# Colmena - remote deployment via SSH
colmena =
{
meta =
(
let
system = "x86_64-linux";
in {
# colmena's default nixpkgs & specialArgs
nixpkgs = import nixpkgs {inherit system;};
specialArgs = genSpecialArgs system;
}
)
// {
# per-node nixpkgs & specialArgs
nodeNixpkgs = lib.attrsets.mergeAttrsList (map (it: it.colmenaMeta.nodeNixpkgs or {}) nixosSystemValues);
nodeSpecialArgs = lib.attrsets.mergeAttrsList (map (it: it.colmenaMeta.nodeSpecialArgs or {}) nixosSystemValues);
};
}
// lib.attrsets.mergeAttrsList (map (it: it.colmena or {}) nixosSystemValues);
colmena = {
meta =
(
let
system = "x86_64-linux";
in
{
# colmena's default nixpkgs & specialArgs
nixpkgs = import nixpkgs { inherit system; };
specialArgs = genSpecialArgs system;
}
)
// {
# per-node nixpkgs & specialArgs
nodeNixpkgs = lib.attrsets.mergeAttrsList (
map (it: it.colmenaMeta.nodeNixpkgs or { }) nixosSystemValues
);
nodeSpecialArgs = lib.attrsets.mergeAttrsList (
map (it: it.colmenaMeta.nodeSpecialArgs or { }) nixosSystemValues
);
};
}
// lib.attrsets.mergeAttrsList (map (it: it.colmena or { }) nixosSystemValues);
# macOS Hosts
darwinConfigurations =
lib.attrsets.mergeAttrsList (map (it: it.darwinConfigurations or {}) darwinSystemValues);
darwinConfigurations = lib.attrsets.mergeAttrsList (
map (it: it.darwinConfigurations or { }) darwinSystemValues
);
# Packages
packages = forAllSystems (
system: allSystems.${system}.packages or {}
);
packages = forAllSystems (system: allSystems.${system}.packages or { });
# Eval Tests for all NixOS & darwin systems.
evalTests = lib.lists.all (it: it.evalTests == {}) allSystemValues;
evalTests = lib.lists.all (it: it.evalTests == { }) allSystemValues;
checks = forAllSystems (
system: {
# eval-tests per system
eval-tests = allSystems.${system}.evalTests == {};
checks = forAllSystems (system: {
# eval-tests per system
eval-tests = allSystems.${system}.evalTests == { };
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = mylib.relativeToRoot ".";
hooks = {
nixfmt-rfc-style = {
enable = true;
settings.width = 100;
};
# Source code spell checker
typos = {
enable = true;
settings = {
write = true; # Automatically fix typos
configPath = "./.typos.toml"; # relative to the flake root
};
};
prettier = {
enable = true;
settings = {
write = true; # Automatically format files
configPath = "./.prettierrc.yaml"; # relative to the flake root
};
};
# deadnix.enable = true; # detect unused variable bindings in `*.nix`
# statix.enable = true; # lints and suggestions for Nix code(auto suggestions)
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = mylib.relativeToRoot ".";
hooks = {
nixfmt-rfc-style = {
enable = true;
settings.width = 100;
};
# Source code spell checker
typos = {
enable = true;
settings = {
write = true; # Automatically fix typos
configPath = "./.typos.toml"; # relative to the flake root
};
};
prettier = {
enable = true;
settings = {
write = true; # Automatically format files
configPath = "./.prettierrc.yaml"; # relative to the flake root
};
};
# deadnix.enable = true; # detect unused variable bindings in `*.nix`
# statix.enable = true; # lints and suggestions for Nix code(auto suggestions)
};
}
);
};
});
# Development Shells
devShells = forAllSystems (
system: let
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in {
in
{
default = pkgs.mkShell {
packages = with pkgs; [
# fix https://discourse.nixos.org/t/non-interactive-bash-errors-from-flake-nix-mkshell/33310
@@ -159,7 +181,5 @@ in {
);
# Format the nix code in this flake
formatter = forAllSystems (
system: nixpkgs.legacyPackages.${system}.nixfmt
);
formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixfmt);
}