1
1
mirror of https://github.com/nmattia/niv.git synced 2024-09-18 19:07:19 +03:00

Prettify the derivation name in tarballs

The derivation name for package `foo` of type `tarball` is now `foo-src`
as opposed to `source`.
This commit is contained in:
Nicolas Mattia 2020-03-27 11:51:30 +01:00
parent 89e6f36b6f
commit 372f96bff2
2 changed files with 26 additions and 8 deletions

View File

@ -12,11 +12,16 @@ let
else
pkgs.fetchurl { inherit (spec) url sha256; };
fetch_tarball = pkgs: spec:
if spec.builtin or true then
builtins_fetchTarball { inherit (spec) url sha256; }
else
pkgs.fetchzip { inherit (spec) url sha256; };
fetch_tarball = pkgs: name: spec:
let
ok = str: ! builtins.isNull (builtins.match "[a-zA-Z0-9+-._?=]" str);
# sanitize the name, though nix will still fail if name starts with period
name' = stringAsChars (x: if ! ok x then "-" else x) "${name}-src";
in
if spec.builtin or true then
builtins_fetchTarball { name = name'; inherit (spec) url sha256; }
else
pkgs.fetchzip { name = name'; inherit (spec) url sha256; };
fetch_git = spec:
builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; };
@ -58,7 +63,7 @@ let
if ! builtins.hasAttr "type" spec then
abort "ERROR: niv spec ${name} does not have a 'type' attribute"
else if spec.type == "file" then fetch_file pkgs spec
else if spec.type == "tarball" then fetch_tarball pkgs spec
else if spec.type == "tarball" then fetch_tarball pkgs name spec
else if spec.type == "git" then fetch_git spec
else if spec.type == "builtin-tarball" then fetch_builtin-tarball name
else if spec.type == "builtin-url" then fetch_builtin-url name
@ -73,13 +78,23 @@ let
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))
);
# 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 "";
# fetchTarball version that is compatible between all the versions of Nix
builtins_fetchTarball = { url, sha256 }@attrs:
builtins_fetchTarball = { url, name, sha256 }@attrs:
let
inherit (builtins) lessThan nixVersion fetchTarball;
in
if lessThan nixVersion "1.12" then
fetchTarball { inherit url; }
fetchTarball { inherit name url; }
else
fetchTarball attrs;

View File

@ -148,6 +148,7 @@ data SourcesNixVersion
| V15
| V16
| V17
| V18
deriving stock (Bounded, Enum, Eq)
-- | A user friendly version
@ -170,6 +171,7 @@ sourcesVersionToText = \case
V15 -> "15"
V16 -> "16"
V17 -> "17"
V18 -> "18"
latestVersionMD5 :: T.Text
latestVersionMD5 = sourcesVersionToMD5 maxBound
@ -199,6 +201,7 @@ sourcesVersionToMD5 = \case
V15 -> "dc11af910773ec9b4e505e0f49ebcfd2"
V16 -> "2d93c52cab8e960e767a79af05ca572a"
V17 -> "149b8907f7b08dc1c28164dfa55c7fad"
V18 -> "5fec8217a6e712c817f9de5289d85fbe"
-- | The MD5 sum of ./nix/sources.nix
sourcesNixMD5 :: IO T.Text