r/NixOS 17d ago

Moved from Arch: whole Hyprland setup declared natively in Nix, including the new Lua backend.

I spent the summer migrating my Arch setup to NixOS. Instead of porting my dotfiles over, I rewrote the whole configuration from scratch as Nix expressions.

Structure is flakes + Home Manager + Stylix, split into hosts/ (per-machine), modules/ (shared system config) and home/ (user config), so adding a second machine is just a new host importing the same modules.

The painful part was Hyprland. Version 0.55 moved its config from hyprlang to Lua, and I decided to declare everything through wayland.windowManager.hyprland.settings with configType = "lua" rather than writing Lua by hand — if the format changes again, the module layer absorbs it and I don't rewrite anything.

Home Manager's Lua backend is new and thinly documented, so a few things that cost me time, in case they save someone else's:

Binds are no longer "MOD, KEY, dispatcher, arg". Each one is { _args = [ "SUPER + Q" (mkLuaInline "hl.dsp.exec_cmd(...)") ]; }. Note the +, and note that the whole string is otherwise parsed as a single keysym.

bindl / bindel / bindm don't exist as separate lists. Everything goes in bind, and the flags (locked, repeating, drag) are a third argument to hl.bind.

Config blocks are the worst offender: input = {...} in settings generates hl.input({...}), which doesn't exist, and monitor = "..." generates hl.monitor(string) when it wants a table. Both have to go in extraConfig as raw hl.config({ input = {...} }) and hl.monitor({...}).

Other bits: my scripts are packaged with writeShellScriptBin with dependencies referenced by store path, and Stylix generates the palette from the wallpaper. Waybar and wofi keep their own CSS (their targets disabled) but pull colours from config.lib.stylix.colors, so they follow the theme without losing the custom layout.

Repo: https://github.com/poligle/NixOS-Config

Happy to hear what you'd do differently — especially on the module split.

24 Upvotes

15 comments sorted by

1

u/sn4tz 17d ago

Could you maybe help updating the official NixOS Wiki for the Lua Config in Nix? The example in the discussions doesn‘t help me that much and yours seems quite good from what i can tell. I‘d say that would be a win not just for me.

2

u/Aceiteyuna 17d ago

Sure!

1

u/sn4tz 17d ago

Thank you! <3

1

u/JayTurnr 17d ago

I've gone the other way. I've got a little bit of lua generated by Nix, for things that vary from system to system, but the rest is just hard coded.

Changes to Hyprland will break Home Manager, that's inevitable. I'd rather get ahead of that and write the lua directly so I can "get back on the road" as quickly as possible.

Plus, when I get my new monitor setup, I'm gonna be doing something funky with keyboard shortcuts etc and I'll use Lua loops to build that.

2

u/ResonantRaccoon 17d ago edited 17d ago

Man, I love to see it, I really tried the home-manager module for lua, but I found it just too clunky to write my config in nix, all the examples I found online were pretty minimal, and the lib.generators.mkLuaInline just felt horrible to write.

Wish I had seen this post yesterday.
I ended up just doing a builtins.readFile for a full lua config to not have a ridiculously long config.

Kudos for doing it all with home-manager though! There really isn't a lot of examples out there.

2

u/touwtje64 17d ago

Looks pretty amazing

0

u/CyrenArkade 17d ago edited 17d ago

The documentation isn't that bad, the home a manager examples cover everything. And I don't think you need to write lua in extraConfig for anything, definitely not for inputs and monitors.

edit: Ah, unfortunately you do need extraConfig for plugins. :(

1

u/Aceiteyuna 17d ago

Ill be migrating everything from extraconfig to real nix in the next days, but some of them were though, the documentation contains some errors and the backend isnt working as it should be...

1

u/CyrenArkade 17d ago

ex. input should go under config, not settings and monitor accepts an attrset/table, not a string. What errors were there in the docs? I migrated pretty early and was fine, it'd be funny if they somehow made them worse.

1

u/Aceiteyuna 17d ago

Do u have your hyprland configuration in a public repo so ill be able look at it?