Skip to content

Commit

Permalink
Add support for configuring a GitHub access token.
Browse files Browse the repository at this point in the history
  • Loading branch information
rickynils committed Jun 22, 2023
1 parent 562a61a commit 68fb8de
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
17 changes: 14 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,19 @@ inputs:
nix_conf:
required: false
description: |
If set, this configuration is written to a new file which is then added to
the NIX_USER_CONF_FILES environment variable. You can also set that
variable yourself to control the Nix configuration.
If set, this configuration is written to XDG_CONFIG_HOME/nix/nix.conf,
which is read by Nix.
See https://nixos.org/manual/nix/stable/command-ref/conf-file.html for
information on what settings that are available. Make sure the settings
you define are supported by the Nix version you're using.
github_access_token:
required: false
description: |
Configure Nix to use the specified token when it is fetching private
sources from GitHub. If this setting is not specified,
nix-quick-install-action will use the content of the GITHUB_TOKEN
environment variable instead (if set).
nix_on_tmpfs:
required: true
Expand Down Expand Up @@ -51,6 +61,7 @@ runs:
NIX_CONF: ${{ inputs.nix_conf }}
NIX_ARCHIVES_URL: ${{ inputs.nix_archives_url }}
NIX_ON_TMPFS: ${{ inputs.nix_on_tmpfs }}
GITHUB_ACCESS_TOKEN: ${{ inputs.github_access_token }}


branding:
Expand Down
16 changes: 13 additions & 3 deletions nix-quick-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,22 @@ fi
rm -f "$archive"

# Setup nix.conf
if [ -n "$NIX_CONF" ]; then
NIX_CONF_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/nix/nix.conf"
mkdir -p "$(dirname "$NIX_CONF_FILE")"
NIX_CONF_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/nix/nix.conf"
mkdir -p "$(dirname "$NIX_CONF_FILE")"
touch "$NIX_CONF_FILE"
if [ -n "${NIX_CONF:-}" ]; then
printenv NIX_CONF > "$NIX_CONF_FILE"
fi

# Setup GitHub access token
if [[ -n "${GITHUB_ACCESS_TOKEN:-}" ]]; then
echo >>"$NIX_CONF_FILE" \
"access-tokens = github.com=$GITHUB_ACCESS_TOKEN"
elif [[ -n "${GITHUB_TOKEN:-}" ]]; then
echo >>"$NIX_CONF_FILE" \
"access-tokens = github.com=$GITHUB_TOKEN"
fi

# Populate the nix db
nix="$(readlink /nix/var/nix-quick-install-action/nix)"
"$nix/bin/nix-store" --load-db < /nix/var/nix-quick-install-action/registration
Expand Down

0 comments on commit 68fb8de

Please sign in to comment.