diff --git a/.gitignore b/.gitignore index 693ec29..f09b303 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /.cache /.vscode +/result config.h maomao maomao.o diff --git a/README.md b/README.md index 4cc3fb3..9951a59 100644 --- a/README.md +++ b/README.md @@ -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 +# 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 [maomao-config](https://github.com/DreamMaoMao/dotfile/tree/main/maomao) diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..620452f --- /dev/null +++ b/flake.lock @@ -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 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..866bb7f --- /dev/null +++ b/flake.nix @@ -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" ]; + }; +} diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..8cca30b --- /dev/null +++ b/nix/default.nix @@ -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; + }; +} diff --git a/nix/hm-modules.nix b/nix/hm-modules.nix new file mode 100644 index 0000000..30996fe --- /dev/null +++ b/nix/hm-modules.nix @@ -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; + }; + }; + }; +} diff --git a/treefmt.nix b/treefmt.nix new file mode 100644 index 0000000..e61ce2d --- /dev/null +++ b/treefmt.nix @@ -0,0 +1,8 @@ +{ ... }: + +{ + projectRootFile = "flake.nix"; + programs = { + nixfmt.enable = true; + }; +}