1
0
Fork 0

Use flake-parts for managing languages

This commit is contained in:
Ethan Reece 2025-07-13 23:33:47 -05:00
parent 0fffeb6e55
commit 9e4bc003cb
Signed by: me
GPG key ID: DD8CE04D5D8FF832
118 changed files with 494 additions and 383 deletions

4
.envrc
View file

@ -1,3 +1,3 @@
watch_file ./languages
watch_file ./.vale/styles
watch_dir ./languages
watch_dir ./modules
use flake

View file

@ -10,7 +10,8 @@ for this Flake.
## ⭐ Features
- 🏠 **`home-manager`**: Defines the user environment.
- 🧩 **`flake-parts`**: Makes the Flake modular and reusable.
- 🧩 **`flake-parts`**: Makes the Flake modular and reusable, enabling clean
separation of components.
- 🔐 **`sops`**: Encrypts secrets.
- ✨ **`treefmt`** (with Helix integration): Automatically formats the code in
this repository when modifying it, with features to check the flake for

153
flake.nix
View file

@ -39,10 +39,9 @@
{
systems = [ "aarch64-linux" ];
imports = [
inputs.devshell.flakeModule
inputs.git-hooks-nix.flakeModule
inputs.home-manager.flakeModules.home-manager
inputs.treefmt-nix.flakeModule
./modules
./languages
];
flake = {
# https://nix-community.github.io/home-manager/options.xhtml
@ -53,37 +52,20 @@
inherit pkgs;
extraSpecialArgs = { inherit inputs pkgs; };
modules = [
./home/home.nix
inputs.stylix.homeModules.stylix
inputs.catppuccin.homeModules.catppuccin
{ nixpkgs.overlays = [ inputs.nur.overlays.default ]; }
inputs.lix-module.nixosModules.default
inputs.sops-nix.homeManagerModules.sops
{ nixpkgs.overlays = [ inputs.nur.overlays.default ]; }
inputs.stylix.homeModules.stylix
inputs.catppuccin.homeModules.catppuccin
./home/home.nix
];
}
);
};
};
perSystem =
{ system, config, ... }:
{ system, ... }:
let
deepMerge =
lhs: rhs:
lhs
// rhs
// (builtins.mapAttrs (
rName: rValue:
let
lValue = lhs.${rName} or null;
in
if builtins.isAttrs lValue && builtins.isAttrs rValue then
deepMerge lValue rValue
else if builtins.isList lValue && builtins.isList rValue then
lValue ++ rValue
else
rValue
) rhs);
tomlFormatter = pkgs.formats.toml { };
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
@ -91,43 +73,6 @@
inputs.nixgl.overlays.default
];
};
treefmt = config.treefmt.build.wrapper;
langDir = ./languages;
langFiles = builtins.attrNames (builtins.readDir langDir);
nixFiles = builtins.filter (name: builtins.match ".*\\.nix" name != null) langFiles;
configs = map (file: import (langDir + "/${file}") { inherit pkgs treefmt; }) nixFiles;
helixLanguages = {
directory = ".helix";
filename = "languages.toml";
content = {
language = map (cfg: cfg.helix.language) (
(builtins.filter (cfg: builtins.hasAttr "language" cfg.helix) (
builtins.filter (cfg: builtins.hasAttr "helix" cfg) configs
))
);
language-server = builtins.foldl' (acc: cfg: acc // (cfg.helix.language-server or { })) { } configs;
};
file = tomlFormatter.generate "languages.toml" helixLanguages.content;
};
treefmtPrograms = builtins.foldl' (
acc: cfg: deepMerge acc (cfg.treefmt.programs or { })
) { } configs;
preCommitHooks = builtins.foldl' (acc: cfg: acc // (cfg.pre-commit or { })) { } configs;
devshellConfigs = {
commands = builtins.concatMap (cfg: cfg.devshell.commands) (
(builtins.filter (cfg: builtins.hasAttr "commands" cfg.devshell) (
builtins.filter (cfg: builtins.hasAttr "devshell" cfg) configs
))
);
packages = builtins.concatMap (cfg: cfg.devshell.packages) (
(builtins.filter (cfg: builtins.hasAttr "packages" cfg.devshell) (
builtins.filter (cfg: builtins.hasAttr "devshell" cfg) configs
))
);
devshellStartup = builtins.foldl' (
acc: cfg: acc // (cfg.devshell.devshellStartup or { })
) { } configs;
};
in
{
_module.args.pkgs = pkgs;
@ -135,100 +80,52 @@
devshells.default = {
commands = [
{
help = "`home-manager switch` for asahi";
name = "switch-asahi";
help = " `home-manager switch` for asahi";
name = "hm-asahi";
command = "${pkgs.home-manager}/bin/home-manager switch --flake .#asahi";
category = " home-manager (Asahi)";
}
{
help = "`home-manager switch` for asahi with backup";
name = "switch-asahi-backup";
help = "󰸨 `home-manager switch` for asahi with backup";
name = "hm-asahi-backup";
command = "${pkgs.home-manager}/bin/home-manager switch --flake .#asahi -b backup";
category = " home-manager (Asahi)";
}
{
help = "update dependencies";
name = "update";
command = "${pkgs.lix}/bin/nix flake update";
}
{
help = "show home-manager documentation";
help = "󰘥 show home-manager documentation";
name = "man-home";
command = "${pkgs.man}/bin/man home-configuration.nix";
category = " home-manager";
}
{
help = "generate Helix grammars";
name = "_helix-grammars";
command = "${pkgs.helix}/bin/hx --grammar fetch && hx --grammar build";
}
{
help = "generate age key";
name = "_age-generate-key";
help = " generate age key";
name = "age-generate-key";
command = "${pkgs.uutils-coreutils-noprefix}/bin/mkdir -p ~/.config/sops/age && ${pkgs.age}/bin/age-keygen -o ~/.config/sops/age/keys.txt && ${pkgs.uutils-coreutils-noprefix}/bin/cat ~/.config/sops/age/keys.txt";
category = " SOPS";
}
{
help = "edit secrets.yaml";
help = " edit secrets.yaml";
name = "sops-edit";
command = "${pkgs.sops}/bin/sops edit ./home/secrets/secrets.yaml";
category = " SOPS";
}
] ++ devshellConfigs.commands;
];
packages = [
pkgs.age
pkgs.forgejo-cli
pkgs.git
pkgs.helix
pkgs.home-manager
pkgs.jujutsu
pkgs.lix
pkgs.man
pkgs.sops
pkgs.uutils-coreutils-noprefix
] ++ devshellConfigs.packages;
];
devshell = {
motd = ''
{202}🔨 Nix Laptop Configuration{reset}
{202} Nix Laptop Configuration{reset}
$(type -p menu &>/dev/null && menu)
'';
name = "Laptop Configuration";
startup = devshellConfigs.devshellStartup // {
# https://github.com/helix-editor/helix/blob/master/languages.toml
# https://helix-editor.vercel.app/reference/formatters
# https://docs.helix-editor.com/lang-support.html
helix_config = {
text = ''
mkdir -p .helix
${pkgs.uutils-coreutils-noprefix}/bin/ln -fs ${helixLanguages.file} ./${helixLanguages.directory}/${helixLanguages.filename}
'';
};
pre-commit.text = ''
${config.pre-commit.installationScript}
'';
};
};
};
# https://flake.parts/options/git-hooks-nix.html
pre-commit.settings = {
hooks = preCommitHooks // {
treefmt = {
enable = true;
package = treefmt;
};
check-merge-conflicts.enable = true;
check-symlinks.enable = true;
flake-checker.enable = true;
};
excludes = [
".vale"
"home/vencord.nix"
];
};
# https://flake.parts/options/treefmt-nix.html
treefmt = {
projectRootFile = "flake.nix";
programs = treefmtPrograms;
settings.global.excludes = [
".vale/*"
"home/vencord.nix"
];
};
pre-commit.settings.excludes = [ "home/vencord.nix" ];
treefmt.settings.global.excludes = [ "home/vencord.nix" ];
};
}
);

