1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-12-12 15:24:14 +03:00
mobile-nixos/doc/default.nix
Samuel Dionne-Riel 0766091589 doc: Don't rely on <nixpkgs> anymore
We're instead re-importing the given Nixkgs with overlays.

Why re-import? It's because `extend` doesn't play well with some
features from Nixpkgs:

```
nix-repl> (pkgs.extend(f: s: { foobarbaz = "hi"; })).foobarbaz
"hi"

nix-repl> (pkgs.extend(f: s: { foobarbaz = "hi"; })).pkgsCross.aarch64-multiplatform.foobarbaz
error: attribute 'foobarbaz' missing, at (string):1:1
```
2021-08-31 14:19:51 -04:00

102 lines
2.4 KiB
Nix

{ pkgs ? import ../pkgs.nix { } }:
if pkgs == null then (builtins.throw "The `pkgs` argument needs to be provided to doc/default.nix") else
let pkgs' = pkgs; in # Break the cycle
let
pkgs = pkgs'.appendOverlays [
(final: super: {
mobile-nixos-process-doc = final.callPackage ./_support/converter {};
})
];
in
let
inherit (pkgs) stdenv mobile-nixos-process-doc rsync;
# Styles, built from a preprocessor.
styles = pkgs.callPackage ./_support/styles { };
# Asciidoc source for the devices section.
devices = pkgs.callPackage ./_support/devices { };
# Asciidoc source for the options section.
options = pkgs.callPackage ./_support/options { };
in
stdenv.mkDerivation {
name = "mobile-nixos-docs";
src = ./.;
buildInputs = [
mobile-nixos-process-doc
rsync
];
buildPhase = ''
export LANG=C.UTF-8
# Removes the internal notes.
rm -f README.md
# Replace it in-place with the repo README.
cat >> README.adoc <<EOF
= README.adoc
include::_support/common.inc[]
EOF
tail -n +4 ${../README.adoc} >> README.adoc
# The title needs to be first
head -n1 ${../CONTRIBUTING.adoc} > contributing.adoc
# Then we're adding our common stuff
cat >> contributing.adoc <<EOF
include::_support/common.inc[]
EOF
# Then continuing with the file.
tail -n +2 ${../CONTRIBUTING.adoc} >> contributing.adoc
if [ ! -e index.adoc ]; then
cat >> index.adoc <<EOF
= Main Page
include::_support/common.inc[]
This is a local build of the Mobile NixOS documentation.
The full site is at https://mobile.nixos.org/.
EOF
fi
# Copies the generated asciidoc source for the devices.
cp -prf ${devices}/devices devices
# Copies the generated asciidoc source for the options.
cp -prf ${options}/options options
# Use our pipeline to process the docs.
process-doc "**/*.adoc" "**/*.md" \
--styles-dir="${styles}" \
--output-dir="$out"
'';
installPhase = ''
rsync --prune-empty-dirs --verbose --archive \
--exclude="*.src.svg" \
--include="*.svg" \
--include="*.jpeg" \
--include="*.png" \
--include="*/" --exclude="*" . $out/
(
cd $out
if grep -RIi "$NIX_BUILD_TOP"; then
echo "error: References to $NIX_BUILD_TOP found in output:"
grep -RIi "$NIX_BUILD_TOP"
exit 1
fi
)
'';
}