Hi!
I have the following problem. I’m trying to declare different monitor resolution based on host in Hyprland. This is my config:
{ config, lib, ... }:
{
wayland.windowManager.hyprland = {
enable = true;
xwayland.enable = true;
settings = {
# monitors:
lib.mkMerge = [
(lib.mkIf config.networking.hostName == "host-1" {
monitor = [
"eDP-1, 1366x768@60, 0x0, 1"
"HDMI-A-1, 1920x1080@100, 0x0, 1"
];
})
(lib.mkIf config.networking.hostName == "host-2" {
monitor = "eDP-1, 1920x1080@120, 0x0, 1";
})
];
};
}
(I’ve omitted irrelevant lines)
But when I try to rebuild home-manager I get this error:
error: attempt to call something which is not a function but a string: "host-1"
at /nix/store/d2ghwj8d81n877c05my379pbzxs3ck6z-source/hyprland/hyprland.nix:26:49:
25| lib.mkMerge = [
26| (lib.mkIf config.networking.hostName == "host-1" {
| ^
27| monitor = [
Well… I can see that it is a string, I’m quite confused because I saw exactly this form here:
https://www.reddit.com/r/NixOS/comments/8xxvcy/if_blocks_based_on_hostname_in_configurationnix/
And even here:
https://nixos.wiki/wiki/Extend_NixOS
Can you guys help me out with this?
Best,
Miro
If I understand correctly:
lib.mkMerge = [
(lib.mkIf "config.networking.hostName == dell-1" {
monitor = [
"eDP-1, 1366x768@60, 0x0, 1"
"HDMI-A-1, 1920x1080@100, 0x0, 1"
];
})
(lib.mkIf "config.networking.hostName == dell-3" {
monitor = "eDP-1, 1920x1080@120, 0x0, 1";
})
];
Then it gives me this error:
error: ‘mkIf’ called with a non-Boolean condition
bme
March 15, 2025, 10:20am
4
config.networking.hostName == "dell-1"
should become
(config.networking.hostName == "dell-1")
The issue is function calls bind tighter than equality. You can replicate this in the repl pretty easily:
~
❯ nix repl --file '<nixpkgs>'
Nix 2.24.12
Type :? for help.
Loading installable ''...
Added 22985 variables.
nix-repl> foo = "xxx"
nix-repl> lib.mkIf foo == "XXX" { some.attr = {}; }
error: attempt to call something which is not a function but a string: "XXX"
at «string»:1:17:
1| lib.mkIf foo == "XXX" { some.attr = {}; }
| ^
nix-repl> lib.mkIf (foo == "XXX") { some.attr = {}; }
{
_type = "if";
condition = false;
content = { ... };
}
You can replicate the exact error trivially:
nix-repl> "hai" {}
error: attempt to call something which is not a function but a string: "hai"
at «string»:1:1:
1| "hai" {}
| ^
Perhaps you can see why parentheses help? They force the equality clause to be evaluated correctly and passed as the second arg to mkIf
.
I’m sorry, English is my second language. Thank you for clarification.
It turns this error:
error: attribute 'networking' missing
at /nix/store/wgqb5y06xrq10j4sj89zm5bda6zjvkqd-source/hyprland/hyprland.nix:25:20:
24| lib.mkMerge = [
25| (lib.mkIf (config.networking.hostName == "host-1") {
| ^
26| monitor = [
How can I access hostname value from home-manager?
bme
March 15, 2025, 10:58am
6
As home-manager doesn’t configure it, it isn’t in the config. You can do something filthy like
nix-repl> lib.strings.trim (builtins.readFile /etc/hostname)
"lamorna"
but it would probably be better to either 1. add an option with the host yourself, and make small file per host that imports your modules and sets the host option, you can then specify the host with -f host.nix, or 2. I think flakes probably has something, I’m always hearing it is the only way to manage multiple systems! I don’t use them, so I couldn’t tell you.
Okay, thank you, I’ll do some research.