From c12337258809b78c50742a7bc073f99249fa93c7 Mon Sep 17 00:00:00 2001 From: Diganta Misra Date: Wed, 15 Jul 2026 10:51:05 +0200 Subject: [PATCH 01/11] Updated global agent instructions --- home/AGENTS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/home/AGENTS.md b/home/AGENTS.md index f9145ba..121b9ba 100644 --- a/home/AGENTS.md +++ b/home/AGENTS.md @@ -11,5 +11,5 @@ If something clearly looks off, even if it is not directly related to what you are doing, try to get it fixed along the way. - Apply that same high standard to engineering excellence: lint, test failures, and test flakiness. If you see one, even if it is not caused by what you are working on right now, still get it fixed. - - +- When running jobs on compute clusters, always allocate resources that will maximize usage throughout the job. +- When doing literature review, provide a comprehensive report in a HTML or markdown file containing the high level idea of the paper, blogpost, webpage along with central claims, results and potential weaknesses or conflicts with our proposal. \ No newline at end of file From e2c301b910acc05bb4ed1bc4f920e0c74f4c081b Mon Sep 17 00:00:00 2001 From: Diganta Misra Date: Wed, 15 Jul 2026 11:17:19 +0200 Subject: [PATCH 02/11] Updated user name and brew leaves --- .github/ISSUE_TEMPLATE/config.yml | 2 +- README.md | 4 ++-- configuration.nix | 10 ++++++++++ flake.nix | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 9c1277c..a2862b2 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,5 +1,5 @@ blank_issues_enabled: false contact_links: - name: Feature ideas and personal changes - url: https://github.com/kunchenguid/dotfiles/fork + url: https://github.com/digantamisra98/dotfiles/fork about: Feature requests are not accepted here, but you are welcome to fork this repo and make it yours. diff --git a/README.md b/README.md index d55dfb9..82d3789 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Running the switch builds: On a brand new Mac, from a bare clone of this repo: ```sh -git clone https://github.com/kunchenguid/dotfiles.git +git clone https://github.com/digantamisra98/dotfiles.git cd dotfiles ``` @@ -84,7 +84,7 @@ No separate build-and-copy step. This repo is mine. If you clone it, review these before you run `bootstrap.sh`: -- **Username**: run `./bootstrap.sh` (it detects your macOS username and offers to set it) OR change the single `user = "kunchen"` line in `flake.nix`. +- **Username**: run `./bootstrap.sh` (it detects your macOS username and offers to set it) OR change the single `user = "diganta.misra"` line in `flake.nix`. Everything else (`configuration.nix`, `home.nix`, home directory paths) is threaded from that one variable. - **Host label** `"mac"`, in three places: `flake.nix` (the `darwinConfigurations."mac"` name), `rebuild.sh:5` (the `#mac` at the end of the flake reference), and `bootstrap.sh`'s first-switch command (also `#mac`). All three have to match. diff --git a/configuration.nix b/configuration.nix index 74baa39..51c8060 100644 --- a/configuration.nix +++ b/configuration.nix @@ -34,12 +34,22 @@ onActivation.cleanup = "zap"; # remove anything not listed here onActivation.autoUpdate = true; onActivation.extraFlags = [ "--force" ]; + # Top-level formulae only (from `brew leaves`); dependencies are pulled + # in automatically, so they are intentionally not listed here. brews = [ + "bash" + "fish" + "gemini-cli" + "gh" + "git" "herdr" + "python@3.14" + "uv" ]; casks = [ "wezterm" "claude-code" + "copilot-cli" ]; }; } diff --git a/flake.nix b/flake.nix index 96b6b8d..3951faf 100644 --- a/flake.nix +++ b/flake.nix @@ -18,7 +18,7 @@ let # The one username line to change if this isn't your machine. # bootstrap.sh offers to rewrite this for you if your macOS username differs. - user = "kunchen"; + user = "diganta.misra"; in { darwinConfigurations."mac" = nix-darwin.lib.darwinSystem { From 0c237f960769b6c35263582c4027c937f513cc5d Mon Sep 17 00:00:00 2001 From: Diganta Misra Date: Wed, 15 Jul 2026 11:42:19 +0200 Subject: [PATCH 03/11] updated aliases --- configuration.nix | 4 ++++ flake.nix | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/configuration.nix b/configuration.nix index 51c8060..f41e6ea 100644 --- a/configuration.nix +++ b/configuration.nix @@ -28,6 +28,10 @@ nix-homebrew = { enable = true; inherit user; + # Adopt a pre-existing Homebrew install instead of erroring out. Inert on a + # machine nix-homebrew already manages; needed for a clean first switch on a + # fresh Mac that already had Homebrew (e.g. reproducing this setup elsewhere). + autoMigrate = true; }; homebrew = { enable = true; diff --git a/flake.nix b/flake.nix index 3951faf..0f05a97 100644 --- a/flake.nix +++ b/flake.nix @@ -30,6 +30,10 @@ { home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; + # Rename any pre-existing dotfile (e.g. a hand-written ~/.zshrc) to + # .backup instead of refusing to overwrite it. Lets the first + # switch adopt a machine that already had these files. + home-manager.backupFileExtension = "backup"; home-manager.extraSpecialArgs = { inherit user; }; home-manager.users.${user} = import ./home.nix; } From 3e2bc62e92de21abac0e4a1f71164432a91e4f36 Mon Sep 17 00:00:00 2001 From: Diganta Misra Date: Wed, 15 Jul 2026 11:43:54 +0200 Subject: [PATCH 04/11] updated aliases --- home.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/home.nix b/home.nix index 365a1cb..02bede4 100644 --- a/home.nix +++ b/home.nix @@ -34,6 +34,8 @@ in add = "git add ."; push = "git push"; pull = "git pull"; + gcm = "git commit -m"; + gpp = "git push -origin main"; m = "git switch main"; cc = "claude --dangerously-skip-permissions"; co = "codex --full-auto"; From 1083ab4917cbaeee845c0fb3f41edd908dd9dade Mon Sep 17 00:00:00 2001 From: Diganta Misra Date: Wed, 15 Jul 2026 12:09:43 +0200 Subject: [PATCH 05/11] updated aliases --- home.nix | 2 +- home/.claude/settings.json | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/home.nix b/home.nix index 02bede4..da43327 100644 --- a/home.nix +++ b/home.nix @@ -35,7 +35,7 @@ in push = "git push"; pull = "git pull"; gcm = "git commit -m"; - gpp = "git push -origin main"; + gpp = "git push origin main"; m = "git switch main"; cc = "claude --dangerously-skip-permissions"; co = "codex --full-auto"; diff --git a/home/.claude/settings.json b/home/.claude/settings.json index e3ab775..e0a30f3 100644 --- a/home/.claude/settings.json +++ b/home/.claude/settings.json @@ -1,7 +1,8 @@ { - "theme": "dark-ansi", "statusLine": { "type": "command", "command": "input=$(cat); model=$(echo \"$input\" | jq -r '.model.display_name'); used=$(echo \"$input\" | jq -r '.context_window.used_percentage // empty'); if [ -n \"$used\" ]; then printf \"%s | ctx: %.0f%% used\" \"$model\" \"$used\"; else printf \"%s\" \"$model\"; fi" - } + }, + "theme": "dark-ansi", + "skipDangerousModePermissionPrompt": true } From 02ffefce1c10474a25cac163dc5b491d17ac5b3e Mon Sep 17 00:00:00 2001 From: Diganta Misra Date: Wed, 15 Jul 2026 12:14:48 +0200 Subject: [PATCH 06/11] updated aliases --- home.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/home.nix b/home.nix index da43327..82fab35 100644 --- a/home.nix +++ b/home.nix @@ -32,6 +32,7 @@ in shellAliases = { ".." = "cd .."; add = "git add ."; + status = "git status"; push = "git push"; pull = "git pull"; gcm = "git commit -m"; @@ -39,6 +40,7 @@ in m = "git switch main"; cc = "claude --dangerously-skip-permissions"; co = "codex --full-auto"; + delds = "find . -type f -name '.DS_Store' -delete"; }; }; From 9bfbde560116c1ae8ca180f2d798d3ae74700c18 Mon Sep 17 00:00:00 2001 From: Diganta Misra Date: Wed, 15 Jul 2026 12:32:26 +0200 Subject: [PATCH 07/11] updated herdr config --- home/.config/herdr/config.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/home/.config/herdr/config.toml b/home/.config/herdr/config.toml index 8fa93ac..5e79fbc 100644 --- a/home/.config/herdr/config.toml +++ b/home/.config/herdr/config.toml @@ -1,3 +1,4 @@ +onboarding = false [keys] prefix = "ctrl+b" focus_pane_left = "prefix+h" From 493a8dab626f1075be93f795aa6b1a5e3b419005 Mon Sep 17 00:00:00 2001 From: Diganta Misra Date: Wed, 15 Jul 2026 12:54:02 +0200 Subject: [PATCH 08/11] updated agent.md --- home/AGENTS.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/home/AGENTS.md b/home/AGENTS.md index 121b9ba..cd50070 100644 --- a/home/AGENTS.md +++ b/home/AGENTS.md @@ -1,4 +1,8 @@ -# global agent instructions +# Diganta's agent instructions + +These are common instructions for Diganta's agents across all scenarios. + +# General Guidelines - Never use the em dash "—". Use plain dash "-" instead - When writing commit messages, NEVER auto-add your agent name as co-author @@ -12,4 +16,4 @@ - Apply that same high standard to engineering excellence: lint, test failures, and test flakiness. If you see one, even if it is not caused by what you are working on right now, still get it fixed. - When running jobs on compute clusters, always allocate resources that will maximize usage throughout the job. -- When doing literature review, provide a comprehensive report in a HTML or markdown file containing the high level idea of the paper, blogpost, webpage along with central claims, results and potential weaknesses or conflicts with our proposal. \ No newline at end of file +- When doing literature review, provide a comprehensive report in a HTML or markdown file containing the high level idea of the paper, blogpost, webpage along with central claims, results and potential weaknesses or conflicts with our proposal. From 01a35c801d5e0dfbe15ee2dc4a40fa5f17cdaa09 Mon Sep 17 00:00:00 2001 From: Diganta Misra Date: Wed, 15 Jul 2026 14:59:48 +0200 Subject: [PATCH 09/11] added no-mistakes migration --- configuration.nix | 1 + flake.lock | 23 ++++++++++++++++++++++- flake.nix | 8 ++++++-- home.nix | 30 +++++++++++++++++++++++++++++- home/.claude/settings.json | 16 +++++++++++++++- home/.config/wezterm/wezterm.lua | 4 ++-- 6 files changed, 75 insertions(+), 7 deletions(-) diff --git a/configuration.nix b/configuration.nix index f41e6ea..27b2ffd 100644 --- a/configuration.nix +++ b/configuration.nix @@ -54,6 +54,7 @@ "wezterm" "claude-code" "copilot-cli" + "opensuperwhisper" ]; }; } diff --git a/flake.lock b/flake.lock index 8e22e1a..b0fe676 100644 --- a/flake.lock +++ b/flake.lock @@ -98,7 +98,28 @@ "home-manager": "home-manager", "nix-darwin": "nix-darwin", "nix-homebrew": "nix-homebrew", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "treehouse": "treehouse" + } + }, + "treehouse": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1784059781, + "narHash": "sha256-Ulgkf8o2Z8Gt1uyqHEhwSxNUt1zSZ8Yj/Uf2IAb5oC8=", + "owner": "kunchenguid", + "repo": "treehouse", + "rev": "f31e04e052a3fba1f50afedc65f2c781769aab4a", + "type": "github" + }, + "original": { + "owner": "kunchenguid", + "repo": "treehouse", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index 0f05a97..bca0f40 100644 --- a/flake.nix +++ b/flake.nix @@ -12,9 +12,13 @@ home-manager.inputs.nixpkgs.follows = "nixpkgs"; nix-homebrew.url = "github:zhaofengli/nix-homebrew"; + + # treehouse: git worktree pool manager (Go), installed from its own flake. + treehouse.url = "github:kunchenguid/treehouse"; + treehouse.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = inputs@{ self, nix-darwin, nix-homebrew, home-manager, nixpkgs }: + outputs = inputs@{ self, nix-darwin, nix-homebrew, home-manager, nixpkgs, ... }: let # The one username line to change if this isn't your machine. # bootstrap.sh offers to rewrite this for you if your macOS username differs. @@ -34,7 +38,7 @@ # .backup instead of refusing to overwrite it. Lets the first # switch adopt a machine that already had these files. home-manager.backupFileExtension = "backup"; - home-manager.extraSpecialArgs = { inherit user; }; + home-manager.extraSpecialArgs = { inherit user inputs; }; home-manager.users.${user} = import ./home.nix; } ]; diff --git a/home.nix b/home.nix index 82fab35..500265a 100644 --- a/home.nix +++ b/home.nix @@ -1,7 +1,31 @@ -{ config, pkgs, user, ... }: +{ config, pkgs, user, inputs, ... }: let dotfiles = "${config.home.homeDirectory}/.dotfiles"; + + # no-mistakes: git-push validation proxy. No upstream flake, so install the + # signed prebuilt release binary directly. This keeps it in the Nix profile via + # rebuild — no curl installer, nothing in /usr/local, no sudo beyond darwin-rebuild. + # To bump: change version + hash (nix-prefetch-url the new darwin-arm64 tarball). + no-mistakes = pkgs.stdenvNoCC.mkDerivation rec { + pname = "no-mistakes"; + version = "1.37.0"; + src = pkgs.fetchurl { + url = "https://github.com/kunchenguid/no-mistakes/releases/download/v${version}/no-mistakes-v${version}-darwin-arm64.tar.gz"; + hash = "sha256-jyrIccDKNdrpV78+IOt8r8/V/H3mIsRuXlGQgZJHSaE="; + }; + sourceRoot = "."; # tarball is a single flat binary, no wrapping dir + dontConfigure = true; + dontBuild = true; + dontFixup = true; # skip ALL Mach-O post-processing (strip/re-sign); keeps the upstream + # Developer ID + hardened-runtime signature valid — arm64 kills a + # binary whose signature was invalidated. Nothing to fix in a static Go bin. + installPhase = '' + runHook preInstall + install -Dm755 no-mistakes $out/bin/no-mistakes + runHook postInstall + ''; + }; in { @@ -16,6 +40,10 @@ in jq # json on the command line lazygit neovim + # git worktree pool manager, from its own flake input + inputs.treehouse.packages.${pkgs.system}.default + # git-push validation proxy (prebuilt release binary, defined in the let block above) + no-mistakes # the font everything renders in nerd-fonts.hack ]; diff --git a/home/.claude/settings.json b/home/.claude/settings.json index e0a30f3..839184a 100644 --- a/home/.claude/settings.json +++ b/home/.claude/settings.json @@ -4,5 +4,19 @@ "command": "input=$(cat); model=$(echo \"$input\" | jq -r '.model.display_name'); used=$(echo \"$input\" | jq -r '.context_window.used_percentage // empty'); if [ -n \"$used\" ]; then printf \"%s | ctx: %.0f%% used\" \"$model\" \"$used\"; else printf \"%s\" \"$model\"; fi" }, "theme": "dark-ansi", - "skipDangerousModePermissionPrompt": true + "skipDangerousModePermissionPrompt": true, + "hooks": { + "SessionStart": [ + { + "matcher": "", + "hooks": [ + { + "type": "command", + "command": "gh-axi", + "timeout": 10 + } + ] + } + ] + } } diff --git a/home/.config/wezterm/wezterm.lua b/home/.config/wezterm/wezterm.lua index 8bb9ce8..3b176ca 100644 --- a/home/.config/wezterm/wezterm.lua +++ b/home/.config/wezterm/wezterm.lua @@ -2,10 +2,10 @@ local wezterm = require("wezterm") local config = wezterm.config_builder() -config.color_scheme = "rose-pine-moon" +config.color_scheme = "Dark Violet (base16)" config.font = wezterm.font("Hack Nerd Font") config.font_size = 15.0 -config.window_background_opacity = 0.8 +config.window_background_opacity = 0.7 config.macos_window_background_blur = 50 config.hide_tab_bar_if_only_one_tab = true config.window_decorations = "RESIZE" From ece093da78f961920258d5267ef0f2ef65b31778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xa9aX=20=E3=83=84?= Date: Wed, 15 Jul 2026 15:27:18 +0200 Subject: [PATCH 10/11] updated username for new mac --- README.md | 2 +- flake.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 82d3789..37ba47d 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ No separate build-and-copy step. This repo is mine. If you clone it, review these before you run `bootstrap.sh`: -- **Username**: run `./bootstrap.sh` (it detects your macOS username and offers to set it) OR change the single `user = "diganta.misra"` line in `flake.nix`. +- **Username**: run `./bootstrap.sh` (it detects your macOS username and offers to set it) OR change the single `user = "digantamisra"` line in `flake.nix`. Everything else (`configuration.nix`, `home.nix`, home directory paths) is threaded from that one variable. - **Host label** `"mac"`, in three places: `flake.nix` (the `darwinConfigurations."mac"` name), `rebuild.sh:5` (the `#mac` at the end of the flake reference), and `bootstrap.sh`'s first-switch command (also `#mac`). All three have to match. diff --git a/flake.nix b/flake.nix index bca0f40..0779e08 100644 --- a/flake.nix +++ b/flake.nix @@ -22,7 +22,7 @@ let # The one username line to change if this isn't your machine. # bootstrap.sh offers to rewrite this for you if your macOS username differs. - user = "diganta.misra"; + user = "digantamisra"; in { darwinConfigurations."mac" = nix-darwin.lib.darwinSystem { From 3b5ba7271757fe28261effff1411bff3bb1b4f47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xa9aX=20=E3=83=84?= Date: Wed, 15 Jul 2026 15:36:27 +0200 Subject: [PATCH 11/11] made username machine-agnostic, read from env at eval time --- README.md | 13 +++++++------ bootstrap.sh | 28 +++------------------------- flake.nix | 13 ++++++++++--- rebuild.sh | 3 ++- 4 files changed, 22 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 37ba47d..473f5b7 100644 --- a/README.md +++ b/README.md @@ -46,13 +46,12 @@ Change the host label or CPU architecture if needed, and read the Homebrew clean ./bootstrap.sh ``` -`bootstrap.sh` does four things, in order: +`bootstrap.sh` does three things, in order: 1. Installs Determinate Nix, if it isn't already installed. 2. Symlinks this repo to `~/.dotfiles`. This has to happen before the first build, because `home.nix` points at config files through `~/.dotfiles`. -3. Checks the `user` configured in `flake.nix` against your actual macOS username, and offers to fix it for you if they differ. -4. Runs the first `darwin-rebuild switch`. +3. Runs the first `darwin-rebuild switch`. It fetches the `darwin-rebuild` tool from the nix-darwin 26.05 release branch, then applies this repo's locked flake config. After that, `darwin-rebuild` exists and you're on the normal workflow below. @@ -62,10 +61,11 @@ After that, `darwin-rebuild` exists and you're on the normal workflow below. Once Nix is installed (`bootstrap.sh` step 1 handles that), you can check that the config builds without touching your system - handy when you have edited something: ```sh -nix flake check --no-build -nix build .#darwinConfigurations.mac.system --dry-run +nix flake check --no-build --impure +nix build .#darwinConfigurations.mac.system --dry-run --impure ``` +`--impure` is needed because `flake.nix` reads your username from the environment. If you renamed the host label in "Make it yours", substitute your label for `mac` in these commands. ## Daily use @@ -84,7 +84,8 @@ No separate build-and-copy step. This repo is mine. If you clone it, review these before you run `bootstrap.sh`: -- **Username**: run `./bootstrap.sh` (it detects your macOS username and offers to set it) OR change the single `user = "digantamisra"` line in `flake.nix`. +- **Username**: nothing to change. + `flake.nix` reads your macOS username from the environment at build time (`SUDO_USER` under sudo, `USER` otherwise), so the same branch works on any machine. Everything else (`configuration.nix`, `home.nix`, home directory paths) is threaded from that one variable. - **Host label** `"mac"`, in three places: `flake.nix` (the `darwinConfigurations."mac"` name), `rebuild.sh:5` (the `#mac` at the end of the flake reference), and `bootstrap.sh`'s first-switch command (also `#mac`). All three have to match. diff --git a/bootstrap.sh b/bootstrap.sh index 070a97f..55d6911 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -20,30 +20,7 @@ echo "==> Step 2: symlink this repo to ~/.dotfiles" # has to exist before the first switch or the build will fail to find them. ln -sfn "$DIR" ~/.dotfiles -echo "==> Step 3: personalize the configured username" -# Do this before any sudo call: sudo resets $USER to root, so whoami has to -# run as the real interactive user first. -REAL_USER="$(whoami)" -FLAKE_USER="$(sed -nE 's/^[[:space:]]*user = "([^"]+)";.*/\1/p' "$DIR/flake.nix" | head -n1)" -if [ -z "$FLAKE_USER" ]; then - echo " Could not find the single \"user = \" line in flake.nix." - echo " Edit flake.nix yourself before continuing." - exit 1 -elif [ "$FLAKE_USER" != "$REAL_USER" ]; then - echo " flake.nix is configured for user \"$FLAKE_USER\", but you are \"$REAL_USER\"." - read -r -p " Rewrite flake.nix's \"user = \" line to \"$REAL_USER\"? [y/N] " REPLY - if [ "$REPLY" = "y" ] || [ "$REPLY" = "Y" ]; then - sed -i '' -E "s/^([[:space:]]*user = \")[^\"]+(\";.*)/\1${REAL_USER}\2/" "$DIR/flake.nix" - echo " Updated. Review the change with: git diff flake.nix" - else - echo " Skipped. Edit the single \"user = \" line in flake.nix yourself before continuing." - exit 1 - fi -else - echo " flake.nix already matches \"$REAL_USER\", nothing to do." -fi - -echo "==> Step 4: first darwin-rebuild switch (pinned to nix-darwin-26.05)" +echo "==> Step 3: first darwin-rebuild switch (pinned to nix-darwin-26.05)" # darwin-rebuild doesn't exist yet on a fresh machine, so run it straight # from the flake this once. After this, rebuild.sh works normally. # This fetches the darwin-rebuild tool from the nix-darwin-26.05 release branch, @@ -55,8 +32,9 @@ echo "==> Step 4: first darwin-rebuild switch (pinned to nix-darwin-26.05)" NIX_BIN="$(command -v nix)" # "mac" is the flake host label - if you renamed it, change it in flake.nix # and rebuild.sh too. +# --impure lets flake.nix read the username from the environment (SUDO_USER). sudo "$NIX_BIN" run github:nix-darwin/nix-darwin/nix-darwin-26.05#darwin-rebuild -- \ - switch --flake ~/.dotfiles#mac + switch --flake ~/.dotfiles#mac --impure # If this still fails with "nix: command not found", open a new terminal # (Determinate adds nix to new shells' PATH) and re-run ./bootstrap.sh. diff --git a/flake.nix b/flake.nix index 0779e08..4f3b863 100644 --- a/flake.nix +++ b/flake.nix @@ -20,9 +20,16 @@ outputs = inputs@{ self, nix-darwin, nix-homebrew, home-manager, nixpkgs, ... }: let - # The one username line to change if this isn't your machine. - # bootstrap.sh offers to rewrite this for you if your macOS username differs. - user = "digantamisra"; + # Read the username from the environment at evaluation time, so the same + # branch builds on any machine with no per-machine edits. SUDO_USER wins + # because darwin-rebuild runs under sudo, where USER is "root". + # getEnv needs impure evaluation - rebuild.sh and bootstrap.sh pass --impure. + sudoUser = builtins.getEnv "SUDO_USER"; + envUser = builtins.getEnv "USER"; + user = + if sudoUser != "" then sudoUser + else if envUser != "" && envUser != "root" then envUser + else throw "Cannot determine the username: run via ./rebuild.sh, or pass --impure so flake.nix can read $USER."; in { darwinConfigurations."mac" = nix-darwin.lib.darwinSystem { diff --git a/rebuild.sh b/rebuild.sh index b0b6bf1..f43131d 100755 --- a/rebuild.sh +++ b/rebuild.sh @@ -2,4 +2,5 @@ set -euo pipefail DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" ln -sfn "$DIR" ~/.dotfiles -exec sudo darwin-rebuild switch --flake ~/.dotfiles#mac +# --impure lets flake.nix read the username from the environment (SUDO_USER). +exec sudo darwin-rebuild switch --flake ~/.dotfiles#mac --impure