Skip to content

Commit 3b56bc0

Browse files
committed
flake: parametrize host — one entry per machine
mkDarwinHost carries the shared modules; a new Mac is one line in darwinConfigurations (plus optional per-host extraModules). NIX_HOST in the Makefile and bootstrap.sh comes from scutil now, and the CI eval covers every declared host automatically instead of naming one.
1 parent e80bbca commit 3b56bc0

4 files changed

Lines changed: 32 additions & 23 deletions

File tree

.github/workflows/checks.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
- uses: actions/checkout@v4
4646
- uses: DeterminateSystems/nix-installer-action@v16
4747
- run: nix flake check
48-
# Pure eval type-checks the whole darwin + home-manager module tree;
49-
# no macOS runner needed.
50-
- run: nix eval .#darwinConfigurations.Sankets-MacBook-Air.system.drvPath
48+
# Pure eval type-checks every host's darwin + home-manager module tree;
49+
# no macOS runner needed, and new hosts are covered automatically.
50+
- run: nix eval .#darwinConfigurations --apply 'cfgs: builtins.mapAttrs (_: c: c.system.drvPath) cfgs'
5151
- run: nix run nixpkgs#statix -- check nix/

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ HM_PACKAGES := zsh git atuin btop gh bin
1313

1414
# The brewfile is generated by the nix-darwin homebrew module
1515
# (nix/darwin/homebrew.nix); scripts/nix-brewfile.sh prints its path.
16-
NIX_HOST := Sankets-MacBook-Air
16+
# The local host name selects the darwinConfigurations entry; a new machine
17+
# needs its own entry in flake.nix (see mkDarwinHost).
18+
NIX_HOST := $(shell scutil --get LocalHostName)
1719
# Absolute paths: make's shell (and sudo's secure_path) don't carry the
1820
# nix profile dirs.
1921
NIX := /nix/var/nix/profiles/default/bin/nix

bootstrap.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
# curl -fsSL https://raw.githubusercontent.com/sanketsudake/dotfiles/main/bootstrap.sh -o /tmp/bootstrap.sh
88
# bash /tmp/bootstrap.sh
99
#
10-
# The flake pins one host config (see NIX_HOST in the Makefile). On a machine
11-
# with a different LocalHostName, add a darwinConfigurations entry for it (or
12-
# rename the machine) before bootstrapping.
10+
# The host name selects the darwinConfigurations entry; on a new machine, add
11+
# an entry for its LocalHostName in flake.nix (mkDarwinHost) before running.
1312
set -euo pipefail
1413

1514
DOTFILES_DIR="${DOTFILES_DIR:-$HOME/personal/dotfiles}"
1615
DOTFILES_SSH="git@github.com:sanketsudake/dotfiles.git"
1716
DOTFILES_HTTPS="https://github.com/sanketsudake/dotfiles.git"
18-
NIX_HOST="Sankets-MacBook-Air"
17+
NIX_HOST="$(scutil --get LocalHostName)"
1918

2019
step() { printf '\n==> %s\n' "$*"; }
2120

flake.nix

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,30 @@
1515

1616
outputs =
1717
inputs@{ nixpkgs, nix-darwin, ... }:
18+
let
19+
# One host = one entry below. Shared config lives in nix/darwin and
20+
# nix/home; per-host overrides go in the extraModules list.
21+
mkDarwinHost =
22+
extraModules:
23+
nix-darwin.lib.darwinSystem {
24+
specialArgs = { inherit inputs; };
25+
modules = [
26+
./nix/darwin
27+
inputs.home-manager.darwinModules.home-manager
28+
{
29+
home-manager = {
30+
useGlobalPkgs = true;
31+
useUserPackages = true;
32+
backupFileExtension = "hm-backup";
33+
users.sanketsudake = import ./nix/home;
34+
};
35+
}
36+
]
37+
++ extraModules;
38+
};
39+
in
1840
{
19-
darwinConfigurations."Sankets-MacBook-Air" = nix-darwin.lib.darwinSystem {
20-
specialArgs = { inherit inputs; };
21-
modules = [
22-
./nix/darwin
23-
inputs.home-manager.darwinModules.home-manager
24-
{
25-
home-manager = {
26-
useGlobalPkgs = true;
27-
useUserPackages = true;
28-
backupFileExtension = "hm-backup";
29-
users.sanketsudake = import ./nix/home;
30-
};
31-
}
32-
];
33-
};
41+
darwinConfigurations."Sankets-MacBook-Air" = mkDarwinHost [ ];
3442

3543
formatter.aarch64-darwin = nixpkgs.legacyPackages.aarch64-darwin.nixfmt-rfc-style;
3644
};

0 commit comments

Comments
 (0)