refactor: format nix code with alejandra & rename nix files for clarity

This commit is contained in:
pengo 2026-06-08 17:38:35 -06:00
parent bb86ea12ca
commit df492dab6b
6 changed files with 298 additions and 311 deletions

View file

@ -40,25 +40,25 @@
system, system,
}: let }: let
inherit (pkgs) callPackage; inherit (pkgs) callPackage;
mango = callPackage ./nix { mango = callPackage ./nix/package.nix {
inherit (scenefx.packages.${system}) scenefx; inherit (scenefx.packages.${system}) scenefx;
}; };
in { in {
inherit mango; inherit mango;
default = mango; default = mango;
hm-options-json = callPackage (import ./nix/generate-options.nix self) { hm-options-json = callPackage (import ./nix/generate-options.nix self) {
module = ./nix/hm-modules.nix; module = ./nix/hm-module.nix;
optionPrefix = "wayland.windowManager.mango."; optionPrefix = "wayland.windowManager.mango.";
}; };
nixos-options-json = callPackage (import ./nix/generate-options.nix self) { nixos-options-json = callPackage (import ./nix/generate-options.nix self) {
module = ./nix/nixos-modules.nix; module = ./nix/nixos-module.nix;
optionPrefix = "programs.mango."; optionPrefix = "programs.mango.";
}; };
} }
); );
nixosModules.mango = import ./nix/nixos-modules.nix self; nixosModules.mango = import ./nix/nixos-module.nix self;
hmModules.mango = import ./nix/hm-modules.nix self; hmModules.mango = import ./nix/hm-module.nix self;
devShells = forEachSystem ( devShells = forEachSystem (
{system, ...}: { {system, ...}: {

View file

@ -1,11 +1,9 @@
self: self: {
{
pkgs, pkgs,
lib ? pkgs.lib, lib ? pkgs.lib,
module, module,
optionPrefix, optionPrefix,
}: }: let
let
# Absolute store path of the flake root, used to compute relative subpaths # Absolute store path of the flake root, used to compute relative subpaths
repoPath = toString self; repoPath = toString self;
@ -28,8 +26,7 @@ let
optionsDoc = pkgs.nixosOptionsDoc { optionsDoc = pkgs.nixosOptionsDoc {
options = eval.options; options = eval.options;
transformOptions = transformOptions = opt:
opt:
opt opt
// { // {
visible = opt.visible && !opt.internal; visible = opt.visible && !opt.internal;

View file

@ -1,11 +1,9 @@
self: self: {
{
lib, lib,
config, config,
pkgs, pkgs,
... ...
}: }: let
let
cfg = config.wayland.windowManager.mango; cfg = config.wayland.windowManager.mango;
selflib = import ./lib.nix lib; selflib = import ./lib.nix lib;
variables = lib.concatStringsSep " " cfg.systemd.variables; variables = lib.concatStringsSep " " cfg.systemd.variables;
@ -15,8 +13,7 @@ let
${lib.optionalString cfg.systemd.enable systemdActivation} ${lib.optionalString cfg.systemd.enable systemdActivation}
${cfg.autostart_sh} ${cfg.autostart_sh}
''; '';
in in {
{
options = { options = {
wayland.windowManager.mango = with lib; { wayland.windowManager.mango = with lib; {
enable = mkOption { enable = mkOption {
@ -80,9 +77,7 @@ in
''; '';
}; };
settings = mkOption { settings = mkOption {
type = type = with lib.types; let
with lib.types;
let
valueType = valueType =
nullOr (oneOf [ nullOr (oneOf [
bool bool
@ -217,14 +212,15 @@ in
finalConfigText = finalConfigText =
# Support old string-based config during transition period # Support old string-based config during transition period
( (
if builtins.isString cfg.settings then if builtins.isString cfg.settings
cfg.settings then cfg.settings
else else
lib.optionalString (cfg.settings != {}) ( lib.optionalString (cfg.settings != {}) (
selflib.toMango { selflib.toMango {
topCommandsPrefixes = cfg.topPrefixes; topCommandsPrefixes = cfg.topPrefixes;
bottomCommandsPrefixes = cfg.bottomPrefixes; bottomCommandsPrefixes = cfg.bottomPrefixes;
} cfg.settings }
cfg.settings
) )
) )
+ lib.optionalString (cfg.extraConfig != "") cfg.extraConfig + lib.optionalString (cfg.extraConfig != "") cfg.extraConfig
@ -234,8 +230,7 @@ in
cp ${pkgs.writeText "mango-config.conf" finalConfigText} "$out" cp ${pkgs.writeText "mango-config.conf" finalConfigText} "$out"
${cfg.package}/bin/mango -c "$out" -p || exit 1 ${cfg.package}/bin/mango -c "$out" -p || exit 1
''; '';
in in {
{
# Backwards compatibility warning for old string-based config # Backwards compatibility warning for old string-based config
warnings = lib.optional (builtins.isString cfg.settings) '' warnings = lib.optional (builtins.isString cfg.settings) ''
wayland.windowManager.mango.settings: Using a string for settings is deprecated. wayland.windowManager.mango.settings: Using a string for settings is deprecated.
@ -261,7 +256,8 @@ in
Description = "mango compositor session"; Description = "mango compositor session";
Documentation = ["man:systemd.special(7)"]; Documentation = ["man:systemd.special(7)"];
BindsTo = ["graphical-session.target"]; BindsTo = ["graphical-session.target"];
Wants = [ Wants =
[
"graphical-session-pre.target" "graphical-session-pre.target"
] ]
++ lib.optional cfg.systemd.xdgAutostart "xdg-desktop-autostart.target"; ++ lib.optional cfg.systemd.xdgAutostart "xdg-desktop-autostart.target";

View file

@ -1,6 +1,6 @@
lib: lib: let
let inherit
inherit (lib) (lib)
attrNames attrNames
filterAttrs filterAttrs
foldl foldl
@ -9,7 +9,8 @@ let
removeAttrs removeAttrs
; ;
inherit (lib.strings) inherit
(lib.strings)
concatMapStrings concatMapStrings
hasPrefix hasPrefix
; ;
@ -172,16 +173,11 @@ let
::: :::
*/ */
toMango = toMango = {
{
topCommandsPrefixes ? [], topCommandsPrefixes ? [],
bottomCommandsPrefixes ? [], bottomCommandsPrefixes ? [],
}: }: attrs: let
attrs: toMango' = attrs: let
let
toMango' =
attrs:
let
# Specially configured `toKeyValue` generator with support for duplicate keys # Specially configured `toKeyValue` generator with support for duplicate keys
# and a legible key-value separator. # and a legible key-value separator.
mkCommands = generators.toKeyValue { mkCommands = generators.toKeyValue {
@ -196,18 +192,14 @@ let
# Generate keymode blocks # Generate keymode blocks
# Format: keymode=name\nbind=...\nbind=...\n # Format: keymode=name\nbind=...\nbind=...\n
mkKeymodeBlock = mkKeymodeBlock = name: modeAttrs: let
name: modeAttrs:
let
modeCommands = flattenAttrs (p: k: "${p}_${k}") modeAttrs; modeCommands = flattenAttrs (p: k: "${p}_${k}") modeAttrs;
in in "keymode = ${name}\n${mkCommands modeCommands}";
"keymode = ${name}\n${mkCommands modeCommands}";
keymodeBlocks = keymodeBlocks =
if keymodes == { } then if keymodes == {}
"" then ""
else else "\n" + concatMapStrings (name: mkKeymodeBlock name keymodes.${name} + "\n") (attrNames keymodes);
"\n" + concatMapStrings (name: mkKeymodeBlock name keymodes.${name} + "\n") (attrNames keymodes);
# Flatten the attrset, combining keys in a "path" like `"a_b_c" = "x"`. # Flatten the attrset, combining keys in a "path" like `"a_b_c" = "x"`.
# Uses `flattenAttrs` with an underscore separator. # Uses `flattenAttrs` with an underscore separator.
@ -291,22 +283,25 @@ let
::: :::
*/ */
flattenAttrs = flattenAttrs = pred: attrs: let
pred: attrs: flattenAttrs' = prefix: attrs:
let
flattenAttrs' =
prefix: attrs:
builtins.foldl' ( builtins.foldl' (
acc: key: acc: key: let
let
value = attrs.${key}; value = attrs.${key};
newKey = if prefix == "" then key else pred prefix key; newKey =
if prefix == ""
then key
else pred prefix key;
in in
acc // (if builtins.isAttrs value then flattenAttrs' newKey value else { "${newKey}" = value; }) acc
// (
if builtins.isAttrs value
then flattenAttrs' newKey value
else {"${newKey}" = value;}
)
) {} (builtins.attrNames attrs); ) {} (builtins.attrNames attrs);
in in
flattenAttrs' "" attrs; flattenAttrs' "" attrs;
in in {
{
inherit flattenAttrs toMango; inherit flattenAttrs toMango;
} }

View file

@ -23,8 +23,7 @@ in {
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
environment.systemPackages = environment.systemPackages = [
[
cfg.package cfg.package
]; ];