make-derivation: use pname-version as default name if both are present
This commit is contained in:
parent
48caae5045
commit
320c9c10de
|
@ -236,6 +236,26 @@ rec {
|
||||||
in lenContent >= lenSuffix &&
|
in lenContent >= lenSuffix &&
|
||||||
substring (lenContent - lenSuffix) lenContent content == suffix;
|
substring (lenContent - lenSuffix) lenContent content == suffix;
|
||||||
|
|
||||||
|
/* Determine whether a string contains the given infix
|
||||||
|
|
||||||
|
Type: hasInfix :: string -> string -> bool
|
||||||
|
|
||||||
|
Example:
|
||||||
|
hasInfix "bc" "abcd"
|
||||||
|
=> true
|
||||||
|
hasInfix "ab" "abcd"
|
||||||
|
=> true
|
||||||
|
hasInfix "cd" "abcd"
|
||||||
|
=> true
|
||||||
|
hasInfix "foo" "abcd"
|
||||||
|
=> false
|
||||||
|
*/
|
||||||
|
hasInfix = infix: content:
|
||||||
|
let
|
||||||
|
drop = x: substring 1 (stringLength x) x;
|
||||||
|
in hasPrefix infix content
|
||||||
|
|| content != "" && hasInfix infix (drop content);
|
||||||
|
|
||||||
/* Convert a string to a list of characters (i.e. singleton strings).
|
/* Convert a string to a list of characters (i.e. singleton strings).
|
||||||
This allows you to, e.g., map a function over each character. However,
|
This allows you to, e.g., map a function over each character. However,
|
||||||
note that this will likely be horribly inefficient; Nix is not a
|
note that this will likely be horribly inefficient; Nix is not a
|
||||||
|
|
|
@ -65,6 +65,8 @@ rec {
|
||||||
, pos ? # position used in error messages and for meta.position
|
, pos ? # position used in error messages and for meta.position
|
||||||
(if attrs.meta.description or null != null
|
(if attrs.meta.description or null != null
|
||||||
then builtins.unsafeGetAttrPos "description" attrs.meta
|
then builtins.unsafeGetAttrPos "description" attrs.meta
|
||||||
|
else if attrs.version or null != null
|
||||||
|
then builtins.unsafeGetAttrPos "version" attrs
|
||||||
else builtins.unsafeGetAttrPos "name" attrs)
|
else builtins.unsafeGetAttrPos "name" attrs)
|
||||||
, separateDebugInfo ? false
|
, separateDebugInfo ? false
|
||||||
, outputs ? [ "out" ]
|
, outputs ? [ "out" ]
|
||||||
|
@ -79,6 +81,15 @@ rec {
|
||||||
, ... } @ attrs:
|
, ... } @ attrs:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
# Check that the name is consistent with pname and version:
|
||||||
|
selfConsistent = (with attrs; attrs ? "name" ->
|
||||||
|
(lib.assertMsg (attrs ? "version" -> lib.strings.hasInfix version name)
|
||||||
|
"version ${version} does not appear in name ${name}" &&
|
||||||
|
lib.assertMsg (attrs ? "pname" -> lib.strings.hasInfix pname name)
|
||||||
|
"pname ${pname} does not appear in name ${name}"));
|
||||||
|
|
||||||
|
computedName = if name != "" then name else "${attrs.pname}-${attrs.version}";
|
||||||
|
|
||||||
# TODO(@oxij, @Ericson2314): This is here to keep the old semantics, remove when
|
# TODO(@oxij, @Ericson2314): This is here to keep the old semantics, remove when
|
||||||
# no package has `doCheck = true`.
|
# no package has `doCheck = true`.
|
||||||
doCheck' = doCheck && stdenv.hostPlatform == stdenv.buildPlatform;
|
doCheck' = doCheck && stdenv.hostPlatform == stdenv.buildPlatform;
|
||||||
|
@ -175,7 +186,7 @@ rec {
|
||||||
// {
|
// {
|
||||||
# A hack to make `nix-env -qa` and `nix search` ignore broken packages.
|
# A hack to make `nix-env -qa` and `nix search` ignore broken packages.
|
||||||
# TODO(@oxij): remove this assert when something like NixOS/nix#1771 gets merged into nix.
|
# TODO(@oxij): remove this assert when something like NixOS/nix#1771 gets merged into nix.
|
||||||
name = assert validity.handled && (separateDebugInfo -> stdenv.hostPlatform.isLinux); name + lib.optionalString
|
name = assert selfConsistent && validity.handled && (separateDebugInfo -> stdenv.hostPlatform.isLinux); computedName + lib.optionalString
|
||||||
# Fixed-output derivations like source tarballs shouldn't get a host
|
# Fixed-output derivations like source tarballs shouldn't get a host
|
||||||
# suffix. But we have some weird ones with run-time deps that are
|
# suffix. But we have some weird ones with run-time deps that are
|
||||||
# just used for their side-affects. Those might as well since the
|
# just used for their side-affects. Those might as well since the
|
||||||
|
@ -287,7 +298,7 @@ rec {
|
||||||
meta = {
|
meta = {
|
||||||
# `name` above includes cross-compilation cruft (and is under assert),
|
# `name` above includes cross-compilation cruft (and is under assert),
|
||||||
# lets have a clean always accessible version here.
|
# lets have a clean always accessible version here.
|
||||||
inherit name;
|
name = computedName;
|
||||||
|
|
||||||
# If the packager hasn't specified `outputsToInstall`, choose a default,
|
# If the packager hasn't specified `outputsToInstall`, choose a default,
|
||||||
# which is the name of `p.bin or p.out or p`;
|
# which is the name of `p.bin or p.out or p`;
|
||||||
|
|
Loading…
Reference in a new issue