Skip to content

Commit

Permalink
docbook: refactor rng and XML dtd versions
Browse files Browse the repository at this point in the history
  • Loading branch information
rc-zb committed Oct 28, 2024
1 parent ab8a67c commit cc78c62
Show file tree
Hide file tree
Showing 12 changed files with 233 additions and 129 deletions.
61 changes: 61 additions & 0 deletions pkgs/by-name/do/docbook/generic-xml-dtd.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
version,
url ? null,
hash,
preInstall ? "",
}:

{
lib,
stdenvNoCC,
fetchurl,
unzip,
libxml2,
}:

stdenvNoCC.mkDerivation (finalAttrs: {
pname = "docbook";
inherit version;

src = fetchurl {
url = if isNull url then "https://docbook.org/xml/${version}/docbook-xml-${version}.zip" else url;
inherit hash;
};

nativeBuildInputs = [
unzip
libxml2
];

sourceRoot = ".";

inherit preInstall;

installPhase = ''
runHook preInstall
dst=$out/xml/dtd/docbook
mkdir -p $dst
cp -prv * $dst/
substituteInPlace $dst/catalog.xml --replace 'uri="' "uri=\"$dst/"
runHook postInstall
'';

meta = {
description = "General purpose XML and SGML document type";
longDescription = ''
DocBook is general purpose XML and SGML document type particularly well
suited to books and papers about computer hardware and software (though it
is by no means limited to these applications).
The OASIS DocBook Technical Committee maintains the DocBook schema.
DocBook is officially available as a Document Type Definition (DTD) for
both XML and SGML. It is unofficially available in other forms as well.
'';
homepage = "https://docbook.org/";
license = "DocBook-Schema";
maintainers = with lib.maintainers; [ rc-zb ];
platforms = lib.platforms.all;
};
})
50 changes: 50 additions & 0 deletions pkgs/by-name/do/docbook/generic-xml-rng.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
version,
url ? null,
hash,
installPhase,
}:

{
lib,
stdenvNoCC,
fetchurl,
unzip,
}:

stdenvNoCC.mkDerivation (finalAttrs: {
pname = "docbook";
inherit version;

src = fetchurl {
url =
if isNull url then
"https://docs.oasis-open.org/docbook/docbook/v${version}/os/docbook-v${version}-os.zip"
else
url;
inherit hash;
};

nativeBuildInputs = [ unzip ];

sourceRoot = ".";

inherit installPhase;

meta = {
description = "General purpose XML schema";
longDescription = ''
DocBook is general purpose XML schema particularly well suited to books and
papers about computer hardware and software (though it is by no means
limited to these applications).
The OASIS DocBook Technical Committee maintains the DocBook schema.
Starting with V5.0, DocBook is normatively available as a RELAX NG Schema
(with some additional Schematron assertions).
'';
homepage = "https://docbook.org/";
license = "DocBook-Schema";
maintainers = with lib.maintainers; [ rc-zb ];
platforms = lib.platforms.all;
};
})
6 changes: 6 additions & 0 deletions pkgs/by-name/do/docbook/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
callPackage,
releaseVersion ? "5.2",
}:

