Skip to content

Commit

Permalink
Fix misc errors, stop needing a Nix change
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericson2314 committed Oct 8, 2024
1 parent 757975d commit 4a52b29
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 18 deletions.
2 changes: 1 addition & 1 deletion doc/manual/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ nix_eval_for_docs_common = nix_for_docs + [
nix_eval_for_docs = nix_eval_for_docs_common + '--raw'

conf_file_json = custom_target(
command : nix_for_docs + ['show', 'config', '--json'],
command : nix_for_docs + ['config', 'show', '--json'],
capture : true,
output : 'conf-file.json',
env : nix_env_for_docs,
Expand Down
33 changes: 33 additions & 0 deletions doc/manual/remove_before_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3

import os
import subprocess
import sys
import shutil
import typing as t

def main():
if len(sys.argv) < 4 or '--' not in sys.argv:
print("Usage: remove-before-wrapper <output> -- <nix command...>")
sys.exit(1)

# Extract the parts
output: str = sys.argv[1]
nix_command_idx: int = sys.argv.index('--') + 1
nix_command: t.List[str] = sys.argv[nix_command_idx:]

output_temp: str = output + '.tmp'

# Remove the output and temp output in case they exist
shutil.rmtree(output, ignore_errors=True)
shutil.rmtree(output_temp, ignore_errors=True)

# Execute nix command with `--write-to` tempary output
nix_command_write_to = nix_command + ['--write-to', output_temp]
subprocess.run(nix_command_write_to, check=True)

# Move the temporary output to the intended location
os.rename(output_temp, output)

if __name__ == "__main__":
main()
11 changes: 8 additions & 3 deletions doc/manual/src/command-ref/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ experimental_features_shortlist_md = custom_target(
)

nix3_cli_files = custom_target(
command : nix_eval_for_docs_common + [
'--write-to', '@OUTPUT@',
command : [
python.full_path(),
'@INPUT0@',
'@OUTPUT@',
'--'
] + nix_eval_for_docs + [
'--expr',
'import @INPUT0@ true (builtins.readFile ./@INPUT1@)',
'import @INPUT1@ true (builtins.readFile ./@INPUT2@)',
],
input : [
'../../remove_before_wrapper.py',
'../../generate-manpage.nix',
nix3_cli_json,
],
Expand Down
11 changes: 8 additions & 3 deletions doc/manual/src/language/meson.build
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
builtins_md = custom_target(
command : nix_eval_for_docs + [
'--write-to', '@OUTPUT@',
command : [
python.full_path(),
'@INPUT0@',
'@OUTPUT@',
'--'
] + nix_eval_for_docs + [
'--expr',
'(builtins.readFile @INPUT2@) + import @INPUT0@ (builtins.fromJSON (builtins.readFile ./@INPUT1@)) + (builtins.readFile @INPUT3@)',
'(builtins.readFile @INPUT3@) + import @INPUT1@ (builtins.fromJSON (builtins.readFile ./@INPUT2@)) + (builtins.readFile @INPUT4@)',
],
input : [
'../../remove_before_wrapper.py',
'../../generate-builtins.nix',
language_json,
'builtins-prefix.md',
Expand Down
11 changes: 8 additions & 3 deletions doc/manual/src/store/meson.build
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
types_dir = custom_target(
command : nix_eval_for_docs + [
'--write-to', '@OUTPUT@',
command : [
python.full_path(),
'@INPUT0@',
'@OUTPUT@',
'--'
] + nix_eval_for_docs + [
'--expr',
'import @INPUT0@ (builtins.fromJSON (builtins.readFile ./@INPUT1@)).stores',
'import @INPUT1@ (builtins.fromJSON (builtins.readFile ./@INPUT2@)).stores',
],
input : [
'../../remove_before_wrapper.py',
'../../generate-store-types.nix',
nix3_cli_json,
],
Expand Down
5 changes: 3 additions & 2 deletions doc/manual/substitute.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import json
import os, os.path
import sys
import typing as t

name = 'substitute.py'

def log(*args: Any, **kwargs: Any) -> None:
def log(*args: t.Any, **kwargs: t.Any) -> None:
kwargs['file'] = sys.stderr
print(f'{name}:', *args, **kwargs)

Expand All @@ -34,7 +35,7 @@ def do_include(content: str, relative_md_path: Path, source_root: Path, search_p
lines.append(l)
return "".join(lines)

def recursive_replace(data: dict[str, Any], book_root: Path, search_path: Path) -> dict[str, Any]:
def recursive_replace(data: dict[str, t.Any], book_root: Path, search_path: Path) -> dict[str, t.Any]:
match data:
case {'sections': sections}:
return data | dict(
Expand Down
10 changes: 4 additions & 6 deletions src/nix/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

using namespace nix;

namespace nix::fs { using namespace std::filesystem; }

struct CmdEval : MixJSON, InstallableValueCommand, MixReadOnlyOption
{
bool raw = false;
Expand Down Expand Up @@ -77,8 +75,8 @@ struct CmdEval : MixJSON, InstallableValueCommand, MixReadOnlyOption
if (writeTo) {
stopProgressBar();

//if (pathExists(*writeTo))
// throw Error("path '%s' already exists", *writeTo);
if (pathExists(*writeTo))
throw Error("path '%s' already exists", *writeTo);

std::function<void(Value & v, const PosIdx pos, const std::filesystem::path & path)> recurse;

Expand All @@ -89,8 +87,8 @@ struct CmdEval : MixJSON, InstallableValueCommand, MixReadOnlyOption
// FIXME: disallow strings with contexts?
writeFile(path.string(), v.string_view());
else if (v.type() == nAttrs) {
// N.B. this is idempotent
fs::create_directory(path.string());
// TODO abstract mkdir perms for Windows
createDir(path.string(), 0777);
for (auto & attr : *v.attrs()) {
std::string_view name = state->symbols[attr.name];
try {
Expand Down

0 comments on commit 4a52b29

Please sign in to comment.