Skip to content

Commit 0c65bbe

Browse files
authored
Merge pull request #235 from cachix/docs-aws-creds
2 parents 80f8d94 + 4f800b7 commit 0c65bbe

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,59 @@ Or you can disable pure mode entirely with the `--impure` flag:
174174
```
175175
nix develop --impure
176176
```
177+
178+
### How do I pass AWS credentials to the Nix daemon?
179+
180+
In multi-user mode, Nix commands that operate on the Nix store are forwarded to a privileged daemon. This daemon runs in a separate context from your GitHub Actions workflow and cannot access the workflow's environment variables. Consequently, any secrets or credentials defined in your workflow environment will not be available to Nix operations that require store access.
181+
182+
There are two ways to pass AWS credentials to the Nix daemon:
183+
- Configure a default profile using the AWS CLI
184+
- Install Nix in single-user mode
185+
186+
#### Configure a default profile using the AWS CLI
187+
188+
The Nix daemon supports reading AWS credentials from the `~/.aws/credentials` file.
189+
190+
We can use the AWS CLI to configure a default profile using short-lived credentials fetched using OIDC:
191+
192+
```yaml
193+
job:
194+
build:
195+
runs-on: ubuntu-latest
196+
# Required permissions to request AWS credentials
197+
permissions:
198+
id-token: write
199+
contents: read
200+
steps:
201+
- uses: actions/checkout@v4
202+
- uses: cachix/install-nix-action@v31
203+
- name: Assume AWS Role
204+
uses: aws-actions/configure-aws-credentials@v4.1.0
205+
with:
206+
aws-region: us-east-1
207+
role-to-assume: arn:aws-cn:iam::123456789100:role/my-github-actions-role
208+
- name: Make AWS Credentials accessible to nix-daemon
209+
run: |
210+
sudo -i aws configure set aws_access_key_id "${AWS_ACCESS_KEY_ID}"
211+
sudo -i aws configure set aws_secret_access_key "${AWS_SECRET_ACCESS_KEY}"
212+
sudo -i aws configure set aws_session_token "${AWS_SESSION_TOKEN}"
213+
sudo -i aws configure set region "${AWS_REGION}"
214+
```
215+
216+
#### Install Nix in single-user mode
217+
218+
In some environments it may be possible to install Nix in single-user mode by passing the `--no-daemon` flag to the installer.
219+
This mode is normally used on platforms without an init system, like systemd, and in containerized environments with a single user that can own the entire Nix store.
220+
221+
This approach is more generic as it allows passing environment variables directly to Nix, including secrets, proxy settings, and other configuration options.
222+
223+
However, it may not be suitable for all environments. [Consult the Nix manual](https://nix.dev/manual/nix/latest/installation/nix-security) for the latest restrictions and differences between the two modes.
224+
225+
For example, single-user mode is currently supported on hosted Linux GitHub runners, like `ubuntu-latest`.
226+
It is not supported on macOS runners, like `macos-latest`.
227+
228+
```yaml
229+
- uses: cachix/install-nix-action@v31
230+
with:
231+
install_options: --no-daemon
232+
```

0 commit comments

Comments
 (0)