-
-
Save dasJ/3140d8e8bdf94990f26b7614925d8c3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ config, lib, pkgs, ... }: with lib; let | |
cfg = config.helsinki.doc; | |
mkManual = manual: modList: pkgs: manual rec { | |
inherit pkgs config; | |
version = config.system.nixos.release; | |
revision = "release-${version}"; | |
options = let | |
scrubbedEval = evalModules { | |
modules = [ { nixpkgs.localSystem = config.nixpkgs.localSystem; } ] ++ (import <helsinki/3modules>) ++ modList; | |
args = (config._module.args) // { modules = [ ]; }; | |
specialArgs = { pkgs = scrubDerivations "pkgs" pkgs; }; | |
}; | |
scrubDerivations = namePrefix: pkgSet: mapAttrs | |
(name: value: | |
let wholeName = "${namePrefix}.${name}"; in | |
if isAttrs value then | |
scrubDerivations wholeName value | |
// (optionalAttrs (isDerivation value) { outPath = "\${${wholeName}}"; }) | |
else value | |
) | |
pkgSet; | |
in scrubbedEval.options; | |
}; | |
manual = mkManual (import <nixpkgs/nixos/doc/manual>) (import <nixpkgs/nixos/modules/module-list.nix>) (import <nixpkgs> {}); | |
unstableManual = mkManual (import <nixos-unstable/nixos/doc/manual>) (import <nixos-unstable/nixos/modules/module-list.nix>) (import <nixos-unstable> {}); | |
loadNixpkgs = version: let | |
src = builtins.fetchTarball "https://nixos.org/channels/nixos-${version}/nixexprs.tar.xz"; | |
in import src {}; | |
mkPkgList = filename: release: pkgs.runCommand filename { | |
buildInputs = with pkgs; [ nix ]; | |
NIX_STORE_DIR = "/tmp/nix/store"; | |
NIX_LOCALESTATE_DIR = "/tmp/nix/var"; | |
NIX_LOG_DIR = "/tmp/nix/var/log/nix"; | |
NIX_STATE_DIR = "/tmp/nix/var"; | |
NIX_CONF_DIR = "/tmp/nix/etc"; | |
NIXPKGS_ALLOW_UNFREE = "1"; | |
} '' | |
( | |
echo -n '{ "commit": "' | |
cat ${(loadNixpkgs release).path}/.git-revision | |
echo -n '","packages":' | |
nix-env --readonly-mode -f '<nixpkgs>' -I nixpkgs=${(loadNixpkgs release).path} -I nixpkgs-overlays=${<helsinki/4pkgs>}/default.nix -qa --json | ${pkgs.jq}/bin/jq -c . | |
echo -n '}' | |
) > $out | |
''; | |
pkgList = mkPkgList "package-list-stable.json" config.helsinki.config.release; | |
pkgListUnstable = mkPkgList "package-list-unstable.json" "unstable"; | |
entry = "${manual.manual}/share/doc/nixos/index.html"; | |
helpScript = pkgs.writeScriptBin "nixos-help" | |
'' | |
#!${pkgs.stdenv.shell} -e | |
browser="$BROWSER" | |
if [ -z "$browser" ]; then | |
browser="$(type -P xdg-open || true)" | |
if [ -z "$browser" ]; then | |
browser="$(type -P w3m || true)" | |
if [ -z "$browser" ]; then | |
echo "$0: unable to start a web browser; please set \$BROWSER" | |
exit 1 | |
fi | |
fi | |
fi | |
exec "$browser" ${entry} | |
''; | |
desktopItem = pkgs.makeDesktopItem { | |
name = "nixos-manual"; | |
desktopName = "NixOS Manual"; | |
genericName = "View NixOS documentation in a web browser"; | |
icon = "nix-snowflake"; | |
exec = "${helpScript}/bin/nixos-help"; | |
categories = "System"; | |
}; | |
in { | |
options.helsinki.doc = with types; { | |
virtualHost = mkOption { | |
type = nullOr str; | |
default = null; | |
description = "Name of the nginx virtual host serving the generated HTML files"; | |
}; | |
}; | |
config = { | |
services.nixosManual.enable = false; | |
system.build.manual = manual; | |
environment.systemPackages = | |
[ manual.manual helpScript ] | |
++ optionals config.services.xserver.enable [ desktopItem pkgs.nixos-icons ] | |
++ optional config.documentation.man.enable (manual.manpages.overrideAttrs (old: { name = "helsinki-manpages"; })) | |
++ optionals config.documentation.doc.enable [ (manual.manpages.overrideAttrs (old: { name = "helsinki-manpages"; })) helpScript ]; | |
services.nginx.virtualHosts = mkIf (cfg.virtualHost != null) { | |
"${cfg.virtualHost}" = { | |
root = pkgs.nixos-homepage; | |
locations."/" = { | |
index = "options-stable.html"; | |
extraConfig = '' | |
rewrite ^/$ /options-stable.html redirect; | |
''; | |
}; | |
locations."/options-stable.json".extraConfig = '' | |
alias ${manual.optionsJSON}/share/doc/nixos/options.json; | |
''; | |
locations."/options-unstable.json".extraConfig = '' | |
alias ${unstableManual.optionsJSON}/share/doc/nixos/options.json; | |
''; | |
locations."/packages-stable.json".extraConfig = '' | |
alias ${pkgList}; | |
''; | |
locations."/packages-unstable.json".extraConfig = '' | |
alias ${pkgListUnstable}; | |
''; | |
}; | |
}; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- a/layout.tt 2018-08-30 16:21:55.449575405 +0200 | |
+++ b/layout.tt 2018-08-30 16:21:55.449575405 +0200 | |
@@ -51,6 +51,8 @@ | |
Disnix | |
[% ELSIF menu == 'hydra' %] | |
Hydra | |
+ [% ELSIF menu == 'helsinki' %] | |
+ Helsinki | |
[% ELSE %] | |
NixOS | |
[% END %] | |
@@ -83,6 +85,15 @@ | |
<li><a href="https://github.com/NixOS/nixpkgs"><i class="fa fa-github"></i></a></li> | |
<li><a href="https://twitter.com/nixos_org"><i class="fa fa-twitter"></i></a></li> | |
--> | |
+ [% ELSIF menu == 'helsinki' %] | |
+ <ul class="nav pull-left"> | |
+ <li><a href="[%root%]/options-stable.html">Stable Options</a></li> | |
+ <li><a href="[%root%]/options-unstable.html">Unstable Options</a></li> | |
+ <li><a href="[%root%]/packages-stable.html">Stable Packages</a></li> | |
+ <li><a href="[%root%]/packages-unstable.html">Unstable Packages</a></li> | |
+ </ul> | |
+ <ul class="nav pull-right"> | |
+ <li><a href="https://github.com/NixOS/nixpkgs"><i class="fa fa-github"></i></a></li> | |
[% ELSIF menu == 'nix' %] | |
<ul class="nav pull-left"> | |
<li><a href="[%root%]nix/about.html">About</a></li> | |
@@ -128,10 +137,6 @@ | |
<ul class="nav pull-right"> | |
[% END %] | |
- <form class="navbar-search" method="get" action="https://www.google.com/search"> | |
- <input name="q" type="text" class="search-query span2" placeholder="Search nixos.org"/> | |
- <input name="sitesearch" type="hidden" value="nixos.org"/> | |
- </form> | |
</ul> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs, stdenv, lib, fetchFromGitHub, curl, perlPackages, libxml2, libxslt, imagemagick }: with lib; stdenv.mkDerivation { | |
name = "nixos-homepage"; | |
version = "0"; | |
src = fetchFromGitHub { | |
owner = "NixOS"; | |
repo = "nixos-homepage"; | |
rev = "e35b6a6f23e2433bde87799dbc215c65e4044a1a"; | |
sha256 = "11wyllcakib0xws5qpl883y6wzi475wa9wsad26jlb8fpjwv7x7k"; | |
}; | |
prePatch = '' | |
sed -i \ | |
-e 's/git log -1 --pretty='%ai' $<//g' \ | |
-e 's/git log -1 --pretty='%an' $<//g' \ | |
-e 's/--define root=.*$/--define root="" \\/g' \ | |
Makefile | |
sed -i \ | |
-e "s/menu='nixos'/menu='helsinki'/g" \ | |
-e 's/url:.*$/url: "options-@@CHANNEL@@.json",/g' \ | |
nixos/options.tt | |
sed -i \ | |
-e 's/menu="nixos"/menu="helsinki"/g' \ | |
-e 's/url:.*$/url: "packages-@@CHANNEL@@.json",/g' \ | |
nixos/packages.tt | |
''; | |
patches = [ ./layout.tt.patch ]; | |
noBuild = true; | |
buildInputs = with perlPackages; [ curl libxml2 libxslt imagemagick TemplateToolkit TemplatePluginJSONEscape TemplatePluginIOAll XMLSimple ]; | |
makeFlags = [ "nixos/options.html" "nixos/packages.html" "favicon.png" ]; | |
installPhase = '' | |
mkdir -p $out | |
cp -r \ | |
bootstrap \ | |
css \ | |
images \ | |
js \ | |
$out | |
mkdir -p $out/logo | |
for f in logo/*.png; do | |
convert "$f" -colorspace gray +level-colors ,red "$out/logo/$(basename "$f")" | |
done | |
# TODO Make both convert commands lighter | |
convert favicon.png -colorspace gray +level-colors ,red "$out/favicon.png" | |
convert "$out/favicon.png" -define icon:auto-resize=64,48,32,16 "$out/favicon.ico" | |
sed 's/@@CHANNEL@@/stable/g' nixos/options.html > $out/options-stable.html | |
sed 's/@@CHANNEL@@/stable/g' nixos/packages.html > $out/packages-stable.html | |
sed 's/@@CHANNEL@@/unstable/g' nixos/options.html > $out/options-unstable.html | |
sed 's/@@CHANNEL@@/unstable/g' nixos/packages.html > $out/packages-unstable.html | |
''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment