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

Module system deep dive tutorial #645

Merged
merged 40 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
6b00c1c
Draft module system introduction tutorial
infinisil Jul 13, 2023
1a00a42
add intro/conclusion, rework prose, follow styleguide, clean diffs
proofconstruction Sep 14, 2023
c5dbed1
Review pass
proofconstruction Sep 14, 2023
d87f586
Apply suggestions from code review
fricklerhandwerk Oct 26, 2023
6fbd08f
fix whitespace
fricklerhandwerk Oct 26, 2023
cd12ffe
add some more motivation the each section
fricklerhandwerk Oct 26, 2023
d85f142
make scripts downloadable
fricklerhandwerk Oct 26, 2023
d9b4b73
address review comments
fricklerhandwerk Oct 26, 2023
4089839
make script actually work
fricklerhandwerk Oct 26, 2023
003f082
add file watching
fricklerhandwerk Oct 26, 2023
690752b
update diff and wording
fricklerhandwerk Oct 26, 2023
b89a737
more notes on potential pitfalls
fricklerhandwerk Oct 26, 2023
202643a
be explicit which `map` we mean
fricklerhandwerk Oct 26, 2023
dab738c
split nullable from default values
fricklerhandwerk Oct 26, 2023
6cfbb37
also wrap the geocode script
fricklerhandwerk Oct 26, 2023
7d7f939
work through the tutorial to the end
fricklerhandwerk Oct 26, 2023
b9bef80
add tutorial overview
fricklerhandwerk Oct 27, 2023
09f64ca
`lib` is always passed
fricklerhandwerk Oct 27, 2023
ceb46bf
add separate section for `evalModules` and fix link
fricklerhandwerk Oct 27, 2023
3900543
make option strucutre more self-explanatory
fricklerhandwerk Oct 27, 2023
5929af2
explain command line invocations
fricklerhandwerk Oct 27, 2023
b80fdbe
add note on incomplete reference documentation
fricklerhandwerk Oct 27, 2023
b65bb58
add more highlight to the `config` distinction
fricklerhandwerk Oct 27, 2023
3022f0b
fix parameter passing to the `./map` script
fricklerhandwerk Oct 27, 2023
c8c8b9a
fix typo
fricklerhandwerk Oct 27, 2023
110fa17
fix wording
fricklerhandwerk Oct 27, 2023
0231c02
link to summer of nix
fricklerhandwerk Oct 27, 2023
38e6d7d
add missing word
fricklerhandwerk Oct 27, 2023
41b8eed
link to Google Maps API docs
fricklerhandwerk Oct 27, 2023
4e054c3
more explicit requirements
fricklerhandwerk Oct 27, 2023
bb20f34
use correct module system terminology
fricklerhandwerk Oct 27, 2023
b8a36c3
Update source/tutorials/module-system/module-system.md
asymmetric Nov 3, 2023
c775e75
Apply suggestions from code review
asymmetric Nov 3, 2023
a25b549
whitespace
asymmetric Nov 3, 2023
86e86f9
module-system.md: replace comments with captions
asymmetric Nov 3, 2023
bd9bd93
Merge pull request #786 from NixOS/captions
asymmetric Nov 4, 2023
875b51d
add missing lang for code-block
asymmetric Nov 4, 2023
ea3316e
Update module system title
infinisil Nov 9, 2023
e81602b
change most headers to be about module features (#797)
asymmetric Nov 18, 2023
0a2096d
module-system.md: Fix header casing
infinisil Nov 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ['_static', 'tutorials/module-system/files']

# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
Expand Down
1 change: 1 addition & 0 deletions source/tutorials/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ nix-language.md
learning-journey/index.md
nixos/index.md
cross-compilation.md
module-system/module-system.md
```
53 changes: 53 additions & 0 deletions source/tutorials/module-system/files/geocode
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
set -euo pipefail

cachedir=~/.cache/google-api/geocode
mkdir -p "$cachedir"
hash=$(echo "$1" | sha256sum - | cut -d' ' -f1)
cachefile="$cachedir/$hash"

if [[ ! -f "$cachefile" ]]; then

keyFile=${XDG_DATA_HOME:-~/.local/share}/google-api/key

if [[ ! -f "$keyFile" ]]; then
mkdir -p "$(basename "$keyFile")"
echo "No Google API key found in $keyFile" >&2
echo "For getting one, see https://developers.google.com/maps/documentation/geocoding/overview#before-you-begin" >&2
exit 1
fi

key=$(cat "$keyFile")


tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' exit

output=$tmp/output

curlArgs=(
https://maps.googleapis.com/maps/api/geocode/json
--silent --show-error --get --output "$output" --write-out '%{http_code}'
--data-urlencode address="$1"
)

#echo curl ''${curlArgs[@]@Q} >&2

curlArgs+=(--data-urlencode key="$key")

if status=$(curl "${curlArgs[@]}"); then
if [[ "$status" == 200 ]]; then
jq -r '.results[0].geometry.location as $loc | "\($loc | .lat),\($loc | .lng)"' "$output" > "$cachefile"
else
echo "API returned non-200 HTTP status code $status, output is" >&2
cat "$output" >&2
exit 1
fi
else
code=$?
echo "curl exited with code $code" >&2
exit 1
fi
fi

cat "$cachefile"
60 changes: 60 additions & 0 deletions source/tutorials/module-system/files/map
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bash
set -euo pipefail

cachedir=${XDG_CACHE_HOME:-~/.cache}/google-api/maps-static
mkdir -p "$cachedir"
hash=$(echo "$@" | sha256sum - | cut -d' ' -f1)
cachefile="$cachedir/$hash"

if [[ ! -f "$cachefile" ]]; then

keyFile=${XDG_DATA_HOME:-~/.local/share}/google-api/key

if [[ ! -f "$keyFile" ]]; then
mkdir -p "$(basename "$keyFile")"
echo "No Google API key found in $keyFile" >&2
echo "For getting one, see https://developers.google.com/maps/documentation/maps-static/start#before-you-begin" >&2
exit 1
fi

key=$(cat "$keyFile")


tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' exit

output=$tmp/output

curlArgs=(
https://maps.googleapis.com/maps/api/staticmap
--silent --show-error --get --output "$output" --write-out %{http_code}
)

for arg in "$@"; do
curlArgs+=(--data-urlencode "$arg")
done

#echo curl ''${curlArgs[@]@Q} >&2

curlArgs+=(--data-urlencode key="$key")

if status=$(curl "${curlArgs[@]}"); then
if [[ "$status" == 200 ]]; then
mv "$output" "$cachefile"
else
echo "API returned non-200 HTTP status code $status, output is" >&2
cat "$output" >&2
exit 1
fi
else
code=$?
echo "curl exited with code $code" >&2
exit 1
fi
fi

if [[ -t 1 ]]; then
echo "Successful, but won't output image to tty, pipe to a file or icat instead" >&2
else
cat "$cachefile"
fi