(callPackage ./versions.nix { }).${releaseVersion}
94 changes: 94 additions & 0 deletions pkgs/by-name/do/docbook/versions.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
callPackage,
fetchurl,
libxml2,
}:
let
makeDocBookVersions =
era: builtins.mapAttrs (name: spec: callPackage (import (./. + "/generic-${era}.nix") spec) { });
in
(makeDocBookVersions "xml-rng" {
"5.2" = {
version = "5.2";
hash = "sha256-grMb+6HEo18TiZWr1Ofko9yf4XIX3vlSeXm/QsFpiWI=";
installPhase = ''
runHook preInstall
dst=$out/share/xml/docbook-5.2
mkdir -p $dst
cp -prv * $dst/
substituteInPlace $dst/catalog.xml --replace 'uri="' "uri=\"$dst/"
rm -rf $dst/*.{docx,html,pdf} $dst/release-notes
runHook postInstall
'';
};
"5.1" = {
version = "5.1";
hash = "sha256-s/NBNlQAPB53M2DX/GDruKvQ6Mmvjn1sS1XxJPNNHn8=";
installPhase = ''
runHook preInstall
dst=$out/share/xml/docbook-5.1
mkdir -p $dst
cp -prv schemas/* $dst/
substituteInPlace $dst/catalog.xml --replace 'uri="' "uri=\"$dst/"
runHook postInstall
'';
};
"5.0" = rec {
version = "5.0.1";
url = "https://docbook.org/xml/${version}/docbook-${version}.zip";
hash = "sha256-evnfRSQQ4DWjcHiD5DA5tAYvCdwvSfLphto+TAOG48c=";
installPhase = ''
runHook preInstall
dst=$out/share/xml/docbook-5.0
mkdir -p $dst
# The dir must be specified manually, because sourceRoot is set to ".".
cp -prv docbook-${version}/* $dst/
substituteInPlace $dst/catalog.xml --replace 'uri="' "uri=\"$dst/"
rm -rf $dst/docs $dst/ChangeLog
# Backwards compatibility. Will remove eventually.
mkdir -p $out/xml/rng $out/xml/dtd
ln -s $dst/rng $out/xml/rng/docbook
ln -s $dst/dtd $out/xml/dtd/docbook
runHook postInstall
'';
};
})
// (makeDocBookVersions "xml-dtd" {
"4.5" = {
version = "4.5";
hash = "sha256-Tk4DeiuDyYxslIGDkNS90/bhD27GLdeRiFlOJhkNx7Q=";
};
"4.4" = {
version = "4.4";
hash = "sha256-AvFZ64jEJU2V6DHFHBRLGGOyFtkJtf9FdDoc5vUnMJA=";
};
"4.3" = {
version = "4.3";
hash = "sha256-IwaKlOpv1ISwBMWnPsNqZqpH6o8Na2LMFpWTH1wUNGQ=";
};
"4.2" = {
version = "4.2";
hash = "sha256-rMRgHk+XoZYHa35ks2jZJIsHx6vyazSgLMpA7uvmD6I=";
};
"4.1.2" = {
version = "4.1.2";
url = "https://docbook.org/xml/4.1.2/docbkx412.zip";
hash = "sha256-MPBkQGTg6nF1FDglGUCxQx9GrK2oFKBihw9IbHcud3I=";
preInstall =
let
docbook42catalog = fetchurl {
url = "https://docbook.org/xml/4.2/catalog.xml";
sha256 = "sha256-J0g0JhEzZpuYlm0qU+lKmLc1oUbD5FKQHuUAKrC5kKI=";
};
in
''
sed 's|V4.2|V4.1.2|g' < ${docbook42catalog} > catalog.xml
'';
};
})
36 changes: 0 additions & 36 deletions pkgs/data/sgml+xml/schemas/docbook-5.0/default.nix

This file was deleted.

22 changes: 0 additions & 22 deletions pkgs/data/sgml+xml/schemas/xml-dtd/docbook/4.1.2.nix

This file was deleted.

10 changes: 0 additions & 10 deletions pkgs/data/sgml+xml/schemas/xml-dtd/docbook/4.2.nix

This file was deleted.

10 changes: 0 additions & 10 deletions pkgs/data/sgml+xml/schemas/xml-dtd/docbook/4.3.nix

This file was deleted.

10 changes: 0 additions & 10 deletions pkgs/data/sgml+xml/schemas/xml-dtd/docbook/4.4.nix

This file was deleted.

10 changes: 0 additions & 10 deletions pkgs/data/sgml+xml/schemas/xml-dtd/docbook/4.5.nix

This file was deleted.

25 changes: 0 additions & 25 deletions pkgs/data/sgml+xml/schemas/xml-dtd/docbook/generic.nix

This file was deleted.

28 changes: 22 additions & 6 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26824,21 +26824,37 @@ with pkgs;
dm-sans = callPackage ../data/fonts/dm-sans { };
dns-root-data = callPackage ../data/misc/dns-root-data { };

docbook5 = callPackage ../data/sgml+xml/schemas/docbook-5.0 { };
# TODO: refactor DocBook versions into ../by-name/do/docbook/
inherit
(lib.attrsets.mapAttrs'
(relVer: deriv: lib.attrsets.nameValuePair
("docbook_" + lib.strings.concatStringsSep "_" (lib.strings.splitString "." relVer))
deriv)
(callPackage ../by-name/do/docbook/versions.nix {}))
docbook_5_2
docbook_5_1
docbook_5_0
docbook_4_5
docbook_4_4
docbook_4_3
docbook_4_2
docbook_4_1_2;

docbook5 = docbook_5_0;

docbook_sgml_dtd_31 = callPackage ../data/sgml+xml/schemas/sgml-dtd/docbook/3.1.nix { };

docbook_sgml_dtd_41 = callPackage ../data/sgml+xml/schemas/sgml-dtd/docbook/4.1.nix { };

docbook_xml_dtd_412 = callPackage ../data/sgml+xml/schemas/xml-dtd/docbook/4.1.2.nix { };
docbook_xml_dtd_412 = docbook_4_1_2;

docbook_xml_dtd_42 = callPackage ../data/sgml+xml/schemas/xml-dtd/docbook/4.2.nix { };
docbook_xml_dtd_42 = docbook_4_2;

docbook_xml_dtd_43 = callPackage ../data/sgml+xml/schemas/xml-dtd/docbook/4.3.nix { };
docbook_xml_dtd_43 = docbook_4_3;

docbook_xml_dtd_44 = callPackage ../data/sgml+xml/schemas/xml-dtd/docbook/4.4.nix { };
docbook_xml_dtd_44 = docbook_4_4;

docbook_xml_dtd_45 = callPackage ../data/sgml+xml/schemas/xml-dtd/docbook/4.5.nix { };
docbook_xml_dtd_45 = docbook_4_5;

docbook_xml_ebnf_dtd = callPackage ../data/sgml+xml/schemas/xml-dtd/docbook-ebnf { };

Expand Down

0 comments on commit cc78c62

Please sign in to comment.