Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-generate store documentation #8084

Merged
merged 18 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions doc/manual/generate-manpage.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ toplevel }:
cliDumpStr:

with builtins;
with import ./utils.nix;
Expand Down Expand Up @@ -63,7 +63,10 @@ let
* [`${command} ${name}`](./${appendName filename name}.md) - ${subcmd.description}
'';

maybeDocumentation = if details ? doc then details.doc else "";
maybeDocumentation =
if details ? doc
then replaceStrings ["@stores@"] [storeDocs] details.doc
else "";

maybeOptions = if details.flags == {} then "" else ''
# Options
Expand Down Expand Up @@ -110,18 +113,32 @@ let
};
in [ cmd ] ++ concatMap subcommand (attrNames details.commands or {});

parsedToplevel = builtins.fromJSON toplevel;
cliDump = builtins.fromJSON cliDumpStr;

manpages = processCommand {
command = "nix";
details = parsedToplevel;
details = cliDump.args;
filename = "nix";
toplevel = parsedToplevel;
toplevel = cliDump.args;
};

tableOfContents = let
showEntry = page:
" - [${page.command}](command-ref/new-cli/${page.name})";
in concatStringsSep "\n" (map showEntry manpages) + "\n";

storeDocs =
let
showStore = name: { settings, doc }:
''
## ${name}

${doc}

**Settings**:

${showSettings false settings}
'';
in concatStrings (attrValues (mapAttrs showStore cliDump.stores));

in (listToAttrs manpages) // { "SUMMARY.md" = tableOfContents; }
41 changes: 0 additions & 41 deletions doc/manual/generate-options.nix

This file was deleted.

10 changes: 5 additions & 5 deletions doc/manual/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ $(d)/src/SUMMARY.md: $(d)/src/SUMMARY.md.in $(d)/src/command-ref/new-cli
@$(call process-includes,$@,$@)

$(d)/src/command-ref/new-cli: $(d)/nix.json $(d)/generate-manpage.nix $(bindir)/nix
@rm -rf $@
$(trace-gen) $(nix-eval) --write-to $@.tmp --expr 'import doc/manual/generate-manpage.nix { toplevel = builtins.readFile $<; }'
@rm -rf $@ $@.tmp
$(trace-gen) $(nix-eval) --write-to $@.tmp --expr 'import doc/manual/generate-manpage.nix (builtins.readFile $<)'
@mv $@.tmp $@

$(d)/src/command-ref/conf-file.md: $(d)/conf-file.json $(d)/generate-options.nix $(d)/src/command-ref/conf-file-prefix.md $(bindir)/nix
$(d)/src/command-ref/conf-file.md: $(d)/conf-file.json $(d)/utils.nix $(d)/src/command-ref/conf-file-prefix.md $(bindir)/nix
@cat doc/manual/src/command-ref/conf-file-prefix.md > $@.tmp
$(trace-gen) $(nix-eval) --expr 'import doc/manual/generate-options.nix (builtins.fromJSON (builtins.readFile $<))' >> $@.tmp;
$(trace-gen) $(nix-eval) --expr '(import doc/manual/utils.nix).showSettings true (builtins.fromJSON (builtins.readFile $<))' >> $@.tmp;
@mv $@.tmp $@

$(d)/nix.json: $(bindir)/nix
$(trace-gen) $(dummy-env) $(bindir)/nix __dump-args > $@.tmp
$(trace-gen) $(dummy-env) $(bindir)/nix __dump-cli > $@.tmp
@mv $@.tmp $@

$(d)/conf-file.json: $(bindir)/nix
Expand Down
4 changes: 3 additions & 1 deletion doc/manual/src/release-notes/rl-next.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@
```shell-session
$ nix path-info /nix/store/gzaflydcr6sb3567hap9q6srzx8ggdgg-glibc-2.33-78.drv^*
```
provides information about each of its outputs.
provides information about each of its outputs.

