This commit is contained in:
pengo 2026-06-16 15:14:09 +02:00 committed by GitHub
commit 74b49cd346
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": { "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": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1778274207, "lastModified": 1778274207,
@ -34,24 +16,8 @@
"type": "github" "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": { "root": {
"inputs": { "inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"scenefx": "scenefx" "scenefx": "scenefx"
} }

112
flake.nix
View file

@ -1,7 +1,6 @@
{ {
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
scenefx = { scenefx = {
url = "github:wlrfx/scenefx"; url = "github:wlrfx/scenefx";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
@ -10,54 +9,77 @@
outputs = { outputs = {
self, self,
flake-parts, nixpkgs,
... scenefx,
} @ 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,
...
}: let }: let
inherit (pkgs) callPackage ; inherit (nixpkgs.lib) genAttrs;
mango = callPackage ./nix { inherit (nixpkgs.lib.modules) importApply;
inherit (inputs.scenefx.packages.${pkgs.stdenv.hostPlatform.system}) scenefx;
}; # Systems mangowm supports. Options that call `forEachSystem` will generate an attribute for each of these options.
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;
};
systems = [ systems = [
"x86_64-linux" "x86_64-linux"
"aarch64-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, 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;
eval = lib.evalModules { eval = lib.evalModules {
modules = [ modules = [
(import module self) (import module self.packages.${pkgs.stdenv.hostPlatform.system}.default)
{_module.check = false;} {_module.check = false;}
]; ];
specialArgs = {inherit pkgs;}; specialArgs = {inherit pkgs;};
@ -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: mangoPackage: {
{
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 {
@ -26,7 +23,7 @@ in
}; };
package = lib.mkOption { package = lib.mkOption {
type = lib.types.package; type = lib.types.package;
default = self.packages.${pkgs.stdenv.hostPlatform.system}.mango; default = mangoPackage;
description = "The mango package to use"; description = "The mango package to use";
}; };
systemd = { systemd = {
@ -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

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