Compare commits

..

No commits in common. "47c716df21899ec29ee79160fccc8969cbcecda1" and "b985468159a02513773b3f9256bde9c85c5d8626" have entirely different histories.

7 changed files with 745 additions and 619 deletions

View file

@ -71,7 +71,6 @@ isMaximal: {
enable = isMaximal; enable = isMaximal;
extensions.crates-nvim.enable = isMaximal; extensions.crates-nvim.enable = isMaximal;
}; };
toml.enable = isMaximal;
# Language modules that are not as common. # Language modules that are not as common.
assembly.enable = false; assembly.enable = false;

View file

@ -132,12 +132,6 @@
- Added [sqruff](https://github.com/quarylabs/sqruff) support to `languages.sql` - Added [sqruff](https://github.com/quarylabs/sqruff) support to `languages.sql`
- Added [Pyrefly](https://pyrefly.org/) support to `languages.python`
- Added TOML support via {option}`languages.toml` and the
[Tombi](https://tombi-toml.github.io/tombi/) language server, linter, and
formatter.
[Machshev](https://github.com/machshev): [Machshev](https://github.com/machshev):
- Added `ruff` and `ty` LSP support for Python under `programs.python`. - Added `ruff` and `ty` LSP support for Python under `programs.python`.

View file

@ -38,7 +38,6 @@ in {
./svelte.nix ./svelte.nix
./tailwind.nix ./tailwind.nix
./terraform.nix ./terraform.nix
./toml.nix
./ts.nix ./ts.nix
./typst.nix ./typst.nix
./zig.nix ./zig.nix

View file

@ -20,21 +20,6 @@
defaultServers = ["basedpyright"]; defaultServers = ["basedpyright"];
servers = { servers = {
pyrefly = {
enable = true;
cmd = [(getExe pkgs.pyrefly) "server"];
filetypes = ["python"];
root_markers = [
"pyproject.toml"
"pyrefly.toml"
"setup.py"
"setup.cfg"
"requirements.txt"
"Pipfile"
".git"
];
};
pyright = { pyright = {
enable = true; enable = true;
cmd = [(getExe' pkgs.pyright "pyright-langserver") "--stdio"]; cmd = [(getExe' pkgs.pyright "pyright-langserver") "--stdio"];

View file

@ -1,151 +0,0 @@
{
config,
pkgs,
lib,
...
}: let
inherit (builtins) attrNames;
inherit (lib.meta) getExe;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.types) bool enum;
inherit (lib.nvim.types) diagnostics mkGrammarOption deprecatedSingleOrListOf;
inherit (lib.nvim.attrsets) mapListToAttrs;
cfg = config.vim.languages.toml;
defaultServers = ["tombi"];
servers = {
tombi = {
enable = true;
cmd = [
(getExe pkgs.tombi)
"lsp"
];
filetypes = ["toml"];
root_markers = [
"tombi.toml"
".git"
];
};
};
defaultFormat = ["tombi"];
formats = {
tombi = {
command = getExe pkgs.tombi;
args = [
"format"
"--stdin-filepath"
"$FILENAME"
"-"
];
};
};
defaultDiagnosticsProvider = ["tombi"];
diagnosticsProviders = {
tombi = {
package = pkgs.tombi;
args = ["lint"];
};
};
in {
options.vim.languages.toml = {
enable = mkEnableOption "TOML configuration language support";
treesitter = {
enable =
mkEnableOption "TOML treesitter"
// {
default = config.vim.languages.enableTreesitter;
};
package = mkGrammarOption pkgs "toml";
};
lsp = {
enable =
mkEnableOption "TOML LSP support"
// {
default = config.vim.lsp.enable;
};
servers = mkOption {
description = "TOML LSP server to use";
type = deprecatedSingleOrListOf "vim.language.toml.lsp.servers" (enum (attrNames servers));
default = defaultServers;
};
};
format = {
enable =
mkEnableOption "TOML formatting"
// {
default = config.vim.languages.enableFormat;
};
type = mkOption {
type = deprecatedSingleOrListOf "vim.language.toml.format.type" (enum (attrNames formats));
default = defaultFormat;
description = "TOML formatter to use.";
};
};
extraDiagnostics = {
enable =
mkEnableOption "extra TOML diagnostics"
// {
default = config.vim.languages.enableExtraDiagnostics;
};
types = diagnostics {
langDesc = "TOML";
inherit diagnosticsProviders;
inherit defaultDiagnosticsProvider;
};
};
};
config = mkIf cfg.enable (mkMerge [
(mkIf cfg.treesitter.enable {
vim.treesitter.enable = true;
vim.treesitter.grammars = [
cfg.treesitter.package
];
})
(mkIf cfg.lsp.enable {
vim.lsp.servers =
mapListToAttrs (n: {
name = n;
value = servers.${n};
})
cfg.lsp.servers;
})
(mkIf cfg.format.enable {
vim.formatter.conform-nvim = {
enable = true;
setupOpts = {
formatters_by_ft.toml = cfg.format.type;
formatters =
mapListToAttrs (name: {
inherit name;
value = formats.${name};
})
cfg.format.type;
};
};
})
(mkIf cfg.extraDiagnostics.enable {
vim.diagnostics.nvim-lint = {
enable = true;
linters_by_ft.toml = cfg.extraDiagnostics.types;
linters = mkMerge (
map (name: {
${name}.cmd = getExe diagnosticsProviders.${name}.package;
})
cfg.extraDiagnostics.types
);
};
})
]);
}

File diff suppressed because it is too large Load diff

View file

@ -1,176 +1,13 @@
/* {
This file is provided under the MIT licence: lib,
fetchurl,
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: fetchgit,
fetchzip,
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. }:
builtins.mapAttrs
THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. (
*/ name: let
# Generated by npins. Do not modify; will be overwritten regularly getUrl = {
let
# Backwards-compatibly make something that previously didn't take any arguments take some
# The function must return an attrset, and will unfortunately be eagerly evaluated
# Same thing, but it catches eval errors on the default argument so that one may still call it with other arguments
mkFunctor =
fn:
let
e = builtins.tryEval (fn { });
in
(if e.success then e.value else { error = fn { }; }) // { __functor = _self: fn; };
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
range =
first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1);
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
concatStrings = builtins.concatStringsSep "";
# If the environment variable NPINS_OVERRIDE_${name} is set, then use
# the path directly as opposed to the fetched source.
# (Taken from Niv for compatibility)
mayOverride =
name: path:
let
envVarName = "NPINS_OVERRIDE_${saneName}";
saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name;
ersatz = builtins.getEnv envVarName;
in
if ersatz == "" then
path
else
# this turns the string into an actual Nix path (for both absolute and
# relative paths)
builtins.trace "Overriding path of \"${name}\" with \"${ersatz}\" due to set \"${envVarName}\"" (
if builtins.substring 0 1 ersatz == "/" then
/. + ersatz
else
/. + builtins.getEnv "PWD" + "/${ersatz}"
);
mkSource =
name: spec:
{
pkgs ? null,
}:
assert spec ? type;
let
# Unify across builtin and pkgs fetchers.
# `fetchGit` requires a wrapper because of slight API differences.
fetchers =
if pkgs == null then
{
inherit (builtins) fetchTarball fetchurl;
# For some fucking reason, fetchGit has a different signature than the other builtin fetchers …
fetchGit = args: (builtins.fetchGit args).outPath;
}
else
{
fetchTarball =
{
url,
sha256,
}:
pkgs.fetchzip {
inherit url sha256;
extension = "tar";
};
inherit (pkgs) fetchurl;
fetchGit =
{
url,
submodules,
rev,
name,
narHash,
}:
pkgs.fetchgit {
inherit url rev name;
fetchSubmodules = submodules;
hash = narHash;
};
};
# Dispatch to the correct code path based on the type
path =
if spec.type == "Git" then
mkGitSource fetchers spec
else if spec.type == "GitRelease" then
mkGitSource fetchers spec
else if spec.type == "PyPi" then
mkPyPiSource fetchers spec
else if spec.type == "Channel" then
mkChannelSource fetchers spec
else if spec.type == "Tarball" then
mkTarballSource fetchers spec
else if spec.type == "Container" then
mkContainerSource pkgs spec
else
builtins.throw "Unknown source type ${spec.type}";
in
spec // { outPath = mayOverride name path; };
mkGitSource =
{
fetchTarball,
fetchGit,
...
}:
{
repository,
revision,
url ? null,
submodules,
hash,
...
}:
assert repository ? type;
# At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository
# In the latter case, there we will always be an url to the tarball
if url != null && !submodules then
fetchTarball {
inherit url;
sha256 = hash;
}
else
let
url =
if repository.type == "Git" then
repository.url
else if repository.type == "GitHub" then
"https://github.com/${repository.owner}/${repository.repo}.git"
else if repository.type == "GitLab" then
"${repository.server}/${repository.repo_path}.git"
else if repository.type == "Forgejo" then
"${repository.server}/${repository.owner}/${repository.repo}.git"
else
throw "Unrecognized repository type ${repository.type}";
urlToName =
url: rev:
let
matched = builtins.match "^.*/([^/]*)(\\.git)?$" url;
short = builtins.substring 0 7 rev;
appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else "";
in
"${if matched == null then "source" else builtins.head matched}${appendShort}";
name = urlToName url revision;
in
fetchGit {
rev = revision;
narHash = hash;
inherit name submodules url;
};
mkPyPiSource =
{ fetchurl, ... }:
{
url, url,
hash, hash,
... ...
@ -179,71 +16,99 @@ let
inherit url; inherit url;
sha256 = hash; sha256 = hash;
}; };
getZip = {
mkChannelSource =
{ fetchTarball, ... }:
{
url, url,
hash, hash,
... ...
}: }:
fetchTarball { fetchzip {
inherit url; inherit url;
sha256 = hash; sha256 = hash;
extension = "tar";
}; };
mkGitSource = {
mkTarballSource = repository,
{ fetchTarball, ... }: revision,
{ url ? null,
url, submodules,
locked_url ? url,
hash, hash,
... ...
}: } @ attrs:
fetchTarball { assert repository ? type;
url = locked_url; if url != null && !submodules
sha256 = hash; then getZip attrs
}; else
assert repository.type == "Git"; let
url' =
if repository.type == "Git"
then repository.url
else if repository.type == "GitHub"
then "https://github.com/${repository.owner}/${repository.repo}.git"
else if repository.type == "GitLab"
then "${repository.server}/${repository.repo_path}.git"
else throw "Unrecognized repository type ${repository.type}";
mkContainerSource = name = let
pkgs: matched = builtins.match "^.*/([^/]*)(\\.git)?$" url';
{ short = builtins.substring 0 7 revision;
image_name, appendShort =
image_tag, if (builtins.match "[a-f0-9]*" revision) != null
image_digest, then "-${short}"
... else "";
}: in "${
if pkgs == null then if matched == null
builtins.throw "container sources require passing in a Nixpkgs value: https://github.com/andir/npins/blob/master/README.md#using-the-nixpkgs-fetchers" then "source"
else else builtins.head matched
pkgs.dockerTools.pullImage { }${appendShort}";
imageName = image_name;
imageDigest = image_digest;
finalImageTag = image_tag;
};
in
mkFunctor (
{
input ? ./sources.json,
}:
let
data =
if builtins.isPath input then
# while `readFile` will throw an error anyways if the path doesn't exist,
# we still need to check beforehand because *our* error can be caught but not the one from the builtin
# *piegames sighs*
if builtins.pathExists input then
builtins.fromJSON (builtins.readFile input)
else
throw "Input path ${toString input} does not exist"
else if builtins.isAttrs input then
input
else
throw "Unsupported input type ${builtins.typeOf input}, must be a path or an attrset";
version = data.version;
in in
if version == 7 then fetchgit {
builtins.mapAttrs (name: spec: mkFunctor (mkSource name spec)) data.pins inherit name;
url = url';
rev = revision;
sha256 = hash;
fetchSubmodules = submodules;
};
in
spec:
assert spec ? type; let
mayOverride = path: let
envVarName = "NPINS_OVERRIDE_${saneName}";
saneName = lib.stringAsChars (c:
if (builtins.match "[a-zA-Z0-9]" c) == null
then "_"
else c)
name;
ersatz = builtins.getEnv envVarName;
in
if ersatz == ""
then path
else else
throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`" # this turns the string into an actual Nix path (for both absolute and
# relative paths)
builtins.trace "Overriding path of \"${name}\" with \"${ersatz}\" due to set \"${envVarName}\"" (
if builtins.substring 0 1 ersatz == "/"
then /. + ersatz
else /. + builtins.getEnv "PWD" + "/${ersatz}"
);
func =
{
Git = mkGitSource;
GitRelease = mkGitSource;
PyPi = getUrl;
Channel = getZip;
Tarball = getUrl;
}
.${
spec.type
}
or (builtins.throw "Unknown source type ${spec.type}");
in
spec // {outPath = mayOverride (func spec);}
)
(
let
json = lib.importJSON ./sources.json;
in
assert lib.assertMsg (json.version == 5) "Npins version mismatch!";
json.pins
) )