* The command `nix describe-stores` has been removed.
edolstra marked this conversation as resolved.
Show resolved Hide resolved
42 changes: 42 additions & 0 deletions doc/manual/utils.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,46 @@ rec {

filterAttrs = pred: set:
listToAttrs (concatMap (name: let v = set.${name}; in if pred name v then [(nameValuePair name v)] else []) (attrNames set));

showSetting = useSpans: name: { description, documentDefault, defaultValue, aliases, ... }:
let
result = squash ''
- ${if useSpans
then ''<span id="conf-${name}">[`${name}`](#conf-${name})</span>''
edolstra marked this conversation as resolved.
Show resolved Hide resolved
else ''[`${name}`](#conf-${name})''}

${indent " " body}
'';

# separate body to cleanly handle indentation
body = ''
${description}

**Default:** ${showDefault documentDefault defaultValue}

${showAliases aliases}
'';

showDefault = documentDefault: defaultValue:
if documentDefault then
# a StringMap value type is specified as a string, but
# this shows the value type. The empty stringmap is `null` in
# JSON, but that converts to `{ }` here.
if defaultValue == "" || defaultValue == [] || isAttrs defaultValue
then "*empty*"
else if isBool defaultValue then
if defaultValue then "`true`" else "`false`"
else "`${toString defaultValue}`"
else "*machine-specific*";

showAliases = aliases:
if aliases == [] then "" else
"**Deprecated alias:** ${(concatStringsSep ", " (map (s: "`${s}`") aliases))}";

indent = prefix: s:
concatStringsSep "\n" (map (x: if x == "" then x else "${prefix}${x}") (splitLines s));

in result;

showSettings = useSpans: settingsInfo: concatStrings (attrValues (mapAttrs (showSetting useSpans) settingsInfo));
}
1 change: 1 addition & 0 deletions src/libcmd/command.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class EvalState;
struct Pos;
class Store;

static constexpr Command::Category catHelp = -1;
static constexpr Command::Category catSecondary = 100;
static constexpr Command::Category catUtility = 101;
static constexpr Command::Category catNixInstallation = 102;
Expand Down
7 changes: 7 additions & 0 deletions src/libstore/dummy-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ struct DummyStoreConfig : virtual StoreConfig {
using StoreConfig::StoreConfig;

const std::string name() override { return "Dummy Store"; }

std::string doc() override
{
return
#include "dummy-store.md"
;
}
};

struct DummyStore : public virtual DummyStoreConfig, public virtual Store
Expand Down
13 changes: 13 additions & 0 deletions src/libstore/dummy-store.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
R"(

**Store URL format**: `dummy://`

This store type represents a store that contains no store paths and
cannot be written to. It's useful when you want to use the Nix
evaluator when no actual Nix store exists, e.g.

```console
# nix eval --store dummy:// --expr '1 + 2'
```

)"
5 changes: 4 additions & 1 deletion src/libstore/globals.hh
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ public:
Path nixDaemonSocketFile;

Setting<std::string> storeUri{this, getEnv("NIX_REMOTE").value_or("auto"), "store",
"The default Nix store to use."};
R"(
The URL of the Nix store to use. See [`nix help-stores`](@docroot@/command-ref/new-cli/nix3-help-stores.md)
for supported store types and settings.
)"};

Setting<bool> keepFailed{this, false, "keep-failed",
"Whether to keep temporary directories of failed builds."};
Expand Down
9 changes: 8 additions & 1 deletion src/libstore/http-binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ struct HttpBinaryCacheStoreConfig : virtual BinaryCacheStoreConfig
{
using BinaryCacheStoreConfig::BinaryCacheStoreConfig;

const std::string name() override { return "Http Binary Cache Store"; }
const std::string name() override { return "HTTP Binary Cache Store"; }

std::string doc() override
{
return
#include "http-binary-cache-store.md"
;
}
};

class HttpBinaryCacheStore : public virtual HttpBinaryCacheStoreConfig, public virtual BinaryCacheStore
Expand Down
8 changes: 8 additions & 0 deletions src/libstore/http-binary-cache-store.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
R"(

**Store URL format**: `http://...`, `https://...`

This store allows a binary cache to be accessed via the HTTP
protocol.

)"
9 changes: 8 additions & 1 deletion src/libstore/legacy-ssh-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ struct LegacySSHStoreConfig : virtual StoreConfig
const Setting<Path> remoteProgram{(StoreConfig*) this, "nix-store", "remote-program", "path to the nix-store executable on the remote system"};
const Setting<std::string> remoteStore{(StoreConfig*) this, "", "remote-store", "URI of the store on the remote system"};

const std::string name() override { return "Legacy SSH Store"; }
const std::string name() override { return "SSH Store"; }

std::string doc() override
{
return
#include "legacy-ssh-store.md"
;
}
};

struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Store
Expand Down
8 changes: 8 additions & 0 deletions src/libstore/legacy-ssh-store.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
R"(

**Store URL format**: `ssh://[username@]hostname`
edolstra marked this conversation as resolved.
Show resolved Hide resolved

