# Write a lazypath to a file

**URL:** <https://ziggit.dev/t/write-a-lazypath-to-a-file/9210>\
**Category:** Help\
**Tags:** build-system\
**Created:** [March 22, 2025, 9:31pm UTC](https://ziggit.dev/t/write-a-lazypath-to-a-file/9210 "2025-03-22T21:31:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![arnau](https://ziggit.dev/user_avatar/ziggit.dev/arnau/32/4888_2.png) [@arnau](https://ziggit.dev/u/arnau)\
**Post date:** [March 22, 2025, 9:31pm UTC](https://ziggit.dev/t/write-a-lazypath-to-a-file/9210/1 "2025-03-22T21:31:53Z")

</div>

In my build system, I want to use a system command. Unfortunately, the way that specific command takes options is not through arguments. Instead, it takes a JSON config file. One of the fields should be the path to a (generated) file, thus a `LazyPath`. Is there a clean way to write the LazyPath to a file, and then pass that file as an argument? Thanks.

---

<div class="post-metadata">

**Author:** ![mnemnion](https://ziggit.dev/user_avatar/ziggit.dev/mnemnion/32/2478_2.png) [@mnemnion](https://ziggit.dev/u/mnemnion)\
**Post date:** [March 22, 2025, 9:37pm UTC](https://ziggit.dev/t/write-a-lazypath-to-a-file/9210/2 "2025-03-22T21:37:01Z")

</div>

`b.path` is usually given a string literal, but any slice will do the job. It’s not 100% clear what you want to do here, but if it’s reading a relative path out of a file and providing that to `b.path`, you can certainly do that.

---

<div class="post-metadata">

**Author:** ![arnau](https://ziggit.dev/user_avatar/ziggit.dev/arnau/32/4888_2.png) [@arnau](https://ziggit.dev/u/arnau)\
**Post date:** [March 22, 2025, 9:43pm UTC](https://ziggit.dev/t/write-a-lazypath-to-a-file/9210/3 "2025-03-22T21:43:27Z")

</div>

Sorry for the bad explanation. I have a generated file, which is a LazyPath. Let’s call it “initrd”. I have a command, `mkbootimg`, that takes arguments as `mkbootimg <config_file> <output>`. The thing is, in the (JSON) config file, I have to specify the path to “initrd”. So, what I want is to write the path of “initrd” into a JSON file, and then pass that JSON file as a parameter. But remember, “initrd” is a lazypath…

---

<div class="post-metadata">

**Author:** ![vulpesx](https://ziggit.dev/user_avatar/ziggit.dev/vulpesx/32/3989_2.png) [@vulpesx](https://ziggit.dev/u/vulpesx)\
**Post date:** [March 22, 2025, 9:48pm UTC](https://ziggit.dev/t/write-a-lazypath-to-a-file/9210/4 "2025-03-22T21:48:21Z")

</div>

Can you specify the path via an argument, cause then you can just pass the `lazyPath` using the relevant functions.  
If it needs to be in a file then perhaps make a script that writes the path that it takes as an argument.

when running commands from the build system you should always configure inputs and outputs via args or capture stdout/in, that way the build system can use its cache

---

<div class="post-metadata">

**Author:** ![arnau](https://ziggit.dev/user_avatar/ziggit.dev/arnau/32/4888_2.png) [@arnau](https://ziggit.dev/u/arnau)\
**Post date:** [March 22, 2025, 9:54pm UTC](https://ziggit.dev/t/write-a-lazypath-to-a-file/9210/5 "2025-03-22T21:54:00Z")

</div>

> [@vulpesx](#):
>
> Can you specify the path via an argument, cause then you can just pass the `lazyPath` using the relevant functions.

I would love to use `addFileArg`, but unfortunately the only way the program takes that file path is through a JSON file.

I think I’ll do what you said. I’ll write a script and call that. Thanks!

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [March 23, 2025, 12:22am UTC](https://ziggit.dev/t/write-a-lazypath-to-a-file/9210/6 "2025-03-23T00:22:00Z")

</div>

You can adapt this example [Zig Build System ⚡ Zig Programming Language](https://ziglang.org/learn/build-system/#project-tools)

Pass the actual path as input argument to the zig program that writes it to a json file, then pass it an output file too, then get the lazy path to that json output file and pass that to the command that expects the json.
