From e34953f595eeb0a18159a569e1a1bc263f1df2c3 Mon Sep 17 00:00:00 2001 From: Davi Ribeiro <104164579+Markus328@users.noreply.github.com> Date: Tue, 12 Aug 2025 12:06:24 -0300 Subject: nix: add home manager module (#402) * nix/hm: add home manager module * nix/hm: remove uneeded options * nix/hm: add cli option * nix/hm: allow shell use CLI when 'cli.enable' is false * nix/hm: fix systemd service * nix/hm: use config dir from xdg standard --- default.nix | 101 ------------------------------------------------------ flake.nix | 4 ++- nix/default.nix | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ nix/hm-module.nix | 82 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 186 insertions(+), 102 deletions(-) delete mode 100644 default.nix create mode 100644 nix/default.nix create mode 100644 nix/hm-module.nix diff --git a/default.nix b/default.nix deleted file mode 100644 index 25902d2..0000000 --- a/default.nix +++ /dev/null @@ -1,101 +0,0 @@ -{ - rev, - lib, - stdenv, - makeWrapper, - makeFontsConf, - fish, - ddcutil, - brightnessctl, - app2unit, - cava, - networkmanager, - lm_sensors, - grim, - swappy, - wl-clipboard, - libqalculate, - inotify-tools, - bluez, - bash, - hyprland, - coreutils, - findutils, - file, - material-symbols, - rubik, - nerd-fonts, - gcc, - quickshell, - aubio, - pipewire, - caelestia-cli, - withCli ? false, -}: let - runtimeDeps = - [ - fish - ddcutil - brightnessctl - app2unit - cava - networkmanager - lm_sensors - grim - swappy - wl-clipboard - libqalculate - inotify-tools - bluez - bash - hyprland - coreutils - findutils - file - ] - ++ lib.optional withCli caelestia-cli; - - fontconfig = makeFontsConf { - fontDirectories = [material-symbols rubik nerd-fonts.caskaydia-cove]; - }; -in - stdenv.mkDerivation { - pname = "caelestia-shell"; - version = "${rev}"; - src = ./.; - - nativeBuildInputs = [gcc makeWrapper]; - buildInputs = [quickshell aubio pipewire]; - propagatedBuildInputs = runtimeDeps; - - buildPhase = '' - mkdir -p bin - g++ -std=c++17 -Wall -Wextra \ - -I${pipewire.dev}/include/pipewire-0.3 \ - -I${pipewire.dev}/include/spa-0.2 \ - -I${aubio}/include/aubio \ - assets/beat_detector.cpp \ - -o bin/beat_detector \ - -lpipewire-0.3 -laubio - ''; - - installPhase = '' - install -Dm755 bin/beat_detector $out/bin/beat_detector - - mkdir -p $out/share/caelestia-shell - cp -r ./* $out/share/caelestia-shell - - makeWrapper ${quickshell}/bin/qs $out/bin/caelestia-shell \ - --prefix PATH : "${lib.makeBinPath runtimeDeps}" \ - --set FONTCONFIG_FILE "${fontconfig}" \ - --set CAELESTIA_BD_PATH $out/bin/beat_detector \ - --add-flags "-p $out/share/caelestia-shell" - ''; - - meta = { - description = "A very segsy desktop shell"; - homepage = "https://github.com/caelestia-dots/shell"; - license = lib.licenses.gpl3Only; - mainProgram = "caelestia-shell"; - }; - } diff --git a/flake.nix b/flake.nix index 380c009..7af96cc 100644 --- a/flake.nix +++ b/flake.nix @@ -29,7 +29,7 @@ formatter = forAllSystems (pkgs: pkgs.alejandra); packages = forAllSystems (pkgs: rec { - caelestia-shell = pkgs.callPackage ./default.nix { + caelestia-shell = pkgs.callPackage ./nix { rev = self.rev or self.dirtyRev; quickshell = inputs.quickshell.packages.${pkgs.system}.default.override { withX11 = false; @@ -51,5 +51,7 @@ CAELESTIA_BD_PATH = "${shell}/bin/beat_detector"; }; }); + + homeManagerModules.default = import ./nix/hm-module.nix self; }; } diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..8012721 --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,101 @@ +{ + rev, + lib, + stdenv, + makeWrapper, + makeFontsConf, + fish, + ddcutil, + brightnessctl, + app2unit, + cava, + networkmanager, + lm_sensors, + grim, + swappy, + wl-clipboard, + libqalculate, + inotify-tools, + bluez, + bash, + hyprland, + coreutils, + findutils, + file, + material-symbols, + rubik, + nerd-fonts, + gcc, + quickshell, + aubio, + pipewire, + caelestia-cli, + withCli ? false, +}: let + runtimeDeps = + [ + fish + ddcutil + brightnessctl + app2unit + cava + networkmanager + lm_sensors + grim + swappy + wl-clipboard + libqalculate + inotify-tools + bluez + bash + hyprland + coreutils + findutils + file + ] + ++ lib.optional withCli caelestia-cli; + + fontconfig = makeFontsConf { + fontDirectories = [material-symbols rubik nerd-fonts.caskaydia-cove]; + }; +in + stdenv.mkDerivation { + pname = "caelestia-shell"; + version = "${rev}"; + src = ./..; + + nativeBuildInputs = [gcc makeWrapper]; + buildInputs = [quickshell aubio pipewire]; + propagatedBuildInputs = runtimeDeps; + + buildPhase = '' + mkdir -p bin + g++ -std=c++17 -Wall -Wextra \ + -I${pipewire.dev}/include/pipewire-0.3 \ + -I${pipewire.dev}/include/spa-0.2 \ + -I${aubio}/include/aubio \ + assets/beat_detector.cpp \ + -o bin/beat_detector \ + -lpipewire-0.3 -laubio + ''; + + installPhase = '' + install -Dm755 bin/beat_detector $out/bin/beat_detector + + mkdir -p $out/share/caelestia-shell + cp -r ./* $out/share/caelestia-shell + + makeWrapper ${quickshell}/bin/qs $out/bin/caelestia-shell \ + --prefix PATH : "${lib.makeBinPath runtimeDeps}" \ + --set FONTCONFIG_FILE "${fontconfig}" \ + --set CAELESTIA_BD_PATH $out/bin/beat_detector \ + --add-flags "-p $out/share/caelestia-shell" + ''; + + meta = { + description = "A very segsy desktop shell"; + homepage = "https://github.com/caelestia-dots/shell"; + license = lib.licenses.gpl3Only; + mainProgram = "caelestia-shell"; + }; + } diff --git a/nix/hm-module.nix b/nix/hm-module.nix new file mode 100644 index 0000000..631ee4a --- /dev/null +++ b/nix/hm-module.nix @@ -0,0 +1,82 @@ +self: { + config, + pkgs, + lib, + ... +}: let + cli-default = self.inputs.caelestia-cli.packages.${pkgs.system}.default; + shell-default = self.packages.${pkgs.system}.with-cli; + + cfg = config.programs.caelestia; +in { + options = with lib; { + programs.caelestia = { + enable = mkEnableOption "Enable Caelestia shell"; + package = mkOption { + type = types.package; + default = shell-default; + description = "The package of Caelestia shell"; + }; + settings = mkOption { + type = types.attrs; + default = {}; + description = "Caelestia shell settings"; + }; + extraConfig = mkOption { + type = types.str; + default = ""; + description = "Caelestia shell extra configs written to shell.json"; + }; + cli = { + enable = mkEnableOption "Enable Caelestia CLI"; + package = mkOption { + type = types.package; + default = cli-default; + description = "The package of Caelestia CLI"; # Doesn't override the shell's CLI, only change from home.packages + }; + }; + }; + }; + + config = let + cli = cfg.cli.package or cli-default; + shell = cfg.package or shell-default; + in + lib.mkIf cfg.enable { + systemd.user.services.caelestia = { + Unit = { + Description = "Caelestia Shell Service"; + After = ["graphical-session.target"]; + PartOf = ["graphical-session.target"]; + }; + + Service = { + Type = "exec"; + ExecStart = "${shell}/bin/caelestia-shell"; + Restart = "on-failure"; + RestartSec = "5s"; + TimeoutStopSec = "5s"; + Environment = [ + "QT_QPA_PLATFORM=wayland" + ]; + + Slice = "session.slice"; + }; + + Install = { + WantedBy = ["graphical-session.target"]; + }; + }; + + xdg.configFile."caelestia/shell.json".text = let + extraConfig = + if cfg.extraConfig != "" + then cfg.extraConfig + else "{}"; + in + builtins.toJSON (lib.recursiveUpdate + (cfg.settings or {}) (builtins.fromJSON extraConfig)); + + home.packages = [shell] ++ lib.optional cfg.cli.enable cli; + }; +} -- cgit v1.2.3-freya