buildPerlPackage: don't mess with `pname` and phase out use of `name`

Currently `buildPerlPackage` prefixes the Perl version to the package's
`pname`, which results in `nix run` not being able to work for any
packages build with it out of the box. This commit corrects that and
phases out the ability to set `name` directly, as well as refactors the
code to not require `cleanedAttrs`.

Changed files
+21 -27
doc
languages-frameworks
pkgs
development
perl-modules
generic
+15 -11
doc/languages-frameworks/perl.section.md
···
# Perl {#sec-language-perl}
-
## Running perl programs on the shell {#ssec-perl-running}
+
## Running Perl programs on the shell {#ssec-perl-running}
When executing a Perl script, it is possible you get an error such as `./myscript.pl: bad interpreter: /usr/bin/perl: no such file or directory`. This happens when the script expects Perl to be installed at `/usr/bin/perl`, which is not the case when using Perl from nixpkgs. You can fix the script by changing the first line to:
···
```nix
ClassC3 = buildPerlPackage rec {
-
name = "Class-C3-0.21";
+
pname = "Class-C3";
+
version = "0.21";
src = fetchurl {
-
url = "mirror://cpan/authors/id/F/FL/FLORA/${name}.tar.gz";
+
url = "mirror://cpan/authors/id/F/FL/FLORA/${pname}-${version}.tar.gz";
sha256 = "1bl8z095y4js66pwxnm7s853pi9czala4sqc743fdlnk27kq94gz";
};
};
```
-
Note the use of `mirror://cpan/`, and the `${name}` in the URL definition to ensure that the name attribute is consistent with the source that we’re actually downloading. Perl packages are made available in `all-packages.nix` through the variable `perlPackages`. For instance, if you have a package that needs `ClassC3`, you would typically write
+
Note the use of `mirror://cpan/`, and the `pname` and `version` in the URL definition to ensure that the `pname` attribute is consistent with the source that we’re actually downloading. Perl packages are made available in `all-packages.nix` through the variable `perlPackages`. For instance, if you have a package that needs `ClassC3`, you would typically write
```nix
foo = import ../path/to/foo.nix {
···
{ buildPerlPackage, fetchurl, db }:
buildPerlPackage rec {
-
name = "BerkeleyDB-0.36";
+
pname = "BerkeleyDB";
+
version = "0.36";
src = fetchurl {
-
url = "mirror://cpan/authors/id/P/PM/PMQS/${name}.tar.gz";
+
url = "mirror://cpan/authors/id/P/PM/PMQS/${pname}-${version}.tar.gz";
sha256 = "07xf50riarb60l1h6m2dqmql8q5dij619712fsgw7ach04d8g3z1";
};
···
```nix
ClassC3Componentised = buildPerlPackage rec {
-
name = "Class-C3-Componentised-1.0004";
+
pname = "Class-C3-Componentised";
+
version = "1.0004";
src = fetchurl {
-
url = "mirror://cpan/authors/id/A/AS/ASH/${name}.tar.gz";
+
url = "mirror://cpan/authors/id/A/AS/ASH/${pname}-${version}.tar.gz";
sha256 = "0xql73jkcdbq4q9m0b0rnca6nrlvf5hyzy8is0crdk65bynvs8q1";
};
propagatedBuildInputs = [
···
version = "11.50";
src = fetchurl {
-
url = "https://www.sno.phy.queensu.ca/~phil/exiftool/Image-ExifTool-11.50.tar.gz";
+
url = "https://www.sno.phy.queensu.ca/~phil/exiftool/${pname}-${version}.tar.gz";
sha256 = "0d8v48y94z8maxkmw1rv7v9m0jg2dc8xbp581njb6yhr7abwqdv3";
};
···
```ShellSession
$ nix-generate-from-cpan XML::Simple
XMLSimple = buildPerlPackage rec {
-
name = "XML-Simple-2.22";
+
pname = "XML-Simple";
+
version = "2.22";
src = fetchurl {
-
url = "mirror://cpan/authors/id/G/GR/GRANTM/${name}.tar.gz";
+
url = "mirror://cpan/authors/id/G/GR/GRANTM/XML-Simple-2.22.tar.gz";
sha256 = "b9450ef22ea9644ae5d6ada086dc4300fa105be050a2030ebd4efd28c198eb49";
};
propagatedBuildInputs = [ XMLNamespaceSupport XMLSAX XMLSAXExpat ];
+6 -16
pkgs/development/perl-modules/generic/default.nix
···
, ...
}@attrs:
-
assert attrs?pname -> attrs?version;
-
assert attrs?pname -> !(attrs?name);
-
-
lib.warnIf (attrs ? name) "builtPerlPackage: `name' (\"${attrs.name}\") is deprecated, use `pname' and `version' instead"
+
lib.throwIf (attrs ? name) "buildPerlPackage: `name` (\"${attrs.name}\") is deprecated, use `pname` and `version` instead"
(let
defaultMeta = {
-
homepage = "https://metacpan.org/release/${lib.getName attrs}"; # TODO: phase-out `attrs.name`
-
platforms = perl.meta.platforms;
+
homepage = "https://metacpan.org/dist/${attrs.pname}";
+
inherit (perl.meta) platforms;
};
-
cleanedAttrs = builtins.removeAttrs attrs [
-
"meta" "builder" "version" "pname" "fullperl"
-
"buildInputs" "nativeBuildInputs" "buildInputs"
-
"PERL_AUTOINSTALL" "AUTOMATED_TESTING" "PERL_USE_UNSAFE_INC"
-
];
-
-
package = stdenv.mkDerivation ({
-
pname = "perl${perl.version}-${lib.getName attrs}"; # TODO: phase-out `attrs.name`
-
version = lib.getVersion attrs; # TODO: phase-out `attrs.name`
+
package = stdenv.mkDerivation (attrs // {
+
name = "perl${perl.version}-${attrs.pname}-${attrs.version}";
builder = ./builder.sh;
···
inherit PERL_AUTOINSTALL AUTOMATED_TESTING PERL_USE_UNSAFE_INC;
meta = defaultMeta // (attrs.meta or { });
-
} // cleanedAttrs);
+
});
in toPerlModule package)