feat: add flake support

This commit is contained in:
Ruixi-rebirth 2025-02-24 23:30:14 +08:00
parent fb990c196d
commit c983ac8a44
No known key found for this signature in database
GPG key ID: 847E32F6F2F1D108
8 changed files with 362 additions and 7 deletions

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
/.cache /.cache
/.vscode /.vscode
/result
config.h config.h
maomao maomao
maomao.o maomao.o

View file

@ -1,5 +1,5 @@
# #
Master-Stack Layout Master-Stack Layout
@ -18,7 +18,7 @@ https://github.com/user-attachments/assets/c9bf9415-fad1-4400-bcdc-3ad2d76de85a
# Maomaowm # Maomaowm
This project is developed based on `dwl(0.5)` , This project is developed based on `dwl(0.5)` ,
adding many operation that supported in hyprland and a hyprland-like keybinds, adding many operation that supported in hyprland and a hyprland-like keybinds,
niri-like scroll layout and sway-like scratchpad. niri-like scroll layout and sway-like scratchpad.
See below for more features. See below for more features.
@ -34,10 +34,10 @@ See below for more features.
# window open rules # window open rules
## options ## options
- appid: type-string if match it or title, the rule match - appid: type-string if match it or title, the rule match
- title: type-string if match it or appid, the rule match - title: type-string if match it or appid, the rule match
- tags: type-num(1-9) which tags to open the window - tags: type-num(1-9) which tags to open the window
- isfloating: type-num(0 or 1) - isfloating: type-num(0 or 1)
- isfullscreen: type-num(0 or 1) - isfullscreen: type-num(0 or 1)
- scroller_proportion: type-float(0.1-1.0) - scroller_proportion: type-float(0.1-1.0)
- animation_type : type-string(zoom,slide) - animation_type : type-string(zoom,slide)
@ -66,7 +66,7 @@ yay -S rofi foot xdg-desktop-portal-wlr swaybg waybar wl-clip-persist cliphist w
``` ```
# install # install
# wlroots(0.17) # wlroots(0.17)
``` ```
git clone -b 0.17.4 https://gitlab.freedesktop.org/wlroots/wlroots.git git clone -b 0.17.4 https://gitlab.freedesktop.org/wlroots/wlroots.git
@ -99,10 +99,71 @@ like `MAOMAOCONFIG=/home/xxx/maomao`
- the fallback config path is in `/etc/maomao/config.conf`, you can find the default config here - the fallback config path is in `/etc/maomao/config.conf`, you can find the default config here
# NixOS+Home-manager
```nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-parts.url = "github:hercules-ci/flake-parts";
maomaowm.url = "github:DreamMaoMao/maomaowm";
};
outputs =
inputs@{ self, flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
debug = true;
systems = [ "x86_64-linux" ];
flake = {
nixosConfigurations = {
hostname = inputs.nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
inputs.home-manager.nixosModules.home-manager
{
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
backupFileExtension = "backup";
users."username".imports =
[
(
{ ... }:
{
wayland.windowManager.maomaowm = {
enable = true;
settings = ''
# see config.conf
'';
autostart_sh = ''
# see autostart.sh
'';
};
}
)
]
++ [
# Add maomaowm hm module
inputs.maomaowm.hmModules.maomaowm
];
};
}
];
};
};
};
};
}
```
# my dotfile # my dotfile
[maomao-config](https://github.com/DreamMaoMao/dotfile/tree/main/maomao) [maomao-config](https://github.com/DreamMaoMao/dotfile/tree/main/maomao)
# thanks for some refer repo # thanks for some refer repo
- https://github.com/dqrk0jeste/owl - for basal window animaition - https://github.com/dqrk0jeste/owl - for basal window animaition
- https://github.com/djpohly/dwl - for basal dwl feature - https://github.com/djpohly/dwl - for basal dwl feature

79
flake.lock generated Normal file
View file

@ -0,0 +1,79 @@
{
"nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1738453229,
"narHash": "sha256-7H9XgNiGLKN1G1CgRh0vUL4AheZSYzPm+zmZ7vxbJdo=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "32ea77a06711b758da0ad9bd6a844c5740a87abd",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1740019556,
"narHash": "sha256-vn285HxnnlHLWnv59Og7muqECNMS33mWLM14soFIv2g=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "dad564433178067be1fbdfcce23b546254b6d641",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1738452942,
"narHash": "sha256-vJzFZGaCpnmo7I6i416HaBLpC+hvcURh/BQwROcGIp8=",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/072a6db25e947df2f31aab9eccd0ab75d5b2da11.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/072a6db25e947df2f31aab9eccd0ab75d5b2da11.tar.gz"
}
},
"root": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs",
"treefmt-nix": "treefmt-nix"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1739829690,
"narHash": "sha256-mL1szCeIsjh6Khn3nH2cYtwO5YXG6gBiTw1A30iGeDU=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "3d0579f5cc93436052d94b73925b48973a104204",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