View file

@ -786,6 +786,10 @@ in
name = "ltex-plus Supported Languages";
url = "https://ltex-plus.github.io/ltex-plus/supported-languages.html";
}
{
name = "Nerd Fonts Cheatsheet";
url = "https://www.nerdfonts.com/cheat-sheet";
}
{
name = "Nix Firefox Addons Search";
url = "https://nur.nix-community.org/repos/rycee/";

8
languages/default.nix Normal file
View file

@ -0,0 +1,8 @@
{ ... }:
let
entries = builtins.attrNames (builtins.readDir ./.);
configs = builtins.filter (dir: builtins.pathExists (./. + "/${dir}/default.nix")) entries;
in
{
imports = builtins.map (name: (./. + "/${name}")) configs;
}

View file

@ -1,123 +0,0 @@
{ pkgs, treefmt }:
let
dictionary = [
"Asahi"
"Catppuccin"
"LLMs"
"LTeX"
"NixOS"
"Nushell"
"Stylix"
];
tomlFormatter = pkgs.formats.toml { };
vale = {
valeDirectory = ".vale";
stylesDirectory = "styles";
dictionary = {
directory = "config/vocabularies/General";
filename = "accept.txt";
content = builtins.concatStringsSep "\n" dictionary;
file = pkgs.writeTextFile {
name = vale.dictionary.filename;
text = vale.dictionary.content;
};
};
config = {
filename = ".vale.ini";
content = ''
StylesPath = styles
MinAlertLevel = suggestion
Vocab = General
# https://vale.sh/explorer
Packages = RedHat, proselint, write-good, alex
[*.{md}]
BasedOnStyles = Vale, RedHat, proselint, write-good, alex
'';
file = pkgs.writeTextFile {
name = vale.config.filename;
text = vale.config.content;
};
};
directory = {
base = ../.vale/styles;
full = pkgs.runCommand vale.valeDirectory { } ''
${pkgs.uutils-coreutils-noprefix}/bin/mkdir -p $out/${vale.stylesDirectory}/${vale.dictionary.directory}
${pkgs.uutils-coreutils-noprefix}/bin/cp -r ${vale.directory.base}/* $out/${vale.stylesDirectory}
${pkgs.uutils-coreutils-noprefix}/bin/ln -fs ${vale.dictionary.file} $out/${vale.stylesDirectory}/${vale.dictionary.directory}/${vale.dictionary.filename}
${pkgs.uutils-coreutils-noprefix}/bin/ln -fs ${vale.config.file} $out/${vale.config.filename};
'';
configFile = "${vale.directory.full}/${vale.config.filename}";
};
};
typos = {
content = {
default.extendWords = builtins.listToAttrs (
builtins.map (x: {
name = x;
value = x;
}) dictionary
);
};
file = tomlFormatter.generate "typos.toml" typos.content;
};
in
{
helix.language-server = {
# https://ltex-plus.github.io/ltex-plus/supported-languages.html
ltex-ls-plus = {
command = "${pkgs.ltex-ls-plus}/bin/ltex-ls-plus";
config.ltex = {
dictionary.en-US = dictionary;
additionalRules.enablePickyRules = true;
};
};
# https://vale.sh/docs/formats/code
vale-ls = {
command = "${pkgs.vale-ls}/bin/vale-ls";
config.configPath = vale.directory.configFile;
};
# https://writewithharper.com/docs/integrations/language-server#Supported-Languages
harper-ls.command = "${pkgs.harper}/bin/harper-ls";
typos = {
command = "${pkgs.typos-lsp}/bin/typos-lsp";
config.config = typos.file.outPath;
};
};
pre-commit = {
typos = {
enable = true;
settings = {
configPath = typos.file.outPath;
locale = "en-us";
};
};
vale = {
enable = true;
settings.configPath = vale.directory.configFile;
};
};
treefmt.programs.typos = {
enable = true;
configFile = typos.file.outPath;
locale = "en-us";
};
devshell = {
commands = [
{
help = "sync vale configuration";
name = "vale-sync";
command = "${pkgs.vale}/bin/vale sync --config ${vale.valeDirectory}/${vale.config.filename}";
}
];
packages = [ pkgs.vale ];
devshellStartup = {
vale_config.text = ''
${pkgs.uutils-coreutils-noprefix}/bin/ln -fs ${vale.config.file} ${vale.valeDirectory}/${vale.config.filename}
'';
};
};
}

View file

@ -0,0 +1 @@
/nix/store/qjykb097qnh6c6qrl9v58143kj5j9mn5-vale.ini

Some files were not shown because too many files have changed in this diff Show more