Skip to content

Commit

Permalink
feat(nix): packages.${system}.ags.wrapAgs function
Browse files Browse the repository at this point in the history
  • Loading branch information
ys5g committed Jan 15, 2025
1 parent 251d394 commit 81abedd
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 33 deletions.
2 changes: 1 addition & 1 deletion docs/guide/nix.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Or define a `devShell` and cherry pick packages.
devShells.${system}.default = pkgs.mkShell {
buildInputs = [
# includes astal3 astal4 astal-io by default
(ags.packages.${system}.default.override { # [!code focus:5]
(ags.wrapAgs { # [!code focus:5]
extraPackages = [
# cherry pick packages
];
Expand Down
15 changes: 6 additions & 9 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
systems = ["x86_64-linux" "aarch64-linux"];
forAllSystems = nixpkgs.lib.genAttrs systems;
in {
lib.bundle = import ./nix/bundle.nix {
inherit self;
pkgs = nixpkgs.legacyPackages.x86_64-linux;
};
lib.bundle = import ./nix/bundle.nix {inherit self;};

packages = forAllSystems (
system: let
Expand All @@ -29,13 +26,13 @@
astal-io = io;
astal-gjs = "${gjs}/share/astal/gjs";

agsPackages = {
default = self.packages.${system}.ags;
ags = pkgs.callPackage ./nix {
agsPackages = rec {
default = ags;
ags = pkgs.callPackage ./nix/default.nix {
inherit astal3 astal4 astal-io astal-gjs;
wrapAgs = import ./nix/wrap.nix { inherit pkgs ags; };
};
agsFull = pkgs.callPackage ./nix {
inherit astal3 astal4 astal-io astal-gjs;
agsFull = ags.wrapAgs {
extraPackages = builtins.attrValues (
builtins.removeAttrs astal.packages.${system} ["docs"]
);
Expand Down
3 changes: 1 addition & 2 deletions nix/bundle.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
self,
pkgs,
}: {
pkgs ? pkgs,
pkgs,
entry ? "app.ts",
src,
name,
Expand Down
28 changes: 13 additions & 15 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
dart-sass,
blueprint-compiler,
installShellFiles,
extraPackages ? [],
wrapAgs,
}: let
inherit (builtins) replaceStrings readFile;

Expand All @@ -33,12 +33,10 @@
blueprint-compiler
astal-io # FIXME: should not be needed after the astal commends are properly implemented using dbus in astal.go
];

version = replaceStrings ["\n"] [""] (readFile ../version);
pname = "ags";
in
buildGoModule {
inherit pname version;
buildGoModule rec {
pname = "ags";
version = replaceStrings ["\n"] [""] (readFile ../version);

src = builtins.path {
name = "${pname}-${version}";
Expand All @@ -54,19 +52,17 @@ in
installShellFiles
];

buildInputs =
extraPackages
++ [
glib
astal-io
astal3
astal4
];
buildInputs = [
glib
astal-io
astal3
astal4
];

preFixup = ''
gappsWrapperArgs+=(
--prefix NIX_GI_DIRS : "$(${datadirs})"
--prefix PATH : "${lib.makeBinPath (bins ++ extraPackages)}"
--prefix PATH : "${lib.makeBinPath bins}"
)
'';

Expand All @@ -83,6 +79,8 @@ in
"-X main.gtk4LayerShell=${gtk4-layer-shell}/lib/libgtk4-layer-shell.so"
];

passthru = { inherit wrapAgs; };

meta = {
homepage = "https://github.com/Aylur/ags";
description = "Scaffolding CLI tool for Astal+TypeScript projects";
Expand Down
6 changes: 3 additions & 3 deletions nix/hm-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ in {
})
(let
pkg = cfg.package.override {
extraPackages = cfg.extraPackages;
astal3 = cfg.astal.gtk3Package;
astal-io = cfg.astal.ioPackage;
astal-gjs = "${config.home.homeDirectory}/.local/share/ags";
};
wrapped = pkg.wrapAgs { inherit (cfg) extraPackages; };
in {
programs.ags.finalPackage = pkg;
home.packages = [pkg];
programs.ags.finalPackage = wrapped;
home.packages = [wrapped];
home.file.".local/share/ags".source = "${cfg.astal.gjsPackage}/share/astal/gjs";
})
(mkIf cfg.systemd.enable {
Expand Down
6 changes: 3 additions & 3 deletions nix/template/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
description = "My Awesome Desktop Shell";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";

ags = {
url = "github:aylur/ags";
Expand All @@ -11,9 +11,9 @@
};

outputs = {
self,
nixpkgs,
ags,
...
}: let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
Expand All @@ -37,7 +37,7 @@
default = pkgs.mkShell {
buildInputs = [
# includes astal3 astal4 astal-io by default
(ags.packages.${system}.default.override {
(ags.wrapAgs {
extraPackages = [
# cherry pick packages
];
Expand Down
46 changes: 46 additions & 0 deletions nix/wrap.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{pkgs, ags}: { extraPackages ? [], allowRewrap ? false }:

let
inherit (pkgs.lib) makeBinPath unique;

wrapped =
if extraPackages == []
then ags
else pkgs.stdenv.mkDerivation {
name = "ags-wrapped";
dontUnpack = true;

nativeBuildInputs = with pkgs; [wrapGAppsHook gobject-introspection];
buildInputs = with pkgs; [bash glib] ++ extraPackages;

installPhase = ''
mkdir $out/
ln -s ${ags}/* $out
# $out/bin must be recreated manually so wrapGAppsHook can work there
rm $out/bin
mkdir $out/bin
ln -s ${ags}/bin/ags $out/bin/
'';

preFixup = ''
gappsWrapperArgs+=(
--prefix PATH : "${makeBinPath extraPackages}"
)
'';

passthru.wasWrapped = true;
meta.mainProgram = "ags";
};

in

if ags.wasWrapped or false
then
if allowRewrap
then wrapped
else
if extraPackages == []
then ags
else ags.override (old: { extraPackages = unique (old.extraPackages ++ extraPackages); })
else wrapped

0 comments on commit 81abedd

Please sign in to comment.