From 9057c6e64bda934ede494d0ef7e473739aec5fee Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 26 Jan 2026 12:52:07 +0000 Subject: [PATCH 1/4] Make devcontainer check Codespaces-friendly Co-authored-by: hiroakiendoh --- README.org | 7 +++++++ scripts/devcontainer-check.sh | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.org b/README.org index 71c1742..de482c6 100644 --- a/README.org +++ b/README.org @@ -30,6 +30,13 @@ Keyword: macOS, Xcode, Homebrew, Emacs, Zsh ./scripts/devcontainer-check.sh #+end_src +** GitHub Codespaces +- This repo includes a devcontainer definition at =.devcontainer/devcontainer.json=. +- On first launch, Codespaces runs =./scripts/devcontainer-check.sh= which: + - runs =nix flake check= + - applies the Home Manager configuration for =devcontainer@devcontainer= (user =vscode=) +- If you don't want your Codespace home directory dotfiles to be managed automatically, remove/disable =postCreateCommand= in =.devcontainer/devcontainer.json= and run the script manually when needed. + ** CI - GitHub Actions runs =nix flake check= on Ubuntu and macOS for every push and PR. diff --git a/scripts/devcontainer-check.sh b/scripts/devcontainer-check.sh index ce53801..3217cde 100755 --- a/scripts/devcontainer-check.sh +++ b/scripts/devcontainer-check.sh @@ -2,7 +2,7 @@ set -euo pipefail echo "Running nix flake check..." -nix flake check +nix --accept-flake-config flake check echo "Applying home-manager config for devcontainer..." -nix run nixpkgs#home-manager -- switch --flake .#devcontainer@devcontainer +nix --accept-flake-config run nixpkgs#home-manager -- switch --flake .#devcontainer@devcontainer From 86f281729c7f3cd6a1f21526917def6238fda986 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 26 Jan 2026 12:56:05 +0000 Subject: [PATCH 2/4] Support Codespaces Dotfiles install on Linux Co-authored-by: hiroakiendoh --- README.org | 6 ++++ install.sh | 94 +++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 82 insertions(+), 18 deletions(-) diff --git a/README.org b/README.org index de482c6..c9b655d 100644 --- a/README.org +++ b/README.org @@ -37,6 +37,12 @@ Keyword: macOS, Xcode, Homebrew, Emacs, Zsh - applies the Home Manager configuration for =devcontainer@devcontainer= (user =vscode=) - If you don't want your Codespace home directory dotfiles to be managed automatically, remove/disable =postCreateCommand= in =.devcontainer/devcontainer.json= and run the script manually when needed. +** GitHub Codespaces Dotfiles +- You can also use this repository as a Codespaces *Dotfiles* repository. +- When configured in GitHub settings, Codespaces clones this repo and runs =./install.sh=. +- On Linux (Codespaces), =install.sh= installs Nix (if needed) and applies the Home Manager configuration for =devcontainer@devcontainer=. +- Note: this repo uses a git submodule (=resources/zsh/.zsh/zaw=). =install.sh= initializes submodules automatically, but your environment must allow fetching it. + ** CI - GitHub Actions runs =nix flake check= on Ubuntu and macOS for every push and PR. diff --git a/install.sh b/install.sh index 09510d8..522019d 100644 --- a/install.sh +++ b/install.sh @@ -1,29 +1,87 @@ -#!/bin/bash +#!/usr/bin/env bash +set -euo pipefail -echo "Checking dotnet"; -if !(type dotnet >/dev/null 2>&1); then - if [ ! -f /usr/local/share/dotnet/dotnet ]; then - echo "dotnet doesn't exsist." - ./scripts/install-dotnet.sh +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +cd "$ROOT_DIR" + +is_linux() { [[ "${OSTYPE:-}" == linux* ]]; } +is_darwin() { [[ "${OSTYPE:-}" == darwin* ]]; } + +echo "Initializing submodules (if any)..." +if command -v git >/dev/null 2>&1 && [ -f "$ROOT_DIR/.gitmodules" ]; then + git submodule update --init --recursive +fi + +if is_linux; then + echo "Linux detected: applying Nix/Home Manager config (Codespaces-friendly)." + + if ! command -v nix >/dev/null 2>&1; then + echo "Nix not found; installing Nix..." + # Prefer Determinate Nix installer (works well in containers). + if command -v curl >/dev/null 2>&1; then + curl -fsSL https://install.determinate.systems/nix | sh -s -- install --no-confirm || true + fi + + # Load Nix profile if installed. + if [ -e /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh ]; then + # shellcheck disable=SC1091 + . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh + elif [ -e "${HOME}/.nix-profile/etc/profile.d/nix.sh" ]; then + # shellcheck disable=SC1091 + . "${HOME}/.nix-profile/etc/profile.d/nix.sh" fi - - eval `/usr/libexec/path_helper -s` + fi + + # Ensure flakes are enabled even on older Nix installs. + mkdir -p "${HOME}/.config/nix" + if [ ! -f "${HOME}/.config/nix/nix.conf" ] || ! grep -q "experimental-features" "${HOME}/.config/nix/nix.conf"; then + printf "\nexperimental-features = nix-command flakes\n" >> "${HOME}/.config/nix/nix.conf" + fi + + if ! command -v nix >/dev/null 2>&1; then + echo "ERROR: nix command not available after install attempt." >&2 + exit 1 + fi + + echo "Applying Home Manager configuration..." + nix --accept-flake-config run nixpkgs#home-manager -- switch --flake "$ROOT_DIR#devcontainer@devcontainer" + + echo "Done." + exit 0 fi -echo "Checking dotnet script"; -if !(dotnet tool list -g | grep dotnet-script > /dev/null 2>&1); then - echo "Install dotnet-script"; +if is_darwin; then + echo "macOS detected: running legacy (dotnet-script + Homebrew) installer." + + echo "Checking dotnet" + if ! type dotnet >/dev/null 2>&1; then + if [ ! -f /usr/local/share/dotnet/dotnet ]; then + echo "dotnet doesn't exist." + ./scripts/install-dotnet.sh + fi + + eval "$(/usr/libexec/path_helper -s)" + fi + + echo "Checking dotnet script" + if ! (dotnet tool list -g | grep dotnet-script > /dev/null 2>&1); then + echo "Install dotnet-script" dotnet tool install -g dotnet-script -fi + fi -echo "Checking Homebrew" -if !(type brew > /dev/null); then + echo "Checking Homebrew" + if ! type brew >/dev/null 2>&1; then if [ ! -d /opt/homebrew/bin ]; then - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" fi - + eval "$(/opt/homebrew/bin/brew shellenv)" + fi + + echo "Run installation scripts" + dotnet script scripts/Main.csx + exit 0 fi -echo "Run installation scripts" -dotnet script scripts/Main.csx +echo "Unsupported OS: OSTYPE='${OSTYPE:-unknown}'" >&2 +exit 1 From 16fa4de124795620c389980995093e87fe40eaff Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 27 Jan 2026 14:01:01 +0000 Subject: [PATCH 3/4] Fix Codespaces dotfiles flake target and add codespace user Co-authored-by: hiroakiendoh --- README.org | 4 ++-- flake.nix | 43 ++++++++++++++++++++++++++--------- install.sh | 9 +++++++- scripts/devcontainer-check.sh | 2 +- 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/README.org b/README.org index c9b655d..6d4b4df 100644 --- a/README.org +++ b/README.org @@ -34,13 +34,13 @@ Keyword: macOS, Xcode, Homebrew, Emacs, Zsh - This repo includes a devcontainer definition at =.devcontainer/devcontainer.json=. - On first launch, Codespaces runs =./scripts/devcontainer-check.sh= which: - runs =nix flake check= - - applies the Home Manager configuration for =devcontainer@devcontainer= (user =vscode=) + - applies the Home Manager configuration for =vscode@devcontainer= - If you don't want your Codespace home directory dotfiles to be managed automatically, remove/disable =postCreateCommand= in =.devcontainer/devcontainer.json= and run the script manually when needed. ** GitHub Codespaces Dotfiles - You can also use this repository as a Codespaces *Dotfiles* repository. - When configured in GitHub settings, Codespaces clones this repo and runs =./install.sh=. -- On Linux (Codespaces), =install.sh= installs Nix (if needed) and applies the Home Manager configuration for =devcontainer@devcontainer=. +- On Linux (Codespaces), =install.sh= installs Nix (if needed) and applies the Home Manager configuration for the current user (e.g. =codespace@devcontainer=). - Note: this repo uses a git submodule (=resources/zsh/.zsh/zaw=). =install.sh= initializes submodules automatically, but your environment must allow fetching it. ** CI diff --git a/flake.nix b/flake.nix index 2193e8e..c46bd44 100644 --- a/flake.nix +++ b/flake.nix @@ -17,13 +17,23 @@ hostConfig = import ./nix/hosts.nix; username = hostConfig.username; lib = nixpkgs.lib; - devcontainerHost = { - username = "vscode"; - darwinHost = "devcontainer"; - darwinSystem = hostConfig.darwinSystem; - wslHost = "devcontainer"; - wslSystem = hostConfig.wslSystem; - }; + devcontainerHosts = [ + { + username = "vscode"; + darwinHost = "devcontainer"; + darwinSystem = hostConfig.darwinSystem; + wslHost = "devcontainer"; + wslSystem = hostConfig.wslSystem; + } + # GitHub Codespaces often uses the "codespace" user (Dotfiles feature runs as the current user). + { + username = "codespace"; + darwinHost = "devcontainer"; + darwinSystem = hostConfig.darwinSystem; + wslHost = "devcontainer"; + wslSystem = hostConfig.wslSystem; + } + ]; mkPkgs = system: import nixpkgs { @@ -68,8 +78,17 @@ homeConfigurations."${username}@${hostConfig.wslHost}" = mkHome hostConfig.wslSystem; - homeConfigurations."${devcontainerHost.username}@${devcontainerHost.wslHost}" = - mkHomeWith { system = devcontainerHost.wslSystem; hostCfg = devcontainerHost; }; + homeConfigurations = + { + "${username}@${hostConfig.wslHost}" = mkHome hostConfig.wslSystem; + } + // lib.listToAttrs (map + (dc: + { + name = "${dc.username}@${dc.wslHost}"; + value = mkHomeWith { system = dc.wslSystem; hostCfg = dc; }; + }) + devcontainerHosts); checks = lib.genAttrs (lib.unique [ hostConfig.wslSystem hostConfig.darwinSystem ]) @@ -78,8 +97,10 @@ then { darwin-config = (mkDarwin system).system; } else { home-wsl = (mkHome system).activationPackage; - home-devcontainer = - (mkHomeWith { system = system; hostCfg = devcontainerHost; }).activationPackage; + home-devcontainer-vscode = + (mkHomeWith { system = system; hostCfg = builtins.elemAt devcontainerHosts 0; }).activationPackage; + home-devcontainer-codespace = + (mkHomeWith { system = system; hostCfg = builtins.elemAt devcontainerHosts 1; }).activationPackage; }); }; } diff --git a/install.sh b/install.sh index 522019d..96597b0 100644 --- a/install.sh +++ b/install.sh @@ -44,7 +44,14 @@ if is_linux; then fi echo "Applying Home Manager configuration..." - nix --accept-flake-config run nixpkgs#home-manager -- switch --flake "$ROOT_DIR#devcontainer@devcontainer" + current_user="$(id -un)" + target="${current_user}@devcontainer" + if nix --accept-flake-config run nixpkgs#home-manager -- switch --flake "$ROOT_DIR#${target}"; then + echo "Applied Home Manager for '$target'." + else + echo "WARNING: failed to apply '$target'; falling back to 'vscode@devcontainer'." >&2 + nix --accept-flake-config run nixpkgs#home-manager -- switch --flake "$ROOT_DIR#vscode@devcontainer" + fi echo "Done." exit 0 diff --git a/scripts/devcontainer-check.sh b/scripts/devcontainer-check.sh index 3217cde..c4306f5 100755 --- a/scripts/devcontainer-check.sh +++ b/scripts/devcontainer-check.sh @@ -5,4 +5,4 @@ echo "Running nix flake check..." nix --accept-flake-config flake check echo "Applying home-manager config for devcontainer..." -nix --accept-flake-config run nixpkgs#home-manager -- switch --flake .#devcontainer@devcontainer +nix --accept-flake-config run nixpkgs#home-manager -- switch --flake .#vscode@devcontainer From 9c7c4f563b3ff8ae69fd054c703c0246964c0bc4 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 27 Jan 2026 14:03:17 +0000 Subject: [PATCH 4/4] Fix duplicate homeConfigurations in flake Co-authored-by: hiroakiendoh --- flake.nix | 2 -- 1 file changed, 2 deletions(-) diff --git a/flake.nix b/flake.nix index c46bd44..ff6b897 100644 --- a/flake.nix +++ b/flake.nix @@ -76,8 +76,6 @@ darwinConfigurations.${hostConfig.darwinHost} = mkDarwin hostConfig.darwinSystem; - homeConfigurations."${username}@${hostConfig.wslHost}" = - mkHome hostConfig.wslSystem; homeConfigurations = { "${username}@${hostConfig.wslHost}" = mkHome hostConfig.wslSystem;