Skip to content

Commit

Permalink
nix: refactor (#197)
Browse files Browse the repository at this point in the history
close #192
  • Loading branch information
Aylur authored Dec 21, 2024
1 parent dafb191 commit 0507a6b
Show file tree
Hide file tree
Showing 26 changed files with 535 additions and 400 deletions.
240 changes: 8 additions & 232 deletions docs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,239 +2,15 @@
self,
pkgs,
}: let
inherit (builtins) replaceStrings readFile;
readVer = file: replaceStrings ["\n"] [""] (readFile file);
inherit (builtins) removeAttrs concatStringsSep map attrValues;
packages = attrValues (removeAttrs self.packages.${pkgs.system} ["default" "docs" "gjs"]);

toTOML = (pkgs.formats.toml {}).generate;
cp = pkg: ''
doc="${pkg.doc}/share/doc"
name=$(ls $doc)
docgen = pkgs.gi-docgen.overrideAttrs {
patches = [../nix/doc/gi-docgen.patch];
};

genLib = {
flakepkg,
gir,
version,
description,
api-ver ? "0.1",
authors ? "Aylur",
dependencies ? {},
out ? "libastal/${flakepkg}",
browse ? flakepkg,
website ? flakepkg,
}: let
name = "Astal${gir}-${api-ver}";
src = self.packages.${pkgs.system}.${flakepkg}.dev;

