From d7cf73e5666be125060e323902b10c3df8761a2d Mon Sep 17 00:00:00 2001 From: CSchank Date: Wed, 2 Oct 2024 19:10:03 -0400 Subject: [PATCH] new way of doing Codespaces --- .devcontainer/devcontainer.json | 26 -------------------------- install-nix.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 26 deletions(-) create mode 100755 install-nix.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 4b2ff2c..4bf7e0b 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,35 +1,9 @@ { "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": { diff --git a/install-nix.sh b/install-nix.sh new file mode 100755 index 0000000..0de1547 --- /dev/null +++ b/install-nix.sh @@ -0,0 +1,32 @@ +sh <(curl -L https://nixos.org/nix/install) + +. /home/vscode/.nix-profile/etc/profile.d/nix.sh + +sudo apt update +sudo apt install direnv + +nix-env -iA devenv -f https://github.com/NixOS/nixpkgs/tarball/nixpkgs-unstable +nix-env -iA cachix -f https://cachix.org/api/v1/install + +mkdir -p ~/.config/direnv; touch ~/.config/direnv/direnv.toml; echo -e "[whitelist]\nprefix = ['/workspaces/']" >> ~/.config/direnv/direnv.toml +mkdir -p ~/.config/nix/; touch ~/.config/nix/nix.conf; echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf +echo "trusted-users = root vscode" | sudo tee -a /etc/nix/nix.conf && sudo pkill nix-daemon; cachix use cachix; cachix use digitallyinduced; + +sh ./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 + + +echo -e "\n. ~/.nix-profile/etc/profile.d/nix.sh" >> ~/.bashrc + +sudo apt install direnv; echo -e '\neval "$(direnv hook bash)"' >> ~/.bashrc + +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 +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 + +sudo apt install acl; sudo setfacl -k /tmp + +nix develop --accept-flake-config --impure --command make -s all + +direnv allow