treewide: nix fmt
Some checks are pending
Checks / check (NIXPKGS_ALLOW_INSECURE=1 nix flake check --accept-flake-config --impure) (push) Waiting to run
Checks / check (nix run .#alejandra-custom -- -c . -e ./npins) (push) Waiting to run
Checks / build (push) Blocked by required conditions

This commit is contained in:
raf 2025-04-19 19:39:07 +03:00
commit a2ffe642ef
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
2 changed files with 99 additions and 91 deletions

View file

@ -7,7 +7,9 @@
in in
fetchTarball { fetchTarball {
url = url =
lock.nodes.${nodeName}.locked.url lock.nodes.${
nodeName
}.locked.url
or "https://github.com/edolstra/flake-compat/archive/${ or "https://github.com/edolstra/flake-compat/archive/${
lock.nodes.${nodeName}.locked.rev lock.nodes.${nodeName}.locked.rev
}.tar.gz"; }.tar.gz";

View file

@ -1,11 +1,11 @@
/* /*
This file is provided under the MIT licence: This file is provided under the MIT licence:
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: 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:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
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. 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.
*/ */
# Generated by npins. Do not modify; will be overwritten regularly # Generated by npins. Do not modify; will be overwritten regularly
let let
@ -13,8 +13,10 @@ let
version = data.version; version = data.version;
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
range = range = first: last:
first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); if first > last
then []
else builtins.genList (n: first + n) (last - first + 1);
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 # 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)); stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
@ -27,120 +29,124 @@ let
# If the environment variable NPINS_OVERRIDE_${name} is set, then use # If the environment variable NPINS_OVERRIDE_${name} is set, then use
# the path directly as opposed to the fetched source. # the path directly as opposed to the fetched source.
# (Taken from Niv for compatibility) # (Taken from Niv for compatibility)
mayOverride = mayOverride = name: path: let
name: path: envVarName = "NPINS_OVERRIDE_${saneName}";
let saneName = stringAsChars (c:
envVarName = "NPINS_OVERRIDE_${saneName}"; if (builtins.match "[a-zA-Z0-9]" c) == null
saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; then "_"
ersatz = builtins.getEnv envVarName; else c)
in name;
if ersatz == "" then ersatz = builtins.getEnv envVarName;
path in
if ersatz == ""
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 = mkSource = name: spec:
name: spec: assert spec ? type; let
assert spec ? type;
let
path = path =
if spec.type == "Git" then if spec.type == "Git"
mkGitSource spec then mkGitSource spec
else if spec.type == "GitRelease" then else if spec.type == "GitRelease"
mkGitSource spec then mkGitSource spec
else if spec.type == "PyPi" then else if spec.type == "PyPi"
mkPyPiSource spec then mkPyPiSource spec
else if spec.type == "Channel" then else if spec.type == "Channel"
mkChannelSource spec then mkChannelSource spec
else if spec.type == "Tarball" then else if spec.type == "Tarball"
mkTarballSource spec then mkTarballSource spec
else else builtins.throw "Unknown source type ${spec.type}";
builtins.throw "Unknown source type ${spec.type}";
in in
spec // { outPath = mayOverride name path; }; spec // {outPath = mayOverride name path;};
mkGitSource = mkGitSource = {
{ repository,
repository, revision,
revision, url ? null,
url ? null, submodules,
submodules, hash,
hash, branch ? null,
branch ? null, ...
... }:
}:
assert repository ? type; assert repository ? type;
# At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository # 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 # In the latter case, there we will always be an url to the tarball
if url != null && !submodules then if url != null && !submodules
builtins.fetchTarball { then
inherit url; builtins.fetchTarball {
sha256 = hash; # FIXME: check nix version & use SRI hashes inherit url;
} sha256 = hash; # FIXME: check nix version & use SRI hashes
else }
let else let
url = url =
if repository.type == "Git" then if repository.type == "Git"
repository.url then repository.url
else if repository.type == "GitHub" then else if repository.type == "GitHub"
"https://github.com/${repository.owner}/${repository.repo}.git" then "https://github.com/${repository.owner}/${repository.repo}.git"
else if repository.type == "GitLab" then else if repository.type == "GitLab"
"${repository.server}/${repository.repo_path}.git" then "${repository.server}/${repository.repo_path}.git"
else else throw "Unrecognized repository type ${repository.type}";
throw "Unrecognized repository type ${repository.type}"; urlToName = url: rev: let
urlToName = matched = builtins.match "^.*/([^/]*)(\\.git)?$" url;
url: rev:
let
matched = builtins.match "^.*/([^/]*)(\\.git)?$" url;
short = builtins.substring 0 7 rev; short = builtins.substring 0 7 rev;
appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else ""; appendShort =
in if (builtins.match "[a-f0-9]*" rev) != null
"${if matched == null then "source" else builtins.head matched}${appendShort}"; then "-${short}"
else "";
in "${
if matched == null
then "source"
else builtins.head matched
}${appendShort}";
name = urlToName url revision; name = urlToName url revision;
in in
builtins.fetchGit { builtins.fetchGit {
rev = revision; rev = revision;
inherit name; inherit name;
# hash = hash; # hash = hash;
inherit url submodules; inherit url submodules;
}; };
mkPyPiSource = mkPyPiSource = {
{ url, hash, ... }: url,
hash,
...
}:
builtins.fetchurl { builtins.fetchurl {
inherit url; inherit url;
sha256 = hash; sha256 = hash;
}; };
mkChannelSource = mkChannelSource = {
{ url, hash, ... }: url,
hash,
...
}:
builtins.fetchTarball { builtins.fetchTarball {
inherit url; inherit url;
sha256 = hash; sha256 = hash;
}; };
mkTarballSource = mkTarballSource = {
{ url,
url, locked_url ? url,
locked_url ? url, hash,
hash, ...
... }:
}:
builtins.fetchTarball { builtins.fetchTarball {
url = locked_url; url = locked_url;
sha256 = hash; sha256 = hash;
}; };
in in
if version == 5 then if version == 5
builtins.mapAttrs mkSource data.pins then builtins.mapAttrs mkSource data.pins
else else throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"
throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"