data = toTOML gir {
library = {
inherit description authors;
version = readVer version;
license = "LGPL-2.1";
browse_url = "https://github.com/Aylur/astal/tree/main/lib/${browse}";
repository_url = "https://github.com/aylur/aylur.git";
website_url = "https://aylur.github.io/astal/guide/libraries/${website}";
dependencies = ["GObject-2.0"] ++ (builtins.attrNames dependencies);
};

extra.urlmap_file = "urlmap.js";
dependencies = {inherit (dependency) "GObject-2.0";} // dependencies;
};
in ''
mkdir -p $out/${out}
cat ${urlmap} > urlmap.js
gi-docgen generate -C ${data} ${src}/share/gir-1.0/${name}.gir
cp -r ${name}/* $out/${out}
'';

dependency = {
"GObject-2.0" = {
name = "GObject";
description = "The base type system library";
docs_url = "https://docs.gtk.org/gobject/";
};
"Gtk-3.0" = {
name = "Gtk";
description = "The GTK toolkit";
docs_url = "https://docs.gtk.org/gtk3/";
};
"Gtk-4.0" = {
name = "Gtk";
description = "The GTK toolkit";
docs_url = "https://docs.gtk.org/gtk4/";
};
"AstalIO-0.1" = {
name = "AstalIO";
description = "Astal Core library";
docs_url = "https://aylur.github.io/libastal/io";
};
"NM-1.0" = {
name = "NetworkManager";
description = "The standard Linux network configuration tool suite";
docs_url = "https://networkmanager.dev/docs/libnm/latest/";
};
"WP-0.5" = {
name = "WirePlumber";
description = "Modular session/policy manager for PipeWire";
docs_url = "https://pipewire.pages.freedesktop.org/wireplumber/";
};
};

urlmap = pkgs.writeText "urlmap" ''
baseURLs = ${builtins.toJSON [
["GLib" "https://docs.gtk.org/glib/"]
["GObject" "https://docs.gtk.org/gobject/"]
["Gio" "https://docs.gtk.org/gio/"]
["Gdk" "https://docs.gtk.org/gdk3/"]
["Gtk" "https://docs.gtk.org/gtk3/"]
["GdkPixbuf" "https://docs.gtk.org/gdk-pixbuf/"]
["AstalIO" "https://aylur.github.io/libastal/io"]
# FIXME: these are not gi-docgen generated, therefore links are broken
["NM" "https://networkmanager.dev/docs/libnm/latest/"]
["WP" "https://pipewire.pages.freedesktop.org/wireplumber/"]
]}
mkdir -p "$out/$name"
cp -r "$doc/$name" $out
'';
in
pkgs.stdenvNoCC.mkDerivation {
name = "reference";
src = ./.;

nativeBuildInputs = with pkgs; [
docgen
glib
json-glib
gobject-introspection
gtk3
gtk4
gtk-layer-shell
gtk4-layer-shell
gdk-pixbuf
libdbusmenu-gtk3
wireplumber
networkmanager
self.packages.${system}.io
];

installPhase = ''
runHook preInstall
${genLib {
flakepkg = "io";
gir = "IO";
api-ver = "0.1";
browse = "astal/io";
description = "Astal Core library";
version = ../lib/astal/io/version;
}}
${genLib {
flakepkg = "astal3";
gir = "";
api-ver = "3.0";
browse = "astal/gtk3";
description = "Astal GTK3 widget library";
version = ../lib/astal/gtk3/version;
dependencies = {inherit (dependency) "AstalIO-0.1" "Gtk-3.0";};
}}
${genLib {
flakepkg = "astal4";
gir = "";
api-ver = "4.0";
browse = "astal/gtk4";
description = "Astal GTK4 widget library";
version = ../lib/astal/gtk4/version;
dependencies = {inherit (dependency) "AstalIO-0.1" "Gtk-4.0";};
}}
${genLib {
flakepkg = "apps";
gir = "Apps";
description = "Application query library";
version = ../lib/apps/version;
}}
${genLib {
flakepkg = "auth";
gir = "Auth";
authors = "kotontrion";
description = "Authentication using pam";
version = ../lib/auth/version;
}}
${genLib {
flakepkg = "battery";
gir = "Battery";
description = "DBus proxy for upowerd devices";
version = ../lib/battery/version;
}}
${genLib {
flakepkg = "bluetooth";
gir = "Bluetooth";
description = "DBus proxy for bluez";
version = ../lib/bluetooth/version;
}}
${genLib {
flakepkg = "cava";
gir = "Cava";
description = "Audio visualization library using cava";
version = ../lib/cava/version;
authors = "kotontrion";
}}
${genLib {
flakepkg = "greet";
gir = "Greet";
description = "IPC client for greetd";
version = ../lib/greet/version;
}}
${genLib {
flakepkg = "hyprland";
gir = "Hyprland";
description = "IPC client for Hyprland";
version = ../lib/hyprland/version;
}}
${genLib {
flakepkg = "mpris";
gir = "Mpris";
description = "Control mpris players";
version = ../lib/mpris/version;
}}
${genLib {
flakepkg = "network";
gir = "Network";
description = "NetworkManager wrapper library";
version = ../lib/network/version;
dependencies = {inherit (dependency) "NM-1.0";}; # FIXME: why does this not work?
}}
${genLib {
flakepkg = "notifd";
gir = "Notifd";
description = "Notification daemon library";
version = ../lib/notifd/version;
}}
${genLib {
flakepkg = "powerprofiles";
gir = "PowerProfiles";
description = "DBus proxy for upowerd profiles";
version = ../lib/powerprofiles/version;
}}
${genLib {
flakepkg = "river";
gir = "River";
description = "IPC client for River";
version = ../lib/river/version;
authors = "kotontrion";
}}
${genLib {
flakepkg = "tray";
gir = "Tray";
description = "StatusNotifierItem implementation";
version = ../lib/tray/version;
authors = "kotontrion";
}}
${genLib {
flakepkg = "wireplumber";
gir = "Wp";
description = "Wrapper library over the wireplumber API";
version = ../lib/wireplumber/version;
authors = "kotontrion";
dependencies = {inherit (dependency) "WP-0.5";}; # FIXME: why does this not work?
}}
runHook postInstall
'';
}
pkgs.runCommand "docs" {} (concatStringsSep "" (map cp packages))
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 36 additions & 67 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,80 +3,49 @@
self,
nixpkgs,
}: let
inherit (builtins) replaceStrings readFile;
readVer = file: replaceStrings ["\n"] [""] (readFile file);

system = "x86_64-linux"; # TODO: other architectures
pkgs = nixpkgs.legacyPackages.${system};

mkPkg = name: src: inputs:
pkgs.stdenv.mkDerivation {
nativeBuildInputs = with pkgs; [
wrapGAppsHook
gobject-introspection
meson
pkg-config
ninja
vala
wayland
wayland-scanner
python3
];
propagatedBuildInputs = [pkgs.glib] ++ inputs;
pname = name;
version = readVer "${src}/version";
src = src;
postUnpack = ''
cp --remove-destination ${./lib/gir.py} $sourceRoot/gir.py
'';
outputs = ["out" "dev"];
};
forAllSystems = nixpkgs.lib.genAttrs ["x86_64-linux" "aarch64-linux"];
in {
devShells.${system} = import ./nix/devshell.nix {
inherit self pkgs;
};

lib = {
mkLuaPackage = import ./nix/lua.nix {
inherit pkgs;
astal = self;
};
mkLuaPackage = import ./nix/lua.nix self;
};

packages.${system} = with pkgs; {
docs = import ./docs {inherit self pkgs;};
packages = forAllSystems (system: let
pkgs = nixpkgs.legacyPackages.${system};
mkPkg = src:
import src {
inherit self pkgs;
mkAstalPkg = import ./nix/mkAstalPkg.nix pkgs;
};
in {
default = self.packages.${system}.io;
docs = import ./docs {inherit self pkgs;};

io = mkPkg "astal" ./lib/astal/io [];
astal3 = mkPkg "astal" ./lib/astal/gtk3 [self.packages.${system}.io gtk3 gtk-layer-shell];
astal4 = mkPkg "astal" ./lib/astal/gtk4 [self.packages.${system}.io gtk4 gtk4-layer-shell];
apps = mkPkg "astal-apps" ./lib/apps [json-glib];
auth = mkPkg "astal-auth" ./lib/auth [pam];
battery = mkPkg "astal-battery" ./lib/battery [json-glib];
bluetooth = mkPkg "astal-bluetooth" ./lib/bluetooth [];
cava = mkPkg "astal-cava" ./lib/cava [(pkgs.callPackage ./nix/libcava.nix {})];
greet = mkPkg "astal-greet" ./lib/greet [json-glib];
hyprland = mkPkg "astal-hyprland" ./lib/hyprland [json-glib];
mpris = mkPkg "astal-mpris" ./lib/mpris [gvfs json-glib];
network = mkPkg "astal-network" ./lib/network [networkmanager];
notifd = mkPkg "astal-notifd" ./lib/notifd [json-glib gdk-pixbuf];
powerprofiles = mkPkg "astal-power-profiles" ./lib/powerprofiles [json-glib];
river = mkPkg "astal-river" ./lib/river [json-glib];
tray = mkPkg "astal-tray" ./lib/tray [json-glib (pkgs.callPackage ./nix/appmenu-glib.nix {})];
wireplumber = mkPkg "astal-wireplumber" ./lib/wireplumber [wireplumber];
io = mkPkg ./lib/astal/io;
astal3 = mkPkg ./lib/astal/gtk3;
astal4 = mkPkg ./lib/astal/gtk4;
apps = mkPkg ./lib/apps;
auth = mkPkg ./lib/auth;
battery = mkPkg ./lib/battery;
bluetooth = mkPkg ./lib/bluetooth;
cava = mkPkg ./lib/cava;
greet = mkPkg ./lib/greet;
hyprland = mkPkg ./lib/hyprland;
mpris = mkPkg ./lib/mpris;
network = mkPkg ./lib/network;
notifd = mkPkg ./lib/notifd;
powerprofiles = mkPkg ./lib/powerprofiles;
river = mkPkg ./lib/river;
tray = mkPkg ./lib/tray;
wireplumber = mkPkg ./lib/wireplumber;

gjs = pkgs.stdenvNoCC.mkDerivation {
src = ./lang/gjs;
name = "astal-gjs";
nativeBuildInputs = [
meson
ninja
pkg-config
self.packages.${system}.io
self.packages.${system}.astal3
];
};
};
gjs = import ./lang/gjs {inherit self pkgs;};
});

devShells = forAllSystems (system:
import ./nix/devshell.nix {
inherit self;
pkgs = nixpkgs.legacyPackages.${system};
});
};

inputs = {
Expand Down
16 changes: 16 additions & 0 deletions lang/gjs/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
pkgs,
self,
...
}:
pkgs.stdenvNoCC.mkDerivation {
src = ./.;
name = "astal-gjs";
nativeBuildInputs = [
pkgs.meson
pkgs.ninja
pkgs.pkg-config
self.packages.${pkgs.system}.io
self.packages.${pkgs.system}.astal3

This comment has been minimized.

Copy link
@ys5g

ys5g Dec 29, 2024

Would adding self.packages.${pkgs.system}.astal4 be needed after #196?

];
}
Loading

0 comments on commit 0507a6b

Please sign in to comment.