Skip to content

Instantly share code, notes, and snippets.

@brianmcgee
Created August 9, 2023 15:05
Show Gist options
  • Select an option

  • Save brianmcgee/7bf282579f00f52750c0edde93d2fe95 to your computer and use it in GitHub Desktop.

Select an option

Save brianmcgee/7bf282579f00f52750c0edde93d2fe95 to your computer and use it in GitHub Desktop.
Passing hostname into home-manager
{ config, inputs, hostName, ... }: {
// hostName should now be available as an arg to all of your home-manager modules
}
nixosConfigurations = {
floyd = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
{ system.stateVersion = "22.11"; }
nixos-hardware.nixosModules.lenovo-thinkpad-x260
./hosts/floyd
./configuration.nix
home-manager.nixosModules.home-manager
({ config, ...}: {
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.extraSpecialArgs = {
inherit inputs;
inherit (config.networking) hostName;
};
home-manager.users.vk = {...}: {
imports = [
./packages/cli-tools.nix
[...more files...]
};
}) # end home-manager
]; # end modules
}; # end floyd
[... rest of flake.nix ...]
@neoSnakex34
Copy link

thank you so much

@OriCat101
Copy link

noice... thx for posting this <3

@andi242
Copy link

andi242 commented Oct 27, 2025

for anyone like me coming across this...
this is possible with accessing osConfig in HA modules as well:

{ pkgs, osConfig, ... }:
{
  home.file."foo".text = osConfig.networking.hostName;
  # ...
}

nix-community/home-manager#393 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment