Merge pull request #1345 from Gerg-L/main
Some checks are pending
Set up binary cache / cachix (default) (push) Waiting to run
Set up binary cache / cachix (maximal) (push) Waiting to run
Set up binary cache / cachix (nix) (push) Waiting to run
Treewide Checks / Validate flake (push) Waiting to run
Treewide Checks / Check formatting (push) Waiting to run
Treewide Checks / Check source tree for typos (push) Waiting to run
Treewide Checks / Validate documentation builds (push) Waiting to run
Treewide Checks / Validate hyperlinks in documentation sources (push) Waiting to run
Treewide Checks / Validate Editorconfig conformance (push) Waiting to run
Build and deploy documentation / Check latest commit (push) Waiting to run
Build and deploy documentation / publish (push) Blocked by required conditions

npins: update to version 7
This commit is contained in:
raf 2026-01-15 06:28:34 +03:00 committed by GitHub
commit efad785883
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 756 additions and 466 deletions

View file

@ -11,17 +11,6 @@
getPin = flip getAttr (pkgs.callPackages ../../../npins/sources.nix {}); getPin = flip getAttr (pkgs.callPackages ../../../npins/sources.nix {});
noBuildPlug = pname: let
pin = getPin pname;
version = builtins.substring 0 8 pin.revision;
in
pin.outPath.overrideAttrs {
inherit pname version;
name = "${pname}-${version}";
passthru.vimPlugin = false;
};
# Build a Vim plugin with the given name and arguments. # Build a Vim plugin with the given name and arguments.
buildPlug = attrs: let buildPlug = attrs: let
pin = getPin attrs.pname; pin = getPin attrs.pname;
@ -49,7 +38,7 @@
# Checkhealth fails to get the plugin's commit and therefore to # Checkhealth fails to get the plugin's commit and therefore to
# show the rest of the useful diagnostics if not built like this. # show the rest of the useful diagnostics if not built like this.
obsidian-nvim = pkgs.vimUtils.buildVimPlugin { obsidian-nvim = pkgs.vimUtils.buildVimPlugin {
# If set to `"obsidian-nvim"`, this breaks like `buildPlug` and `noBuildPlug`. # If set to `"obsidian-nvim"`, this breaks like `buildPlug` and .
name = "obsidian.nvim"; name = "obsidian.nvim";
src = getPin "obsidian-nvim"; src = getPin "obsidian-nvim";
nvimSkipModules = [ nvimSkipModules = [
@ -80,7 +69,7 @@
if (lib.isType "flake" plugin) if (lib.isType "flake" plugin)
then plugin // {name = plug;} then plugin // {name = plug;}
else plugin) else plugin)
else pluginBuilders.${plug} or (noBuildPlug plug) else pluginBuilders.${plug} or (getPin plug)
else plug) ( else plug) (
filter (f: f != null) plugins filter (f: f != null) plugins
); );

File diff suppressed because it is too large Load diff

View file

@ -1,249 +1,115 @@
/* {
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: spec: let
# Generated by npins. Do not modify; will be overwritten regularly mayOverride = name: path: let
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}"; envVarName = "NPINS_OVERRIDE_${saneName}";
saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; saneName = builtins.concatStringsSep "_" (
builtins.concatLists (
builtins.filter (x: builtins.isList x && x != [""]) (builtins.split "([a-zA-Z0-9]*)" name)
)
);
ersatz = builtins.getEnv envVarName; ersatz = builtins.getEnv envVarName;
in in
if ersatz == "" then if ersatz == ""
path then path
else else
# this turns the string into an actual Nix path (for both absolute and # this turns the string into an actual Nix path (for both absolute and
# relative paths) # relative paths)
builtins.trace "Overriding path of \"${name}\" with \"${ersatz}\" due to set \"${envVarName}\"" ( builtins.trace "Overriding path of \"${name}\" with \"${ersatz}\" due to set \"${envVarName}\"" (
if builtins.substring 0 1 ersatz == "/" then if builtins.substring 0 1 ersatz == "/"
/. + ersatz then /. + ersatz
else else /. + builtins.getEnv "PWD" + "/${ersatz}"
/. + builtins.getEnv "PWD" + "/${ersatz}"
); );
mkSource = path =
name: spec: rec {
{ GitRelease = Git;
pkgs ? null, Channel = Tarball;
}:
assert spec ? type; Git =
let if spec.url != null && !spec.submodules
# Unify across builtin and pkgs fetchers. then Tarball
# `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 else
fetchgit (
let
repo = spec.repository;
url =
{ {
fetchTarball = Git = repo.url;
{ GitHub = "https://github.com/${repo.owner}/${repo.repo}.git";
url, GitLab = "${repo.server}/${repo.repo_path}.git";
sha256, Forgejo = "${repo.server}/${repo.owner}/${repo.repo}.git";
}: }
pkgs.fetchzip { .${
inherit url sha256; repo.type
} or (throw "Unrecognized repository type ${repo.type}");
in {
name = let
matched = builtins.match "^.*/([^/]*)(\\.git)?$" url;
appendShort =
if (builtins.match "[a-f0-9]*" spec.revision) != null
then "-${builtins.substring 0 7 spec.revision}"
else "";
in "${
if matched == null
then "source"
else builtins.head matched
}${appendShort}";
inherit url;
rev = spec.revision;
inherit (spec) hash;
fetchSubmodules = spec.submodules;
}
);
PyPi = fetchurl {
inherit (spec) url hash;
};
Tarball = fetchzip {
inherit (spec) url hash;
extension = "tar"; 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 spec.type
url = } or (builtins.throw "Unknown source type ${spec.type}");
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; version =
if spec ? revision
appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else ""; then builtins.substring 0 8 spec.revision
else "0";
in in
"${if matched == null then "source" else builtins.head matched}${appendShort}"; spec
name = urlToName url revision; // {
in name = "${name}-${version}";
fetchGit { pname = name;
rev = revision; inherit version;
narHash = hash; outPath =
(
inherit name submodules url; # Override logic won't do anything if we're in pure eval
}; if builtins ? currentSystem
then mayOverride name path
mkPyPiSource = else path
{ fetchurl, ... }: ).overrideAttrs
{ {
url, pname = name;
hash, name = "${name}-${version}";
... inherit version;
}:
fetchurl {
inherit url;
sha256 = hash;
}; };
}
mkChannelSource = )
{ fetchTarball, ... }: (
{ let
url, json = lib.importJSON ./sources.json;
hash, in
... assert lib.assertMsg (json.version == 7) "Unsupported format version ${toString json.version} in sources.json. Try running `npins upgrade`";
}: json.pins
fetchTarball {
inherit url;
sha256 = hash;
};
mkTarballSource =
{ fetchTarball, ... }:
{
url,
locked_url ? url,
hash,
...
}:
fetchTarball {
url = locked_url;
sha256 = hash;
};
mkContainerSource =
pkgs:
{
image_name,
image_tag,
image_digest,
...
}:
if pkgs == null then
builtins.throw "container sources require passing in a Nixpkgs value: https://github.com/andir/npins/blob/master/README.md#using-the-nixpkgs-fetchers"
else
pkgs.dockerTools.pullImage {
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
if version == 7 then
builtins.mapAttrs (name: spec: mkFunctor (mkSource name spec)) data.pins
else
throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"
) )