refactor(greetd): astal -> ags
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-07-25 23:24:19 -04:00
parent aa979f0fe4
commit 85ff6af1bf
24 changed files with 142 additions and 198 deletions

Binary file not shown.

BIN
flake.nix

Binary file not shown.

View file

@ -162,11 +162,6 @@ let
owner = "Cu3PO42"; owner = "Cu3PO42";
repo = "gtk-session-lock"; repo = "gtk-session-lock";
}; };
astal = mkDep {
owner = "Aylur";
repo = "Astal";
};
}; };
}; };

View file

@ -21,7 +21,7 @@
astalTray = astal-tray.packages.${pkgs.system}.tray; astalTray = astal-tray.packages.${pkgs.system}.tray;
gtkSessionLock = gtk-session-lock.packages.${pkgs.system}.default; gtkSessionLock = gtk-session-lock.packages.${pkgs.system}.default;
in { in {
# Enable pam for ags and astal # Enable pam for ags
security.pam.services.ags = {}; security.pam.services.ags = {};
services.upower.enable = true; services.upower.enable = true;
@ -40,6 +40,8 @@ in {
configJs = configJs =
# javascript # javascript
'' ''
Utils.execAsync('hyprpaper');
import { transpileTypeScript } from './js/utils.js'; import { transpileTypeScript } from './js/utils.js';
export default (await transpileTypeScript('${hostName}')).default; export default (await transpileTypeScript('${hostName}')).default;

View file

@ -1,10 +1,11 @@
{ {
config, config,
lib,
pkgs, pkgs,
self, self,
... ...
}: let }: let
inherit (config.vars) configDir; inherit (lib) mkIf;
cursorTheme = self.legacyPackages.${pkgs.system}.dracula.hyprcursor; cursorTheme = self.legacyPackages.${pkgs.system}.dracula.hyprcursor;
cursorThemeName = "Dracula-cursors"; cursorThemeName = "Dracula-cursors";
@ -19,31 +20,34 @@ in {
home.file.".local/share/icons/${hyprcursorThemeName}".source = cursorTheme; home.file.".local/share/icons/${hyprcursorThemeName}".source = cursorTheme;
wayland.windowManager.hyprland = { wayland.windowManager.hyprland = {
settings = { settings =
envd = [ {
"XCURSOR_THEME, ${cursorThemeName}" envd = [
"XCURSOR_SIZE, ${cursorSize}" "XCURSOR_THEME, ${cursorThemeName}"
]; "XCURSOR_SIZE, ${cursorSize}"
];
exec-once = [ exec-once = [
"hyprctl setcursor ${hyprcursorThemeName} ${cursorSize}" "hyprctl setcursor ${hyprcursorThemeName} ${cursorSize}"
"hyprpaper" ];
];
windowrule = [ windowrule = [
"size 1231 950,title:^(Open Folder)$" "size 1231 950,title:^(Open Folder)$"
"float,title:^(Open Folder)$" "float,title:^(Open Folder)$"
"size 1231 950,title:^(Open File)$" "size 1231 950,title:^(Open File)$"
"float,title:^(Open File)$" "float,title:^(Open File)$"
]; ];
layerrule = [ layerrule = [
"noanim, selection" "noanim, selection"
]; ];
}
# This file should only be used for theming // (
source = ["${configDir}/hypr/main.conf"]; mkIf (config.home.username != "greeter") {
}; # This file should only be used for theming
source = ["${config.vars.configDir}/hypr/main.conf"];
}
);
}; };
} }

View file

@ -0,0 +1 @@
../../../ags/config/.envrc

View file

@ -0,0 +1,67 @@
{
ags,
config,
lib,
pkgs,
...
}: let
cfg = config.roles.desktop;
hyprland =
config
.home-manager
.users
.${cfg.user}
.wayland
.windowManager
.hyprland
.finalPackage;
in {
# Add home folder for home-manager to work
users.users.greeter = {
home = "/var/lib/greeter";
createHome = true;
};
home-manager.users.greeter = {
imports = [ags.homeManagerModules.default];
programs.ags.enable = true;
home.packages = [
hyprland
pkgs.gtk3
pkgs.glib
];
xdg.configFile = {
"ags".source = pkgs.stdenv.mkDerivation {
name = "ags-greeter";
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./scss
./greeter.ts
./ts
./tsconfig.json
];
};
buildInputs = with pkgs; [
bun
dart-sass
];
buildPhase = ''
sass ./scss/greeter.scss style.css
bun build ./greeter.ts --external resource:///* --external gi://* --external cairo > config.js
'';
installPhase = ''
mkdir $out
mv style.css config.js $out/
'';
};
};
};
}

