jail.nix/website/flake.nix

161 lines
5.2 KiB
Nix
Raw Permalink 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
2026-07-08 10:45:14 -07:00
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
2025-06-07 12:45:48 -07:00
2025-09-11 07:31:48 -07:00
outputs =
{ self, nixpkgs, ... }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
lib = pkgs.lib;
2025-06-07 12:45:48 -07:00
2025-09-11 07:31:48 -07:00
repo = rec {
2026-04-02 12:15:32 -07:00
rev = if self ? rev then self.rev else lib.warn "Repo is dirty, links point to main!" "main";
2025-09-11 07:31:48 -07:00
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}";
};
2025-07-11 11:16:47 -07:00
};
2026-01-28 13:06:37 -08:00
docsFileSet =
with lib.fileset;
toSource {
root = ../.;
fileset = ../lib;
};
2025-09-11 07:31:48 -07:00
formatCombinatorDoc =
name: combinatorObj:
let
attrPos = builtins.unsafeGetAttrPos "impl" combinatorObj;
2026-01-28 13:06:37 -08:00
file = lib.removePrefix (toString docsFileSet) attrPos.file;
2025-09-11 07:31:48 -07:00
in
''
### ${name}
2026-04-02 12:15:32 -07:00
<a class="source" href="${repo.urls.file file attrPos.line}">Source</a>
2026-04-02 12:15:32 -07:00
**${name} :: ${combinatorObj.sig}**
${
if combinatorObj ? aliases then
"Aliases: ${lib.concatMapStringsSep ", " (alias: "`${alias}`") combinatorObj.aliases}"
else
""
}
2025-09-11 07:31:48 -07:00
${combinatorObj.doc}
'';
2025-09-11 07:31:48 -07:00
combinatorDocs =
let
allCombinators =
(import (docsFileSet + /lib/combinators.nix) { inherit pkgs; } (
throw "Docs must not depend on jail arg"
)).docs;
2025-07-11 11:16:47 -07:00
2025-09-11 07:31:48 -07:00
formatSection =
filter:
lib.pipe allCombinators [
(lib.filterAttrs (_: filter))
(lib.mapAttrsToList formatCombinatorDoc)
(lib.concatStringsSep "\n\n---\n")
];
hr = ''<hr style="border: 2px solid #272525">'';
is = flag: combinator: combinator ? ${flag} && combinator.${flag};
in
''
# 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`
function, as well as
[`basePermissions`](advanced-configuration.md#basepermissions).
A `Permission` is a `State -> State` function where `State` is an
internal type that is used to eventually build the final bubblewrap
flags. The type of `State` is not part of the public API, and may change
in the future.
${hr}
${formatSection (v: !(is "includedInBasePermissions" v || is "internal" v || is "experimental" v))}
2025-09-11 07:31:48 -07:00
${hr}
## Default Included Combinators
The following combinators are enabled by default, and do not need to be
explicitly added to your jails unless you [override
`basePermissions`](advanced-configuration.md#basepermissions).
${formatSection (is "includedInBasePermissions")}
${hr}
## Experimental Combinators
The following combinators are experimental, and may be removed, or
have breaking changes in the future. Please reach out if you have any
feedback on them.
Using these combinators will emit an evaluation warning, you can
suppress this warning with
[suppressExperimentalWarnings](advanced-configuration.md#suppressexperimentalwarnings).
${formatSection (is "experimental")}
2025-09-11 07:31:48 -07:00
'';
mkdocsSettings = {
site_name = "jail-nix";
repo_url = repo.urls.base;
theme = {
name = "readthedocs";
hljs_languages = [ "nix" ];
};
2026-04-02 12:15:32 -07:00
extra_css = [ "extra.css" ];
2025-09-11 07:31:48 -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
};
2025-09-11 07:31:48 -07:00
in
2025-10-04 09:42:35 -07:00
rec {
apps.x86_64-linux.serve = {
type = "app";
program = lib.getExe (
pkgs.writeShellApplication {
name = "serve";
runtimeInputs = [ pkgs.python3 ];
text = ''
cd ${packages.x86_64-linux.default}
python3 -m http.server
'';
}
);
};
2025-09-11 07:31:48 -07:00
packages.x86_64-linux.default = pkgs.runCommand "website" { buildInputs = [ pkgs.mkdocs ]; } ''
cp -r ${./static-docs} docs
chmod -R +w docs
echo ${lib.escapeShellArg combinatorDocs} > docs/combinators.md
echo ${lib.escapeShellArg (builtins.toJSON mkdocsSettings)} > mkdocs.yml
mkdocs build
mv site $out
'';
2025-06-07 12:45:48 -07:00
};
}