mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-16 02:33:25 +00:00
20 lines
683 B
Nix
20 lines
683 B
Nix
{ lib }:
|
|
|
|
let
|
|
inherit (lib) removeSuffix hasPrefix removePrefix splitString stringToCharacters concatMapStrings last elem;
|
|
|
|
allowedChars = stringToCharacters "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-._?=";
|
|
sanitizeStoreName = s:
|
|
let
|
|
s' = concatMapStrings (c: if elem c allowedChars then c else "") (stringToCharacters s);
|
|
s'' = if hasPrefix "." s' then "_${removePrefix "." s'}" else s';
|
|
in
|
|
s'';
|
|
in
|
|
urlOrRepo: rev:
|
|
let
|
|
repo' = last (splitString ":" (baseNameOf (removeSuffix ".git" (removeSuffix "/" urlOrRepo))));
|
|
rev' = baseNameOf rev;
|
|
in
|
|
"${sanitizeStoreName repo'}-${sanitizeStoreName rev'}-src"
|