I have created a fork of the configuration by srid here https://github.com/eelcovv/nixos-config . I'm pretty satisfied because I can create a setup for different computers.
However, today I am trying to do something which is almost complete. I have a configuration for an external program called ptgui which I want to load for only one hostname name. Therefore, in the file modules/home/default.nix i am trying to added a filtrer on what to import based on the username and hostname. For some reason this does seem to work . I have now:
let
hostName = builtins.getEnv "HOST";
userName = builtins.getEnv "USER";
isEelco = ((builtins.match ".*eelco.*" userName) != null);
isTongfang = ((builtins.match ".*tongfang.*" hostName) != null); # userName == "eelco";
in
{
home.stateVersion = "22.11";
imports =
(
if true then [
./profiles/development.nix
./profiles/datascience.nix
./profiles/engingeering.nix
] else [ ]
)
++
(
if isTongfang then [
./all/ptgui
] else [ ]
)
++
[
./profiles/graphics.nix
./profiles/internet.nix
./profiles/multimedia.nix
./profiles/officetools.nix
./profiles/publishing.nix
./profiles/security.nix
./profiles/socialmedia.nix
./profiles/systemtools.nix
./all/tmux.nix
./all/neovim
# ./helix.nix
./all/ssh.nix
./all/starship.nix
./all/terminal.nix
./all/nix.nix
./all/git.nix
./all/direnv.nix
./all/zellij.nix
# ./nushell.nix
./all/just.nix
./all/powershell.nix
./all/juspay.nix
# conditional imports
# Comment out because of annoying password prompts
# ./all/_1password.nix
];
}
the idea is that i only want to load ptgui when the hostname is tongfang. But this does seem to work. Anybody has any suggestion what i can do? I dont get an error, i only dont include ptgui. If i set the logicatl expression hard to true it does work. Can i filter on hostname and username in this way? Any hints appreciated
Flakes are pure, so I don't think the likes of builtins.getEnv
will work.
Username should be available from home-manager config or your custom config (e.g.: https://github.com/juspay/nixos-unified-template/pull/129 )
Hostname and other stuff you can pass in specialArgs
, unless you are on NixOS, then it is config.networking.hostName
Note that here,
You can also say legacyPackages.homeConfigurations."${myUserName}@${myHostname}"
(the activate app will recognize that). And perhaps you can pass that as specialArg
or something, from toplevel.
Last updated: Feb 21 2025 at 17:45 UTC