2022-06-16 23:48:18 +00:00
|
|
|
# Dotfiles
|
|
|
|
|
2022-10-23 22:09:58 +00:00
|
|
|
<!-- markdown-link-check-disable -->
|
2022-12-05 11:21:09 +00:00
|
|
|
|
2022-06-16 23:48:18 +00:00
|
|
|
Coder offers the `coder dotfiles <repo>` command which simplifies workspace
|
|
|
|
personalization. Our behavior is consistent with Codespaces, so
|
|
|
|
[their documentation](https://docs.github.com/en/codespaces/customizing-your-codespace/personalizing-codespaces-for-your-account#dotfiles)
|
|
|
|
explains how it loads your repo.
|
2022-12-05 11:21:09 +00:00
|
|
|
|
2022-10-23 22:09:58 +00:00
|
|
|
<!-- markdown-link-check-enable -->
|
2022-06-16 23:48:18 +00:00
|
|
|
|
|
|
|
You can read more on dotfiles best practices [here](https://dotfiles.github.io).
|
|
|
|
|
|
|
|
## Templates
|
|
|
|
|
|
|
|
Templates can prompt users for their dotfiles repo using the following pattern:
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
variable "dotfiles_uri" {
|
|
|
|
description = <<-EOF
|
|
|
|
Dotfiles repo URI (optional)
|
|
|
|
|
|
|
|
see https://dotfiles.github.io
|
|
|
|
EOF
|
|
|
|
# The codercom/enterprise-* images are only built for amd64
|
|
|
|
default = ""
|
|
|
|
}
|
|
|
|
|
2022-07-23 20:26:56 +00:00
|
|
|
resource "coder_agent" "main" {
|
2022-06-16 23:48:18 +00:00
|
|
|
...
|
2022-06-23 19:12:35 +00:00
|
|
|
startup_script = var.dotfiles_uri != "" ? "coder dotfiles -y ${var.dotfiles_uri}" : null
|
2022-06-16 23:48:18 +00:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Persistent Home
|
|
|
|
|
2023-08-23 09:27:57 +00:00
|
|
|
Sometimes you want to support personalization without requiring dotfiles.
|
2022-06-16 23:48:18 +00:00
|
|
|
|
|
|
|
In such cases:
|
|
|
|
|
|
|
|
- Mount a persistent volume to the `/home` directory
|
2023-08-23 09:27:57 +00:00
|
|
|
- Set the `startup_script` to call a `~/personalize` script that the user can
|
|
|
|
edit
|
2022-06-16 23:48:18 +00:00
|
|
|
|
|
|
|
```hcl
|
2022-07-23 20:26:56 +00:00
|
|
|
resource "coder_agent" "main" {
|
2022-06-16 23:48:18 +00:00
|
|
|
...
|
|
|
|
startup_script = "/home/coder/personalize"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
The user can even fill `personalize` with `coder dotfiles <repo>`, but those
|
|
|
|
looking for a simpler approach can inline commands like so:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
#!/bin/bash
|
|
|
|
sudo apt update
|
|
|
|
# Install some of my favorite tools every time my workspace boots
|
|
|
|
sudo apt install -y neovim fish cargo
|
|
|
|
```
|
2023-07-21 18:39:50 +00:00
|
|
|
|
|
|
|
## Setup script support
|
|
|
|
|
2023-08-23 09:27:57 +00:00
|
|
|
User can setup their dotfiles by creating one of the following script files in
|
|
|
|
their dotfiles repo:
|
2023-07-21 18:39:50 +00:00
|
|
|
|
|
|
|
- `install.sh`
|
|
|
|
- `install`
|
|
|
|
- `bootstrap.sh`
|
|
|
|
- `bootstrap`
|
|
|
|
- `script/bootstrap`
|
|
|
|
- `setup.sh`
|
|
|
|
- `setup`
|
|
|
|
- `script/setup`
|
|
|
|
|
2023-08-23 09:27:57 +00:00
|
|
|
If any of the above files are found (in the specified order), Coder will try to
|
|
|
|
execute the first match. After the first match is found, other files will be
|
|
|
|
ignored.
|
2023-07-21 18:39:50 +00:00
|
|
|
|
2023-08-23 09:27:57 +00:00
|
|
|
The setup script must be executable, otherwise the dotfiles setup will fail. If
|
|
|
|
you encounter this issue, you can fix it by making the script executable using
|
|
|
|
the following commands:
|
2023-07-21 18:39:50 +00:00
|
|
|
|
|
|
|
```shell
|
|
|
|
cd <path_to_dotfiles_repo>
|
|
|
|
chmod +x <script_name>
|
|
|
|
git commit -m "Make <script_name> executable" <script_name>
|
|
|
|
git push
|
|
|
|
```
|