mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-07-07 00:07:35 -04:00
refactor: format nix code with alejandra & rename nix files for clarity
This commit is contained in:
parent
24580afe56
commit
c0d7b0cf73
6 changed files with 298 additions and 311 deletions
10
flake.nix
10
flake.nix
|
|
@ -40,25 +40,25 @@
|
|||
system,
|
||||
}: let
|
||||
inherit (pkgs) callPackage;
|
||||
mango = callPackage ./nix {
|
||||
mango = callPackage ./nix/package.nix {
|
||||
inherit (scenefx.packages.${system}) scenefx;
|
||||
};
|
||||
in {
|
||||
inherit mango;
|
||||
default = mango;
|
||||
hm-options-json = callPackage (import ./nix/generate-options.nix self) {
|
||||
module = ./nix/hm-modules.nix;
|
||||
module = ./nix/hm-module.nix;
|
||||
optionPrefix = "wayland.windowManager.mango.";
|
||||
};
|
||||
nixos-options-json = callPackage (import ./nix/generate-options.nix self) {
|
||||
module = ./nix/nixos-modules.nix;
|
||||
module = ./nix/nixos-module.nix;
|
||||
optionPrefix = "programs.mango.";
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
nixosModules.mango = import ./nix/nixos-modules.nix self;
|
||||
hmModules.mango = import ./nix/hm-modules.nix self;
|
||||
nixosModules.mango = import ./nix/nixos-module.nix self;
|
||||
hmModules.mango = import ./nix/hm-module.nix self;
|
||||
|
||||
devShells = forEachSystem (
|
||||
{system, ...}: {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
self:
|
||||
{
|
||||
self: {
|
||||
pkgs,
|
||||
lib ? pkgs.lib,
|
||||
module,
|
||||
optionPrefix,
|
||||
}:
|
||||
let
|
||||
}: let
|
||||
# Absolute store path of the flake root, used to compute relative subpaths
|
||||
repoPath = toString self;
|
||||
|
||||
|
|
@ -28,8 +26,7 @@ let
|
|||
|
||||
optionsDoc = pkgs.nixosOptionsDoc {
|
||||
options = eval.options;
|
||||
transformOptions =
|
||||
opt:
|
||||
transformOptions = opt:
|
||||
opt
|
||||
// {
|
||||
visible = opt.visible && !opt.internal;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
self:
|
||||
{
|
||||
self: {
|
||||
lib,
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
}: let
|
||||
cfg = config.wayland.windowManager.mango;
|
||||
selflib = import ./lib.nix lib;
|
||||
variables = lib.concatStringsSep " " cfg.systemd.variables;
|
||||
|
|
@ -15,8 +13,7 @@ let
|
|||
${lib.optionalString cfg.systemd.enable systemdActivation}
|
||||
${cfg.autostart_sh}
|
||||
'';
|
||||
in
|
||||
{
|
||||
in {
|
||||
options = {
|
||||
wayland.windowManager.mango = with lib; {
|
||||
enable = mkOption {
|
||||
|
|
@ -80,9 +77,7 @@ in
|
|||
'';
|
||||
};
|
||||
settings = mkOption {
|
||||
type =
|
||||
with lib.types;
|
||||
let
|
||||
type = with lib.types; let
|
||||
valueType =
|
||||
nullOr (oneOf [
|
||||
bool
|
||||
|
|
@ -217,14 +212,15 @@ in
|
|||
finalConfigText =
|
||||
# Support old string-based config during transition period
|
||||
(
|
||||
if builtins.isString cfg.settings then
|
||||
cfg.settings
|
||||
if builtins.isString cfg.settings
|
||||
then cfg.settings
|
||||
else
|
||||
lib.optionalString (cfg.settings != {}) (
|
||||
selflib.toMango {
|
||||
topCommandsPrefixes = cfg.topPrefixes;
|
||||
bottomCommandsPrefixes = cfg.bottomPrefixes;
|
||||
} cfg.settings
|
||||
}
|
||||
cfg.settings
|
||||
)
|
||||
)
|
||||
+ lib.optionalString (cfg.extraConfig != "") cfg.extraConfig
|
||||
|
|
@ -234,8 +230,7 @@ in
|
|||
cp ${pkgs.writeText "mango-config.conf" finalConfigText} "$out"
|
||||
${cfg.package}/bin/mango -c "$out" -p || exit 1
|
||||
'';
|
||||
in
|
||||
{
|
||||
in {
|
||||
# Backwards compatibility warning for old string-based config
|
||||
warnings = lib.optional (builtins.isString cfg.settings) ''
|
||||
wayland.windowManager.mango.settings: Using a string for settings is deprecated.
|
||||
|
|
@ -261,7 +256,8 @@ in
|
|||
Description = "mango compositor session";
|
||||
Documentation = ["man:systemd.special(7)"];
|
||||
BindsTo = ["graphical-session.target"];
|
||||
Wants = [
|
||||
Wants =
|
||||
[
|
||||
"graphical-session-pre.target"
|
||||
]
|
||||
++ lib.optional cfg.systemd.xdgAutostart "xdg-desktop-autostart.target";
|
||||
59
nix/lib.nix
59
nix/lib.nix
|
|
@ -1,6 +1,6 @@
|
|||
lib:
|
||||
let
|
||||
inherit (lib)
|
||||
lib: let
|
||||
inherit
|
||||
(lib)
|
||||
attrNames
|
||||
filterAttrs
|
||||
foldl
|
||||
|
|
@ -9,7 +9,8 @@ let
|
|||
removeAttrs
|
||||
;
|
||||
|
||||
inherit (lib.strings)
|
||||
inherit
|
||||
(lib.strings)
|
||||
concatMapStrings
|
||||
hasPrefix
|
||||
;
|
||||
|
|
@ -172,16 +173,11 @@ let
|
|||
|
||||
:::
|
||||
*/
|
||||
toMango =
|
||||
{
|
||||
toMango = {
|
||||
topCommandsPrefixes ? [],
|
||||
bottomCommandsPrefixes ? [],
|
||||
}:
|
||||
attrs:
|
||||
let
|
||||
toMango' =
|
||||
attrs:
|
||||
let
|
||||
}: attrs: let
|
||||
toMango' = attrs: let
|
||||
# Specially configured `toKeyValue` generator with support for duplicate keys
|
||||
# and a legible key-value separator.
|
||||
mkCommands = generators.toKeyValue {
|
||||
|
|
@ -196,18 +192,14 @@ let
|
|||
|
||||
# Generate keymode blocks
|
||||
# Format: keymode=name\nbind=...\nbind=...\n
|
||||
mkKeymodeBlock =
|
||||
name: modeAttrs:
|
||||
let
|
||||
mkKeymodeBlock = name: modeAttrs: let
|
||||
modeCommands = flattenAttrs (p: k: "${p}_${k}") modeAttrs;
|
||||
in
|
||||
"keymode = ${name}\n${mkCommands modeCommands}";
|
||||
in "keymode = ${name}\n${mkCommands modeCommands}";
|
||||
|
||||
keymodeBlocks =
|
||||
if keymodes == { } then
|
||||
""
|
||||
else
|
||||
"\n" + concatMapStrings (name: mkKeymodeBlock name keymodes.${name} + "\n") (attrNames keymodes);
|
||||
if keymodes == {}
|
||||
then ""
|
||||
else "\n" + concatMapStrings (name: mkKeymodeBlock name keymodes.${name} + "\n") (attrNames keymodes);
|
||||
|
||||
# Flatten the attrset, combining keys in a "path" like `"a_b_c" = "x"`.
|
||||
# Uses `flattenAttrs` with an underscore separator.
|
||||
|
|
@ -291,22 +283,25 @@ let
|
|||
|
||||
:::
|
||||
*/
|
||||
flattenAttrs =
|
||||
pred: attrs:
|
||||
let
|
||||
flattenAttrs' =
|
||||
prefix: attrs:
|
||||
flattenAttrs = pred: attrs: let
|
||||
flattenAttrs' = prefix: attrs:
|
||||
builtins.foldl' (
|
||||
acc: key:
|
||||
let
|
||||
acc: key: let
|
||||
value = attrs.${key};
|
||||
newKey = if prefix == "" then key else pred prefix key;
|
||||
newKey =
|
||||
if prefix == ""
|
||||
then key
|
||||
else pred prefix key;
|
||||
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);
|
||||
in
|
||||
flattenAttrs' "" attrs;
|
||||
in
|
||||
{
|
||||
in {
|
||||
inherit flattenAttrs toMango;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,8 +23,7 @@ in {
|
|||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
environment.systemPackages =
|
||||
[
|
||||
environment.systemPackages = [
|
||||
cfg.package
|
||||
];
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue