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

Expose the executable bit into a HTTP header #27

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ unpack and serve any file in the cache on the fly.

Inside the provided nix shell run:

```
```shell
./start-dev
```

Expand All @@ -26,18 +26,32 @@ Currently, the default port is 8383. You can change it by setting the `PORT` env

## Usage

Store contents can be fetched via a simple HTTP GET request.

Append any store path to the hostname to fetch and unpack it on
the fly. That's it.

Eg:
E.g.:

* https://nar-serve.zimbatm.now.sh/nix/store/barxv95b8arrlh97s6axj8k7ljn7aky1-go-1.12/share/go/doc/effective_go.html

NAR archives also contain information about the executable bit for each contained file.
nar-serve uses a custom HTTP header named `NAR-executable` to indicate whether the fetched file would be executable.

## Configuration

You can use the following environment variables to configure nar-serve:

| Name | Default value | Description |
|:-- |:-- |:-- |
| `PORT` | `8383` | Port number on which nar-service listens |
| `NAR_CACHE_URL` | `https://cache.nixos.org` | The URL of the Nix store from which NARs are fetched |

## Contributing

Contributions are welcome!

Before adding any new feature it might be best to first discuss them by
creating a new issue in https://github.com/numtide/nar-serve/issues .

All code is licenses under the Apache 2.0 license.
All code is licensed under the Apache 2.0 license.
4 changes: 4 additions & 0 deletions api/unpack/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ func Handler(w http.ResponseWriter, req *http.Request) {
// TODO: use http.DetectContentType as a fallback
}

if hdr.Executable {
w.Header().Set("NAR-Executable", "1")
}

w.Header().Set("Cache-Control", "immutable")
Copy link
Member

Choose a reason for hiding this comment

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

I think this header was removed by mistake?

Looks good otherwise

Copy link
Member

Choose a reason for hiding this comment

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

If you could document the header somewhere that would be nice as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh sorry, I've missed this. Its fixed now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've also updated the README.md

Copy link
Member

Choose a reason for hiding this comment

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

awesome, thank you!

w.Header().Set("Content-Type", ctype)
w.Header().Set("Content-Length", fmt.Sprintf("%d", hdr.Size))
Expand Down
Loading