jail.nix/website/flake.nix

92 lines
3 KiB
Nix
Raw Normal View History

2025-06-07 12:45:48 -07:00
{
# This is a separate flake file from the one at the root because we don't
# want to depend on nixpkgs
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
outputs = { self, nixpkgs, ... }: let
2025-06-07 12:45:48 -07:00
pkgs = import nixpkgs { system = "x86_64-linux"; };
lib = pkgs.lib;
2025-07-11 11:16:47 -07:00
repo = rec {
rev = if self ? rev then self.rev else lib.warn "Repo is dirty, links will not work!" "???";
shortRev = lib.substring 0 8 rev;
urls = {
base = "https://git.sr.ht/~alexdavid/jail.nix";
commit = "https://git.sr.ht/~alexdavid/jail.nix/commit/${rev}";
file = file: lineNr: "https://git.sr.ht/~alexdavid/jail.nix/tree/${rev}${file}#L${toString lineNr}";
};
};
formatCombinatorDoc = name: combinatorObj: let
attrPos = builtins.unsafeGetAttrPos "__functor" combinatorObj;
file = lib.removePrefix (toString ./..) attrPos.file;
in ''
## ${name}
**${name} :: ${combinatorObj.sig}**
2025-07-11 11:16:47 -07:00
[Source](${repo.urls.file file attrPos.line})
${combinatorObj.doc}
---
'';
2025-06-07 12:45:48 -07:00
combinatorDocs = lib.pipe
{
pkgs = throw "Docs must not depend on pkgs";
lib = throw "Docs must not depend on lib";
helpers = throw "Docs must not depend on helpers";
}
[
2025-08-07 15:52:43 -07:00
(import ../lib/combinators.nix)
2025-06-07 12:45:48 -07:00
(lib.filterAttrs (_: v: !(v ? deprecated && v.deprecated)))
(lib.mapAttrsToList formatCombinatorDoc)
2025-06-07 12:45:48 -07:00
(lib.concatStringsSep "\n\n")
2025-07-11 11:16:47 -07:00
(docs: ''
# Combinators
jail.nix combinators are the building blocks to create `Permission`s,
which grant a program specific permissions at runtime.
These permissions can be passed into the third argument to `jail`
funciton, as well as
[`basePermissions`](../advanced-configuration/#basepermissions).
---
2025-07-11 11:16:47 -07:00
${docs}
'')
2025-06-07 12:45:48 -07:00
];
mkdocsSettings = {
site_name = "jail-nix";
2025-07-11 11:16:47 -07:00
repo_url = repo.urls.base;
2025-06-07 12:45:48 -07:00
theme = {
name = "readthedocs";
hljs_languages = [ "nix" ];
};
2025-07-11 11:16:47 -07:00
# Copyright is placed directly into the page within a <p> tag.
# Concatenating with </p><p> here is super janky, but good enough for
# now.
copyright = lib.concatStringsSep "</p><p>" [
''
Copyright © 2025 Alex David ///
<a rel="license" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a>.
''
''
This documentation was generated from the <a href="${repo.urls.base}">jail.nix repo</a>,
commit <a href="${repo.urls.commit}"><code>${repo.shortRev}</code></a>.
''
];
2025-06-07 12:45:48 -07:00
};
in {
packages.x86_64-linux.default = pkgs.runCommand "website" { buildInputs = [ pkgs.mkdocs ]; } ''
2025-07-11 11:16:47 -07:00
cp -r ${./static-docs} docs
chmod -R +w docs
2025-06-07 12:45:48 -07:00
echo ${lib.escapeShellArg combinatorDocs} > docs/combinators.md
echo ${lib.escapeShellArg (builtins.toJSON mkdocsSettings)} > mkdocs.yml
mkdocs build
mv site $out
'';
};
}