diff --git a/distro/nix/niri.nix b/distro/nix/niri.nix index b74e67bdd..e38866f5f 100644 --- a/distro/nix/niri.nix +++ b/distro/nix/niri.nix @@ -15,10 +15,93 @@ in niri = { enableKeybinds = lib.mkEnableOption "DankMaterialShell niri keybinds"; enableSpawn = lib.mkEnableOption "DankMaterialShell niri spawn-at-startup"; + includes = { + enable = (lib.mkEnableOption "includes for niri-flake") // { + default = true; + }; + override = lib.mkOption { + type = lib.types.bool; + description = '' + Whether DMS settings will be prioritized over settings defined in niri-flake or not + ''; + default = true; + example = false; + }; + originalFileName = lib.mkOption { + type = lib.types.str; + description = '' + A new name for the config file generated by niri-flake + ''; + default = "hm"; + example = "niri-flake"; + }; + filesToInclude = lib.mkOption { + type = lib.types.listOf lib.types.str; + description = '' + A list of dms-generated files to include + ''; + default = [ + "alttab" + "binds" + "colors" + "layout" + "outputs" + "wpblur" + ]; + example = [ + "outputs" + "wpblur" + ]; + }; + }; }; }; config = lib.mkIf cfg.enable { + warnings = ( + lib.optional (cfg.niri.enableKeybinds && cfg.niri.includes.enable) '' + It is not recommended to use both `enableKeybinds` and `includes.enable` at the same time. + '' + ); + + # HACK: niri-flake does not support config includes yet, but we can "fix" that + # TODO: replace with proper config includes after https://github.com/sodiboo/niri-flake/pull/1548 merge + xdg.configFile = lib.mkIf cfg.niri.includes.enable ( + let + cfg' = cfg.niri.includes; + + withOriginalConfig = + dmsFiles: + if cfg'.override then + [ cfg'.originalFileName ] ++ dmsFiles + else + dmsFiles ++ [ cfg'.originalFileName ]; + + fixes = map (fix: "\n${fix}") ( + lib.optional (cfg'.enable && config.programs.niri.settings.layout.border.enable) + # kdl + '' + // Border fix + // See https://yalter.github.io/niri/Configuration%3A-Include.html#border-special-case for details + layout { border { on; }; } + '' + ); + in + { + niri-config.target = lib.mkForce "niri/${cfg'.originalFileName}.kdl"; + niri-config-dms = { + target = "niri/config.kdl"; + text = lib.pipe cfg'.filesToInclude [ + (map (filename: "dms/${filename}")) + withOriginalConfig + (map (filename: "include \"${filename}.kdl\"")) + (files: files ++ fixes) + (builtins.concatStringsSep "\n") + ]; + }; + } + ); + programs.niri.settings = lib.mkMerge [ (lib.mkIf cfg.niri.enableKeybinds { binds =