From 93d4c05dac89ce62ad4b2061494bd9ddd620a07c Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Thu, 19 Sep 2024 00:32:42 +0000 Subject: [PATCH] Initial commit --- .devcontainer/devcontainer.json | 52 +++++++++++++++++++++++++++++++++ README.md | 23 +++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100644 README.md diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..4b2ff2c --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,52 @@ +{ + "image": "mcr.microsoft.com/devcontainers/base:jammy", + + "features": { + "ghcr.io/devcontainers/features/nix:1": { + "multiUser": true, + "packages": ["cachix", "ihp-new"], + "extraNixConfig": "experimental-features = nix-command flakes,keep-outputs = true,keep-derivations = true" + } + }, + + + "onCreateCommand": { + "Setup cachix": "echo \"trusted-users = root vscode\" | sudo tee -a /etc/nix/nix.conf && sudo pkill nix-daemon; cachix use cachix; cachix use digitallyinduced;", + "Setup direnv": "sudo apt install direnv; echo 'eval \"$(direnv hook bash)\"' >> ~/.bashrc", + "Set IHP BASEURL": "echo 'export IHP_BASEURL=$(if [ -n \"${CODESPACE_NAME}\" ]; then echo \"https://${CODESPACE_NAME}-8000.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}\"; else echo \"http://localhost:8000\"; fi)' >> ~/.bashrc", + "Set IHP IDE BASEURL": "echo 'export IHP_IDE_BASEURL=$(if [ -n \"${CODESPACE_NAME}\" ]; then echo \"https://${CODESPACE_NAME}-8001.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}\"; else echo \"http://localhost:8001\"; fi)' >> ~/.bashrc", + "Fix nix Permissions": "sudo apt install acl; sudo setfacl -k /tmp", + "Allow direnv": "mkdir -p ~/.config/direnv; touch ~/.config/direnv/direnv.toml; echo \"[whitelist]\nprefix = ['/workspaces/']\" >> ~/.config/direnv/direnv.toml" + }, + + "postCreateCommand": { + // Credits to https://github.com/gitpod-samples/template-ihp/blob/e3fe7012621ab57657c59511b2fe0bc615d5186d/.gitpod.yml#L14 + "Setup IHP": "sudo /usr/local/share/nix-entrypoint.sh; ( if [ ! -e \"Main.hs\" ]; then rm -rf /tmp/ihp-boilerplate; git clone \"https:\/\/github.com/digitallyinduced/ihp-boilerplate.git\" /tmp/ihp-boilerplate; rm -rf /tmp/ihp-boilerplate/.git; cp -r /tmp/ihp-boilerplate/. .; fi) && git add . && nix develop --accept-flake-config --impure --command make -s all; if [ ! -d \"Web\" ]; then (nix develop --accept-flake-config --impure --command new-application Web) fi" + }, + + "containerEnv": { + "PROJECT_DIR": "${containerWorkspaceFolder}" + }, + + "remoteUser": "vscode", + + "customizations": { + "vscode": { + "settings": { + "terminal.integrated.profiles.linux": { + "bash": { + "path": "/bin/bash" + } + }, + "terminal.integrated.defaultProfile.linux": "bash" + }, + "extensions": [ + "bbenoist.nix", + "haskell.haskell", + "s0kil.vscode-hsx", + "mkhl.direnv", + "vigoo.stylish-haskell" + ] + } + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..e46f50d --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# GitHub Codespaces IHP Template + +This is an IHP template configured to run on GitHub Codespaces and [VSCode Devcontainers](https://code.visualstudio.com/docs/devcontainers/containers). + +## Getting Started + +### For New Projects +1. Create a repository from this template. +2. Run it in Codespaces / Devcontainers. +3. Wait for the initial setup to complete. This will take a few minutes and will use two bash windows, one of which will close when it's done. The other should be a blank terminal when it's done. +4. Run `devenv up` to start the server. +5. Have fun with IHP! :) + +### An existing IHP project +To add support to an existing IHP project, simply copy the [devcontainer configuration](.devcontainer/devcontainer.json) to your project, +placing it in `.devcontainer/devcontainer.json`. Then follow the above instructions. + +## Note +Sometimes GitHub updates Codespaces or their base container image, which may break this devcontainer configuration. Please check here regularly for +updates and post an issue if you have problems running a Codespace / Devcontainer. To update, simply copy the new `devcontainer.json` +to your project, and then rebuild the container or recreate your Codespace / Devcontainer entirely. + +See also [ihp.digitallyinduced.com](https://ihp.digitallyinduced.com/)