nushell, helium + pwas, niri session management
This commit is contained in:
parent
cb72b47661
commit
3b3bfb6b39
21 changed files with 816 additions and 464 deletions
|
|
@ -5,13 +5,36 @@
|
|||
...
|
||||
}:
|
||||
let
|
||||
inherit (lib) mkIf;
|
||||
browser = lib.getExe config.apps.browser;
|
||||
inherit (lib)
|
||||
mkOption
|
||||
mkAliasOptionModule
|
||||
types
|
||||
mapAttrsToList
|
||||
attrNames
|
||||
filterAttrs
|
||||
replaceStrings
|
||||
getExe
|
||||
toLower
|
||||
;
|
||||
inherit (types)
|
||||
str
|
||||
strMatching
|
||||
package
|
||||
path
|
||||
nullOr
|
||||
listOf
|
||||
attrsOf
|
||||
submodule
|
||||
either
|
||||
;
|
||||
|
||||
browser = getExe config.apps.browser;
|
||||
|
||||
webAppLauncher = pkgs.writeShellScript "web-app-launcher" ''
|
||||
browser="${browser}"
|
||||
|
||||
browser_exec=""
|
||||
for path in ~/.local ~/.nix-profile /usr; do
|
||||
for path in ~/.local ~/.nix-profile /usr /nix/var/nix/profiles/system/etc/profiles/per-user/$USER; do
|
||||
if [ -f "$path/share/applications/$browser.desktop" ]; then
|
||||
browser_exec=$(sed -n 's/^Exec=\([^ ]*\).*/\1/p' "$path/share/applications/$browser.desktop" 2>/dev/null | head -1)
|
||||
break
|
||||
|
|
@ -45,88 +68,112 @@ let
|
|||
'';
|
||||
|
||||
# Create web app package
|
||||
createWebApp =
|
||||
mkWebApp =
|
||||
{
|
||||
name,
|
||||
url,
|
||||
icon,
|
||||
description ? "",
|
||||
categories ? [
|
||||
"Network"
|
||||
"Chat"
|
||||
"InstantMessaging"
|
||||
],
|
||||
description,
|
||||
categories,
|
||||
}:
|
||||
let
|
||||
pkgName = "${lib.replaceStrings [ " " ] [ "-" ] (lib.toLower name)}-web-app";
|
||||
cleanName = replaceStrings [ " " "\n" "\t" ] [ "-" "-" "-" ] name |> toLower;
|
||||
pname = "${cleanName}-webapp";
|
||||
in
|
||||
{
|
||||
name = pkgName;
|
||||
value = pkgs.stdenv.mkDerivation {
|
||||
pname = pkgName;
|
||||
version = "1.0";
|
||||
dontUnpack = true;
|
||||
pkgs.stdenv.mkDerivation {
|
||||
inherit pname;
|
||||
version = "1.0";
|
||||
dontUnpack = true;
|
||||
|
||||
nativeBuildInputs = [
|
||||
pkgs.copyDesktopItems
|
||||
pkgs.makeWrapper
|
||||
];
|
||||
nativeBuildInputs = [
|
||||
pkgs.copyDesktopItems
|
||||
pkgs.makeWrapper
|
||||
];
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
makeWrapper ${webAppLauncher} $out/bin/${pkgName} \
|
||||
--add-flags "${url}" \
|
||||
--add-flags "${pkgName}"
|
||||
runHook postInstall
|
||||
'';
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
makeWrapper ${webAppLauncher} $out/bin/${pname} \
|
||||
--add-flags "${url}" \
|
||||
--add-flags "${pname}"
|
||||
runHook postInstall
|
||||
'';
|
||||
|
||||
desktopItems = [
|
||||
(pkgs.makeDesktopItem {
|
||||
inherit icon categories;
|
||||
name = pkgName;
|
||||
exec = "${pkgName} %U";
|
||||
desktopItems = [
|
||||
(pkgs.makeDesktopItem (
|
||||
{
|
||||
name = pname;
|
||||
exec = "${pname} %U";
|
||||
desktopName = name;
|
||||
comment = description;
|
||||
startupNotify = true;
|
||||
startupWMClass = pkgName;
|
||||
})
|
||||
];
|
||||
startupWMClass = pname;
|
||||
}
|
||||
// filterAttrs (_: v: v != null) {
|
||||
inherit icon categories;
|
||||
comment = description;
|
||||
}
|
||||
))
|
||||
];
|
||||
|
||||
meta.mainProgram = pname;
|
||||
|
||||
};
|
||||
|
||||
innerOpts = {
|
||||
options = {
|
||||
name = mkOption {
|
||||
type = str;
|
||||
};
|
||||
url = mkOption {
|
||||
type = strMatching "[hH][tT][tT][pP][sS]?://[^\n\r[:space:]]+";
|
||||
};
|
||||
icon = mkOption {
|
||||
type = nullOr (either str path);
|
||||
default = null;
|
||||
};
|
||||
description = mkOption {
|
||||
type = nullOr str;
|
||||
default = null;
|
||||
};
|
||||
categories = mkOption {
|
||||
type = nullOr (listOf str);
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
apps = builtins.listToAttrs (
|
||||
map createWebApp [
|
||||
{
|
||||
name = "Cinny";
|
||||
url = "https://chat.lobotomise.me";
|
||||
icon = "cinny";
|
||||
description = "Cinny, a Matrix client";
|
||||
}
|
||||
{
|
||||
name = "Discord";
|
||||
url = "https://discord.com/app";
|
||||
icon = "discord";
|
||||
description = "Discord Web";
|
||||
}
|
||||
{
|
||||
name = "FB Messenger";
|
||||
url = "https://m.me";
|
||||
icon = "facebook";
|
||||
description = "Facebook Messenger";
|
||||
}
|
||||
]
|
||||
pwaModule = submodule (
|
||||
{ config, ... }:
|
||||
{
|
||||
imports =
|
||||
let
|
||||
names = innerOpts.options |> attrNames;
|
||||
in
|
||||
map (optName: mkAliasOptionModule [ optName ] [ "settings" optName ]) names;
|
||||
options = {
|
||||
settings = mkOption {
|
||||
type = submodule innerOpts;
|
||||
default = { };
|
||||
};
|
||||
package = mkOption {
|
||||
type = package;
|
||||
readOnly = true;
|
||||
default = mkWebApp config.settings;
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
in
|
||||
{
|
||||
config = {
|
||||
environment.systemPackages = builtins.attrValues apps;
|
||||
|
||||
xdg.mime.defaultApplications = {
|
||||
"x-scheme-handler/matrix" = "cinny-web-app.desktop";
|
||||
options = {
|
||||
programs.pwas = mkOption {
|
||||
description = "PWA Applications";
|
||||
type = attrsOf pwaModule;
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
|
||||
environment.etc."web-apps-setup".text = ''
|
||||
mkdir -p /home/*/.local/share/web-apps
|
||||
'';
|
||||
config = {
|
||||
environment.systemPackages = mapAttrsToList (_: v: v.package) config.programs.pwas;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue