feat: add flake support

This commit is contained in:
Ruixi-rebirth 2025-02-25 22:05:29 +08:00
parent 4d48679ccc
commit 1a55178fd6
No known key found for this signature in database
GPG key ID: 847E32F6F2F1D108
7 changed files with 308 additions and 0 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

@ -99,6 +99,67 @@ 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)

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
}

54
flake.nix Normal file
View file

@ -0,0 +1,54 @@
{
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 { };
shellOverride = old: {
nativeBuildInputs = old.nativeBuildInputs ++ [ ];
buildInputs = old.buildInputs ++ [ ];
};
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
in
{
packages.default = maomaowm;
overlayAttrs = {
inherit (config.packages) maomaowm;
};
packages = {
inherit maomaowm;
};
devShells.default = maomaowm.overrideAttrs shellOverride;
formatter = treefmtEval.config.build.wrapper;
};
systems = [ "x86_64-linux" ];
};
}

60
nix/default.nix Normal file
View file

@ -0,0 +1,60 @@
{
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 = ../.;
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.unix;
};
}

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

@ -0,0 +1,45 @@
{
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 = {
".config/maomao/config.conf" = {
text = config.wayland.windowManager.maomaowm.settings;
};
".config/maomao/autostart.sh" = {
text = config.wayland.windowManager.maomaowm.autostart_sh;
executable = true;
};
};
};
}

8
treefmt.nix Normal file
View file

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