Repository navigation
Expand file tree
/
Copy pathshell.nix
More file actions
85 lines (76 loc) · 2.96 KB
/
Copy pathshell.nix
File metadata and controls
85 lines (76 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Development shell for the easybill → Xero exporter (Rust).
#
# Usage:
# nix-shell # drop into a shell with the full Rust toolchain
# direnv allow # or let direnv load it automatically (see .envrc;
# # personal additions go in .envrc.local)
#
# The toolchain comes from nixpkgs, so `rustup` is not involved.
#
# By default this tracks your ambient <nixpkgs> channel. To pin a specific
# nixpkgs revision for reproducibility, replace the `pkgs ?` default with a
# fetchTarball of a known commit, e.g.:
#
# pkgs ? import (fetchTarball {
# url = "https://github.com/NixOS/nixpkgs/archive/<commit>.tar.gz";
# sha256 = "<run once; Nix prints the correct hash>";
# }) { }
{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell {
name = "easybill-xero";
# Rust toolchain + build tools.
nativeBuildInputs = with pkgs; [
rustc
cargo
clippy
rustfmt
rust-analyzer
pkg-config
];
# Let rust-analyzer resolve the standard library sources.
RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}";
# CA bundle so `cargo` can fetch crates from inside the shell.
SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
shellHook = ''
echo "easybill-xero dev shell — $(rustc --version)"
# Load the credentials from ~/.secrets/xero.
#
# This is done here in the shellHook (plain bash at shell entry), NOT via
# builtins.readFile: reading the secret at Nix eval time would copy it into
# the world-readable Nix store. Values are never printed.
#
# Supported layouts:
# - a file: ~/.secrets/xero containing `KEY=value` lines (with or
# without `export`); every variable in it is exported
# - a directory: ~/.secrets/xero/ with one file per value:
# client_id -> XERO_CLIENT_ID
# client_secret -> XERO_CLIENT_SECRET
# easybill_api_token -> EASYBILL_API_TOKEN
# auth -> XERO_AUTH (`oauth` or `client-credentials`)
xero_secret="$HOME/.secrets/xero"
if [ -f "$xero_secret" ]; then
set -a
# shellcheck disable=SC1090
. "$xero_secret"
set +a
elif [ -d "$xero_secret" ]; then
for entry in client_id:XERO_CLIENT_ID client_secret:XERO_CLIENT_SECRET \
easybill_api_token:EASYBILL_API_TOKEN auth:XERO_AUTH; do
file="$xero_secret/''${entry%%:*}"
[ -f "$file" ] && export "''${entry#*:}=$(cat "$file")"
done
unset entry file
fi
missing=""
for var in XERO_CLIENT_ID XERO_CLIENT_SECRET EASYBILL_API_TOKEN; do
[ -n "$(printenv "$var")" ] || missing="$missing $var"
done
if [ -z "$missing" ]; then
echo "Credentials loaded from $xero_secret (Xero auth: ''${XERO_AUTH:-oauth})"
else
echo "Not set:$missing — expected $xero_secret as an env file" \
"or a directory with one file per value (see shell.nix)."
fi
unset missing var
'';
}