Skip to content

Commit

Permalink
nixos/uwsm: init module, temporarily import the package derivation here
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRTitor committed Jul 26, 2024
1 parent a81caa3 commit 7de078c
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 0 deletions.
4 changes: 4 additions & 0 deletions modules-overlays/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
}: {
imports = [
#./amdgpu.nix # import modules here to test
./uwsm/module.nix
];

nixpkgs.overlays = [
(final: prev: {
# bcachefs-tools = inputs.bcachefs-tools.packages.${pkgs.system}.bcachefs-tools;
})
];

programs.uwsm.enable = true;
programs.uwsm.package = pkgs.callPackage ./uwsm/package.nix { };
}
62 changes: 62 additions & 0 deletions modules-overlays/uwsm/module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
config,
lib,
pkgs,
...
}:
let
cfg = config.programs.uwsm;
hyprlandCfg = config.programs.hyprland;
swayCfg = config.programs.sway;
in
{
options.programs.uwsm = {
enable = lib.mkEnableOption ''uwsm, which wraps standalone
Wayland compositors into a set of Systemd units on the fly
'';
package = lib.mkPackageOption pkgs "uwsm" {};
hyprlandSupport = lib.mkEnableOption null // {
default = cfg.enable && hyprlandCfg.enable;
};
swaySupport = lib.mkEnableOption null // {
default = cfg.enable && swayCfg.enable;
};

finalPackage = lib.mkOption {
type = lib.types.package;
readOnly = true;
default = cfg.package.override {
hyprland = hyprlandCfg.package;
sway = swayCfg.package;
inherit (cfg) hyprlandSupport swaySupport;
};
defaultText = lib.literalExpression
"`programs.uwsm.package` with applied configuration";
description = ''
The uwsm package after applying configuration.
'';
};
};

config = lib.mkIf cfg.enable {
environment.systemPackages = [ cfg.finalPackage ];
systemd.packages = [ cfg.finalPackage ];
services.dbus.implementation = "broker";

services.displayManager.sessionPackages = lib.optionals cfg.hyprlandSupport [
(pkgs.callPackage ./uwsm-wm-wrapper.nix {
uwsm = cfg.finalPackage;
wmName = "Hyprland";
wmCmd = "hyprland";
})
] ++ lib.optionals cfg.swaySupport [
(pkgs.callPackage ./uwsm-wm-wrapper.nix {
uwsm = cfg.finalPackage;
wmName = "Sway";
wmCmd = "sway";
})
];
};

meta.maintainers = with lib.maintainers; [ johnrtitor ];
}
99 changes: 99 additions & 0 deletions modules-overlays/uwsm/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
stdenv,
lib,
fetchFromGitHub,
makeBinaryWrapper,
meson,
ninja,
scdoc,
pkg-config,
nix-update-script,
bash,
dmenu,
libnotify,
newt,
python3Packages,
util-linux,
fumonSupport ? true,
uuctlSupport ? true,
uwsmAppSupport ? true,
hyprlandSupport ? false,
swaySupport ? false,
hyprland,
sway,
}:
let
python = python3Packages.python.withPackages (ps: [
ps.pydbus
ps.dbus-python
ps.pyxdg
]);
in
stdenv.mkDerivation (finalAttrs: {
pname = "uwsm";
version = "0.17.0";

src = fetchFromGitHub {
owner = "Vladimir-csp";
repo = "uwsm";
rev = "refs/tags/v${finalAttrs.version}";
hash = "sha256-M2j7l5XTSS2IzaJofAHct1tuAO2A9Ps9mCgAWKEvzoE=";
};

patches = [ ./uwsm-path.patch ];

nativeBuildInputs = [
makeBinaryWrapper
meson
ninja
pkg-config
scdoc
];

propagatedBuildInputs = [
util-linux # waitpid
newt # whiptail
dmenu # for uuctl
libnotify # notify
bash # sh
python
];

mesonFlags = [
"--prefix=${placeholder "out"}"
(lib.mapAttrsToList lib.mesonEnable {
"uwsm-app" = uwsmAppSupport;
"fumon" = fumonSupport;
"uuctl" = uuctlSupport;
"man-pages" = true;
})
];

passthru = {
updateScript = nix-update-script { };
};

postInstall = ''
wrapProgram $out/bin/uwsm \
--prefix PATH : ${
lib.makeBinPath (
finalAttrs.propagatedBuildInputs
++ (lib.optional hyprlandSupport hyprland)
++ (lib.optional swaySupport sway)
)
}
${lib.optionalString uuctlSupport ''
wrapProgram $out/bin/uuctl \
--prefix PATH : ${lib.makeBinPath finalAttrs.propagatedBuildInputs}
''}
'';

meta = {
description = "Universal wayland session manager";
homepage = "https://github.com/Vladimir-csp/uwsm";
mainProgram = "uwsm";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ johnrtitor ];
platforms = lib.platforms.linux;
};
})
35 changes: 35 additions & 0 deletions modules-overlays/uwsm/uwsm-path.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
diff --git a/uwsm/main.py b/uwsm/main.py
index d13208d..864ceb1 100644
--- a/uwsm/main.py
+++ b/uwsm/main.py
@@ -1429,10 +1429,12 @@ def generate_units():
)
# for bindpid use lightweight waitpid binary if available,
# otherwise use aux waitpid shim
- if which("waitpid"):
- bindpid_cmd = "waitpid -e"
+ # Ensure that the binary can be found in the service file
+ waitpid_path = which("waitpid")
+ if waitpid_path:
+ bindpid_cmd = f"{waitpid_path} -e"
else:
- bindpid_cmd = "uwsm aux waitpid"
+ bindpid_cmd = f"{BIN_PATH} aux waitpid"
update_unit(
"[email protected]",
dedent(
@@ -2631,8 +2633,13 @@ def prepare_env():
random_mark = f"MARK_{random_hex(16)}_MARK"
shell_code = prepare_env_gen_sh(random_mark)

+ sh_path = which("sh")
+ if not sh_path:
+ print_error(f'"sh" is not in PATH!')
+ sys.exit(1)
+
sprc = subprocess.run(
- ["sh", "-"],
+ [sh_path, "-"],
text=True,
input=shell_code,
capture_output=True,
29 changes: 29 additions & 0 deletions modules-overlays/uwsm/uwsm-wm-wrapper.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
lib,
stdenvNoCC,
writeText,
uwsm,
wmName ? "Example",
wmCmd ? "example",
}:
let
wm-desktop-entry = writeText "${wmName}_uwsm.desktop" ''
[Desktop Entry]
Name=${wmName} (with UWSM)
Comment=${wmName} compositor managed by UWSM
Exec=${lib.getExe uwsm} start -S -- ${wmCmd}
Type=Application
'';
in stdenvNoCC.mkDerivation {
pname = "${wmName}_uwsm";
version = "1.0.0";
dontUnpack = true;
dontBuild = true;
installPhase = ''
runHook preInstall
mkdir -p $out/share/wayland-sessions
cp ${wm-desktop-entry} $out/share/wayland-sessions/${wmName}_uwsm.desktop
runHook postInstall
'';
passthru.providedSessions = ["${wmName}_uwsm"];
}

0 comments on commit 7de078c

Please sign in to comment.