View file

@ -0,0 +1 @@
../../../ags/config/eslint.config.js

View file

@ -0,0 +1,11 @@
Utils.execAsync('hyprpaper');
import Greeter from './ts/greetd/main.ts';
App.config({
style: './style.css',
windows: () => [
Greeter(),
],
});

View file

@ -0,0 +1 @@
../../../ags/config/package-lock.json

View file

@ -0,0 +1 @@
../../../ags/config/package.json

View file

@ -7,9 +7,6 @@ const { Gtk } = imports.gi;
const DEFAULT_NAME = 'matt'; const DEFAULT_NAME = 'matt';
// Types
import { StringObject } from 'types/@girs/gtk-4.0/gtk-4.0.cjs';
const parsePasswd = (fileContent: string) => { const parsePasswd = (fileContent: string) => {
const splitUsers = fileContent.split('\n'); const splitUsers = fileContent.split('\n');
@ -35,7 +32,11 @@ const parsePasswd = (fileContent: string) => {
}; };
const users = parsePasswd(await readFileAsync('/etc/passwd')); const users = parsePasswd(await readFileAsync('/etc/passwd'));
const dropdown = Gtk.DropDown.new_from_strings(users.map((u) => u.name)); const dropdown = new Gtk.ComboBoxText();
users.forEach((u) => {
dropdown.append(null, u.name);
});
const password = Entry({ const password = Entry({
placeholderText: 'Password', placeholderText: 'Password',
@ -47,7 +48,7 @@ const password = Entry({
on_accept: () => { on_accept: () => {
greetd.login( greetd.login(
(dropdown.selectedItem as StringObject)['string'] || '', dropdown.get_active_text() ?? '',
password.text || '', password.text || '',
'Hyprland', 'Hyprland',
@ -70,7 +71,7 @@ export default () => Window({
vpack: 'center', vpack: 'center',
hexpand: true, hexpand: true,
vexpand: true, vexpand: true,
cssClasses: ['base'], class_names: ['base'],
children: [ children: [
Box({ Box({
@ -79,23 +80,14 @@ export default () => Window({
vpack: 'center', vpack: 'center',
hexpand: true, hexpand: true,
vexpand: true, vexpand: true,
class_names: ['linked'],
setup: (self) => { setup: () => {
self.add_css_class('linked');
idle(() => { idle(() => {
const usernames = [] as string[]; const usernames = users.map((u) => u.name);
for (let i = 0; i < dropdown.model.get_n_items(); ++i) {
const name = (dropdown.model.get_item(i) as StringObject)['string'];
if (name) {
usernames.push(name);
}
}
if (usernames.includes(DEFAULT_NAME)) { if (usernames.includes(DEFAULT_NAME)) {
dropdown.set_selected(usernames.indexOf(DEFAULT_NAME)); dropdown.set_active(usernames.indexOf(DEFAULT_NAME));
} }
}); });
}, },

View file

@ -2,22 +2,24 @@
"compilerOptions": { "compilerOptions": {
"target": "ES2022", "target": "ES2022",
"module": "ES2022", "module": "ES2022",
"lib": [ "lib": ["ES2022"],
"ES2022" "noEmit": true,
], "allowImportingTsExtensions": true,
"allowSyntheticDefaultImports": true,
"allowJs": true, "allowJs": true,
"checkJs": true, "checkJs": true,
"strict": true, "strict": true,
"noImplicitAny": false, "noImplicitAny": false,
"baseUrl": ".", "baseUrl": ".",
"paths": { "paths": {
"gi://Adw": ["./node_modules/@girs/adw-1/adw-1.d.ts"], "fzf": ["./node_modules/fzf/dist/types"]
"gi://Adw?version=1": ["./node_modules/@girs/adw-1/adw-1.d.ts"]
}, },
"typeRoots": [ "typeRoots": [
"./types", "./types",
"./global-types.d.ts",
"./node_modules" "./node_modules"
], ],
"skipLibCheck": true "skipLibCheck": true,
"forceConsistentCasingInFileNames": true
} }
} }

View file

@ -1,59 +0,0 @@
{
astal,
config,
pkgs,
...
}: let
cfg = config.roles.desktop;
hyprland =
config
.home-manager
.users
.${cfg.user}
.wayland
.windowManager
.hyprland
.finalPackage;
in {
# Add home folder for home-manager to work
users.users.greeter = {
home = "/var/lib/greeter";
createHome = true;
};
home-manager.users.greeter = {
imports = [
astal.homeManagerModules.default
../home/theme
../home/hyprpaper.nix
];
programs.astal.enable = true;
home.packages = [
hyprland
pkgs.bun
pkgs.dart-sass
pkgs.gtk3
pkgs.glib
];
xdg.configFile = {
"astal" = {
source = ./astal;
recursive = true;
};
"astal/config.js".text =
# javascript
''
import { transpileTypeScript } from './js/utils.js';
Utils.execAsync('hyprpaper');
export default (await transpileTypeScript('greeter')).default;
'';
};
};
}

View file

@ -1 +0,0 @@
use flake $FLAKE#node

View file

@ -1 +0,0 @@
../../../ags/config/.eslintrc.json

View file

@ -1 +0,0 @@
../../../ags/config/.stylelintrc.yml

View file

@ -1,7 +0,0 @@
import Greeter from './ts/greetd/main';
App.config({
windows: () => [
Greeter(),
],
});

View file

@ -1,47 +0,0 @@
const { execAsync, monitorFile } = Utils;
/** @param {string} host */
const watchAndCompileSass = (host) => {
const reloadCss = () => {
const scss = `${App.configDir}/scss/${host}.scss`;
const css = `/tmp/astal-${host}/style.css`;
execAsync(`sass ${scss} ${css}`).then(() => {
App.resetCss();
App.applyCss(css);
}).catch(print);
};
monitorFile(
`${App.configDir}/scss`,
reloadCss,
);
reloadCss();
};
/** @param {string} host */
export const transpileTypeScript = async(host) => {
const outPath = `/tmp/astal-${host}/index.js`;
await execAsync([
'bash', '-c',
// Create the dir if it doesn't exist
`mkdir -p /tmp/astal-${host}; ` +
// Let bun see tsconfig.json
`cd ${App.configDir};` +
`bun build ${App.configDir}/${host}.ts ` +
'--external resource:///* ' +
'--external gi://* ' +
'--external cairo ' +
// Since bun wants to write in cwd, we just redirect stdin instead
`> ${outPath}`,
]).catch(print);
watchAndCompileSass(host);
return await import(`file://${outPath}`);
};

View file

@ -1,13 +0,0 @@
{
"main": "config.js",
"dependencies": {
"fzf": "^0.5.2"
},
"devDependencies": {
"@girs/adw-1": "^1.4.3-3.2.9",
"@stylistic/eslint-plugin": "^1.4.0",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"eslint": "^8.52.0"
}
}

View file

@ -21,7 +21,7 @@
''); '');
in { in {
imports = [ imports = [
./astal.nix ./ags
./hyprland.nix ./hyprland.nix
]; ];

View file

@ -23,6 +23,8 @@
devices = filterAttrs (n: v: hasPrefix "device:" n) cfgHypr.settings; devices = filterAttrs (n: v: hasPrefix "device:" n) cfgHypr.settings;
in { in {
home-manager.users.greeter = { home-manager.users.greeter = {
imports = [../desktop-environment/home/style.nix];
wayland.windowManager.hyprland = { wayland.windowManager.hyprland = {
enable = true; enable = true;
package = cfgHypr.finalPackage; package = cfgHypr.finalPackage;
@ -32,17 +34,13 @@ in {
{ {
inherit (cfgHypr.settings) cursor input misc monitor; inherit (cfgHypr.settings) cursor input misc monitor;
envd = envd = optionals (config.nvidia.enable) [
(optionals (config.nvidia.enable) [ "LIBVA_DRIVER_NAME, nvidia"
"LIBVA_DRIVER_NAME, nvidia" "NVD_BACKEND, direct"
"NVD_BACKEND, direct" "XDG_SESSION_TYPE, wayland"
"XDG_SESSION_TYPE, wayland" "GBM_BACKEND, nvidia-drm"
"GBM_BACKEND, nvidia-drm" "__GLX_VENDOR_LIBRARY_NAME, nvidia"
"__GLX_VENDOR_LIBRARY_NAME, nvidia" ];
])
++ [
"XCURSOR_SIZE,24"
];
general.border_size = 0; general.border_size = 0;
@ -52,10 +50,8 @@ in {
}; };
exec-once = [ exec-once = [
"hyprctl setcursor Dracula-cursors 24"
setupMonitors setupMonitors
"astal -b greeter &> /tmp/astal.log; hyprctl dispatch exit" "ags -b greeter &> /tmp/ags-greetd.log; hyprctl dispatch exit"
]; ];
} }
// devices; // devices;