This store type allows limited access to a remote store on another
machine via SSH.

)"
7 changes: 7 additions & 0 deletions src/libstore/local-binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ struct LocalBinaryCacheStoreConfig : virtual BinaryCacheStoreConfig
using BinaryCacheStoreConfig::BinaryCacheStoreConfig;

const std::string name() override { return "Local Binary Cache Store"; }

std::string doc() override
{
return
#include "local-binary-cache-store.md"
;
}
};

class LocalBinaryCacheStore : public virtual LocalBinaryCacheStoreConfig, public virtual BinaryCacheStore
Expand Down
16 changes: 16 additions & 0 deletions src/libstore/local-binary-cache-store.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
R"(

**Store URL format**: `file://`*path*

This store allows reading and writing a binary cache stored in *path*
in the local filesystem. If *path* does not exist, it will be created.

For example, the following builds or downloads `nixpkgs#hello` into
the local store and then copies it to the binary cache in
`/tmp/binary-cache`:

```
# nix copy --to file:///tmp/binary-cache nixpkgs#hello
```

)"
7 changes: 7 additions & 0 deletions src/libstore/local-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@

namespace nix {

std::string LocalStoreConfig::doc()
{
return
#include "local-store.md"
;
}

struct LocalStore::State::Stmts {
/* Some precompiled SQLite statements. */
SQLiteStmt RegisterValidPath;
Expand Down
3 changes: 2 additions & 1 deletion src/libstore/local-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ struct LocalStoreConfig : virtual LocalFSStoreConfig
"require-sigs", "whether store paths should have a trusted signature on import"};

const std::string name() override { return "Local Store"; }
};

std::string doc() override;
};

class LocalStore : public virtual LocalStoreConfig, public virtual LocalFSStore, public virtual GcStore
{
Expand Down
40 changes: 40 additions & 0 deletions src/libstore/local-store.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
R"(

**Store URL format**: `local`, *root*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to read multiple examples to understand that this notation means an enumeration of store formats. There probably is a better way to express this in a way that is immediately clear, but I don't see one yet.


This store type accesses a Nix store in the local filesystem directly
(i.e. not via the Nix daemon). *root* is an absolute path that denotes
the "root" of the filesystem; other directories such as the Nix store
edolstra marked this conversation as resolved.
Show resolved Hide resolved
directory (as denoted by the `store` setting) are interpreted relative
edolstra marked this conversation as resolved.
Show resolved Hide resolved
to *root*. The store pseudo-URL `local` denotes a store that uses `/`
as its root directory.

A store that uses a *root* other than `/` is called a *chroot
store*. With such stores, the store directory is "logically" still
`/nix/store`, so programs stored in them can only be built and
executed by `chroot`-ing into *root*. Chroot stores only support
building and running on Linux when mount and user namespaces are
edolstra marked this conversation as resolved.
Show resolved Hide resolved
enabled.

For example, the following uses `/tmp/root` as the chroot environment
to build or download `nixpkgs#hello` and then execute it:

```console
# nix run --store /tmp/root nixpkgs#hello
Hello, world!
```
Comment on lines +18 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make a definitive decision on whether and how to document experimental features in the stable parts of the manual. Similar situation in the hacking guide.

While this, for now, will only show in nix command docs, there is no reason not to have it everywhere it matters, since that stuff is already stable.


Here, the "physical" store location is `/tmp/root/nix/store`, and
Nix's store metadata is in `/tmp/root/nix/var/nix/db`.

It is also possible, but not recommended, to change the "logical"
location of the Nix store from its default of `/nix/store`. This makes
it impossible to use default substituters such as
`https://cache.nixos.org/`, and thus you may have to build everything
locally. Here is an example:

```console
# nix build --store 'local?store=/tmp/my-nix/store&state=/tmp/my-nix/state&log=/tmp/my-nix/log' nixpkgs#hello
```

)"
7 changes: 7 additions & 0 deletions src/libstore/s3-binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ struct S3BinaryCacheStoreConfig : virtual BinaryCacheStoreConfig
(StoreConfig*) this, 5 * 1024 * 1024, "buffer-size", "size (in bytes) of each part in multi-part uploads"};

const std::string name() override { return "S3 Binary Cache Store"; }

std::string doc() override
{
return
#include "s3-binary-cache-store.md"
;
}
};

struct S3BinaryCacheStoreImpl : virtual S3BinaryCacheStoreConfig, public virtual S3BinaryCacheStore
Expand Down
8 changes: 8 additions & 0 deletions src/libstore/s3-binary-cache-store.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
R"(

**Store URL format**: `s3://`*bucket-name*

This store allows reading and writing a binary cache stored in an AWS
S3 bucket.

)"
Loading