This commit is contained in:
pengo 2026-06-28 05:54:35 +00:00 committed by GitHub
commit e6b05b9b0d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 386 additions and 385 deletions

26
default.nix Normal file
View file

@ -0,0 +1,26 @@
let
inherit (builtins) fromJSON readFile;
lock = fromJSON (readFile ./flake.lock);
node = lock.nodes.${lock.nodes.root.inputs.nixpkgs}.locked;
nixpkgs = fetchTarball {
url = with node; "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
sha256 = node.narHash;
};
in
{pkgs ? import nixpkgs {}}: let
inherit (pkgs) callPackage;
inherit (pkgs.lib.modules) importApply;
package = callPackage ./nix/package.nix {};
in {
overlay = final: prev: {
mango = package;
};
inherit package;
nixosModule = importApply ./nix/nixos-module.nix package;
hmModule = importApply ./nix/hm-module.nix package;
}

34
flake.lock generated
View file

@ -1,23 +1,5 @@
{
"nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1749398372,
"narHash": "sha256-tYBdgS56eXYaWVW3fsnPQ/nFlgWi/Z2Ymhyu21zVM98=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "9305fe4e5c2a6fcf5ba6a3ff155720fbe4076569",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1778274207,
@ -34,24 +16,8 @@
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1748740939,
"narHash": "sha256-rQaysilft1aVMwF14xIdGS3sj1yHlI6oKQNBRTF40cc=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "656a64127e9d791a334452c6b6606d17539476e2",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"root": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs",
"scenefx": "scenefx"
}

112
flake.nix
View file

@ -1,7 +1,6 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
scenefx = {
url = "github:wlrfx/scenefx";
inputs.nixpkgs.follows = "nixpkgs";
@ -10,54 +9,77 @@
outputs = {
self,
flake-parts,
...
} @ inputs:
flake-parts.lib.mkFlake {inherit inputs;} {
imports = [
inputs.flake-parts.flakeModules.easyOverlay
];
flake = {
hmModules.mango = import ./nix/hm-modules.nix self;
nixosModules.mango = import ./nix/nixos-modules.nix self;
};
perSystem = {
config,
pkgs,
...
nixpkgs,
scenefx,
}: let
inherit (pkgs) callPackage ;
mango = callPackage ./nix {
inherit (inputs.scenefx.packages.${pkgs.stdenv.hostPlatform.system}) scenefx;
};
shellOverride = old: {
nativeBuildInputs = old.nativeBuildInputs ++ [];
buildInputs = old.buildInputs ++ [];
};
in {
packages.default = mango;
overlayAttrs = {
inherit (config.packages) mango;
};
packages = {
inherit mango;
hm-options-json = pkgs.callPackage (import ./nix/generate-options.nix self) {
module = ./nix/hm-modules.nix;
optionPrefix = "wayland.windowManager.mango.";
};
nixos-options-json = pkgs.callPackage (import ./nix/generate-options.nix self) {
module = ./nix/nixos-modules.nix;
optionPrefix = "programs.mango.";
};
};
devShells.default = mango.overrideAttrs shellOverride;
formatter = pkgs.alejandra;
};
inherit (nixpkgs.lib) genAttrs;
inherit (nixpkgs.lib.modules) importApply;
# Systems mangowm supports. Options that call `forEachSystem` will generate an attribute for each of these options.
systems = [
"x86_64-linux"
"aarch64-linux"
];
# Helper function that generates an attribute set by calling the provided `perSystem` function for each system in `systems` defined above.
forEachSystem = perSystem:
genAttrs systems (
system:
perSystem {
inherit system;
pkgs = nixpkgs.legacyPackages.${system};
}
);
in {
overlays.default = final: prev: {
inherit (self.packages.${final.stdenv.hostPlatform.system}) mango;
};
packages = forEachSystem (
{
pkgs,
system,
}: let
inherit (pkgs) callPackage;
mango = callPackage ./nix/package.nix {
inherit (scenefx.packages.${system}) scenefx;
};
generateOptions = callPackage (import ./nix/generate-options.nix self);
in {
inherit mango;
default = mango;
hm-options-json = generateOptions {
module = ./nix/hm-module.nix;
optionPrefix = "wayland.windowManager.mango.";
};
nixos-options-json = generateOptions {
module = ./nix/nixos-module.nix;
optionPrefix = "programs.mango.";
};
}
);
nixosModules.mango = {pkgs, ...}: {
imports = [
(importApply ./nix/nixos-module.nix self.packages.${pkgs.stdenv.hostPlatform.system}.default)
];
};
hmModules.mango = {pkgs, ...}: {
imports = [
(importApply ./nix/hm-module.nix self.packages.${pkgs.stdenv.hostPlatform.system}.default)
];
};
devShells = forEachSystem (
{system, ...}: {
default = self.packages.${system}.mango;
}
);
formatter = forEachSystem (
{pkgs, ...}: pkgs.alejandra
);
};
}

View file

@ -1,17 +1,15 @@
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;
eval = lib.evalModules {
modules = [
(import module self)
(import module self.packages.${pkgs.stdenv.hostPlatform.system}.default)
{_module.check = false;}
];
specialArgs = {inherit pkgs;};
@ -28,8 +26,7 @@ let
optionsDoc = pkgs.nixosOptionsDoc {
options = eval.options;
transformOptions =
opt:
transformOptions = opt:
opt
// {
visible = opt.visible && !opt.internal;

View file

@ -1,11 +1,9 @@
self:
{
mangoPackage: {
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 {
@ -26,7 +23,7 @@ in
};
package = lib.mkOption {
type = lib.types.package;
default = self.packages.${pkgs.stdenv.hostPlatform.system}.mango;
default = mangoPackage;
description = "The mango package to use";
};
systemd = {
@ -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";

View file

@ -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;
}

View file

@ -1,4 +1,4 @@
self: {
mangoPackage: {
config,
lib,
pkgs,
@ -16,15 +16,14 @@ in {
};
package = lib.mkOption {
type = lib.types.package;
default = self.packages.${pkgs.stdenv.hostPlatform.system}.mango;
default = mangoPackage;
description = "The mango package to use";
};
};
};
config = lib.mkIf cfg.enable {
environment.systemPackages =
[
environment.systemPackages = [
cfg.package
];