50
flake.nix Normal file
View file

@ -0,0 +1,50 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
flake-parts,
treefmt-nix,
...
}@inputs:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.flake-parts.flakeModules.easyOverlay
];
flake.hmModules.maomaowm = import ./nix/hm-modules.nix;
perSystem =
{
config,
pkgs,
...
}:
let
inherit (pkgs)
callPackage
;
maomaowm = callPackage ./nix { };
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
in
{
packages.default = maomaowm;
overlayAttrs = {
inherit (config.packages) maomaowm;
};
packages = {
inherit maomaowm;
};
formatter = treefmtEval.config.build.wrapper;
};
systems = [ "x86_64-linux" ];
};
}

64
nix/default.nix Normal file
View file

@ -0,0 +1,64 @@
{
lib,
libX11,
libinput,
libxcb,
libxkbcommon,
pixman,
pkg-config,
stdenv,
wayland,
wayland-protocols,
wayland-scanner,
wlroots_0_17,
xcbutilwm,
xwayland,
enableXWayland ? true,
meson,
ninja,
}:
let
pname = "maomaowm";
in
stdenv.mkDerivation {
inherit pname;
version = "nightly";
src = ../.;
patches = [
./install-config-to-etc.patch
];
nativeBuildInputs = [
meson
ninja
pkg-config
wayland-scanner
];
buildInputs =
[
libinput
libxcb
libxkbcommon
pixman
wayland
wayland-protocols
wlroots_0_17
]
++ lib.optionals enableXWayland [
libX11
xcbutilwm
xwayland
];
meta = {
mainProgram = "maomao";
description = "A streamlined but feature-rich Wayland compositor";
homepage = "https://github.com/DreamMaoMao/maomaowm";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ ];
platforms = lib.platforms.linux;
};
}

47
nix/hm-modules.nix Normal file
View file

@ -0,0 +1,47 @@
{
lib,
config,
pkgs,
...
}:
let
maomaowm = pkgs.callPackage ./. { };
in
{
options = {
wayland.windowManager.maomaowm = {
enable = lib.mkOption {
type = lib.types.bool;
default = false;
};
settings = lib.mkOption {
type = lib.types.str;
default = "";
};
autostart_sh = lib.mkOption {
type = lib.types.str;
default = "";
};
};
};
config = lib.mkIf config.wayland.windowManager.maomaowm.enable {
home.packages = [ maomaowm ];
home.file =
lib.optionalAttrs (config.wayland.windowManager.maomaowm.settings != "") {
".config/maomao/config.conf" = {
text = config.wayland.windowManager.maomaowm.settings;
};
}
// lib.optionalAttrs (config.wayland.windowManager.maomaowm.autostart_sh != "") {
".config/maomao/autostart.sh" = {
text = config.wayland.windowManager.maomaowm.autostart_sh;
executable = true;
};
};
};
}

View file

@ -0,0 +1,45 @@
diff --git a/meson.build b/meson.build
index eeec918..e0de85a 100644
--- a/meson.build
+++ b/meson.build
@@ -4,6 +4,10 @@ project('maomao', ['c', 'cpp'],
subdir('protocols')
+sysconfdir = get_option('sysconfdir')
+prefix = get_option('prefix')
+add_project_arguments('-DSYSCONFDIR="/@0@"'.format(join_paths(prefix, sysconfdir)), language : 'c')
+
# fs = import('fs')
#
# # 获取用户的主目录
@@ -68,8 +72,7 @@ executable('maomao',
c_args : c_args
)
-prefix = get_option('prefix')
desktop_install_dir = join_paths(prefix, 'share/wayland-sessions')
install_data('maomao.desktop', install_dir : desktop_install_dir)
-install_data('config.conf', install_dir : '/etc/maomao')
+install_data('config.conf', install_dir : join_paths(sysconfdir, 'maomao'))
diff --git a/parse_config.h b/parse_config.h
index 395251d..e241f00 100644
--- a/parse_config.h
+++ b/parse_config.h
@@ -1024,7 +1024,7 @@ void parse_config(void) {
// 检查文件是否存在
if (access(filename, F_OK) != 0) {
// 如果文件不存在,则使用 /etc/maomao/config.conf
- snprintf(filename, sizeof(filename), "/etc/maomao/config.conf");
+ snprintf(filename, sizeof(filename), "%s/maomao/config.conf", SYSCONFDIR);
}
} else {
// 使用 MAOMAOCONFIG 环境变量作为配置文件夹路径
@@ -1049,4 +1049,4 @@ void reload_config(const Arg *arg) {
}
}
arrange(selmon, false);
-}
\ No newline at end of file
+}

8
treefmt.nix Normal file
View file

@ -0,0 +1,8 @@
{ ... }:
{
projectRootFile = "flake.nix";
programs = {
nixfmt.enable = true;
};
}