Skip to content

Commit f75a3d2

Browse files
committed
pass file-system-derived hostname to host configurations
1 parent 33e0f1c commit f75a3d2

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

docs/folder-structure.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ command = "memcached"
126126

127127
### `hosts/<hostname>/(default.nix|configuration.nix|darwin-configuration.nix,system-configuration.nix)`
128128

129-
Each folder contains either a NixOS or nix-darwin configuration:
129+
Each folder contains either a NixOS, [nix-darwin](https://github.com/LnL7/nix-darwin) or [system-manager](https://github.com/numtide/system-manager) configuration:
130130

131131
#### `configuration.nix`
132132

@@ -138,6 +138,7 @@ Additional values passed:
138138
* `flake` maps to `inputs.self`.
139139
* `perSystem`: contains the packages of all the inputs, filtered per system.
140140
Eg: `perSystem.nixos-anywhere.default` is a shorthand for `inputs.nixos-anywhere.packages.<system>.default`.
141+
* `hostname` as per the host directory name.
141142

142143
Flake outputs:
143144

@@ -182,6 +183,7 @@ Additional values passed:
182183
* `flake` maps to `inputs.self`.
183184
* `perSystem`: contains the packages of all the inputs, filtered per system.
184185
Eg: `perSystem.nixos-anywhere.default` is a shorthand for `inputs.nixos-anywhere.packages.<system>.default`.
186+
* `hostname` as per the host directory name.
185187

186188
Flake outputs:
187189

@@ -207,6 +209,7 @@ Additional values passed:
207209
* `flake` maps to `inputs.self`.
208210
* `perSystem`: contains the packages of all the inputs, filtered per system.
209211
Eg: `perSystem.nixos-anywhere.default` is a shorthand for `inputs.nixos-anywhere.packages.<system>.default`.
212+
* `hostname` as per the host directory name.
210213

211214
Flake outputs:
212215

@@ -234,6 +237,7 @@ Additional values passed:
234237

235238
* `inputs` maps to the current flake inputs.
236239
* `flake` maps to `inputs.self`.
240+
* `hostname` as per the host directory name.
237241

238242
Expected return value:
239243

lib/default.nix

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ let
310310
let
311311
loadDefaultFn = { class, value }@inputs: inputs;
312312

313-
loadDefault = path: loadDefaultFn (import path { inherit flake inputs; });
313+
loadDefault = hostname: path: loadDefaultFn (import path { inherit flake inputs hostname; });
314314

315315
loadNixOS = hostname: path: {
316316
class = "nixos";
@@ -319,7 +319,7 @@ let
319319
perSystemModule
320320
path
321321
] ++ mkHomeUsersModule hostname home-manager.nixosModules.default;
322-
inherit specialArgs;
322+
specialArgs = specialArgs // { inherit hostname; };
323323
};
324324
};
325325

@@ -337,12 +337,12 @@ let
337337
perSystemModule
338338
path
339339
] ++ mkHomeUsersModule hostname home-manager.darwinModules.default;
340-
inherit specialArgs;
340+
specialArgs = specialArgs // { inherit hostname; };
341341
};
342342
};
343343

344344
loadSystemManager =
345-
_hostname: path:
345+
hostname: path:
346346
let
347347
system-manager =
348348
inputs.system-manager
@@ -355,15 +355,15 @@ let
355355
perSystemModule
356356
path
357357
];
358-
extraSpecialArgs = specialArgs;
358+
extraSpecialArgs = specialArgs // { inherit hostname; };
359359
};
360360
};
361361

362362
loadHost =
363363
name:
364364
{ path, type }:
365365
if builtins.pathExists (path + "/default.nix") then
366-
loadDefault (path + "/default.nix")
366+
loadDefault name (path + "/default.nix")
367367
else if builtins.pathExists (path + "/configuration.nix") then
368368
loadNixOS name (path + "/configuration.nix")
369369
else if builtins.pathExists (path + "/darwin-configuration.nix") then

0 commit comments

Comments
 (0)