Skip to content

Commit

Permalink
refactor!(nix): switch from self.lib.wrap to passthru.wrapAgs
Browse files Browse the repository at this point in the history
Should it just be `passthru.wrap`?
  • Loading branch information
ys5g committed Jan 15, 2025
1 parent 9e3f191 commit 3d75342
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 40 deletions.
4 changes: 1 addition & 3 deletions docs/guide/nix.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ Or define a `devShell` and cherry pick packages.
devShells.${system}.default = pkgs.mkShell {
buildInputs = [
# includes astal3 astal4 astal-io by default
(ags.lib.wrap { # [!code focus:5]
inherit pkgs;
agsPackage = ags.packages.${system}.default;
(ags.wrapAgs { # [!code focus:5]
extraPackages = [
# cherry pick packages
];
Expand Down
12 changes: 4 additions & 8 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;};
wrap = import ./nix/wrap.nix;
};
lib.bundle = import ./nix/bundle.nix {inherit self;};

packages = forAllSystems (
system: let
Expand All @@ -31,12 +28,11 @@

agsPackages = rec {
default = ags;
ags = pkgs.callPackage ./nix {
ags = pkgs.callPackage ./nix/default.nix {
inherit astal3 astal4 astal-io astal-gjs;
wrapAgs = import ./nix/wrap.nix { inherit pkgs ags; };
};
agsFull = self.lib.wrap {
inherit pkgs;
agsPackage = ags;
agsFull = ags.wrapAgs {
extraPackages = builtins.attrValues (
builtins.removeAttrs astal.packages.${system} ["docs"]
);
Expand Down
11 changes: 6 additions & 5 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
dart-sass,
blueprint-compiler,
installShellFiles,
wrapAgs,
}: let
inherit (builtins) replaceStrings readFile;

Expand All @@ -32,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 Down Expand Up @@ -80,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
17 changes: 7 additions & 10 deletions nix/hm-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,15 @@ in {
xdg.configFile."ags".source = cfg.configDir;
})
(let
pkg = self.lib.wrap {
inherit pkgs;
inherit (cfg) extraPackages;
agsPackage = cfg.package.override {
astal3 = cfg.astal.gtk3Package;
astal-io = cfg.astal.ioPackage;
astal-gjs = "${config.home.homeDirectory}/.local/share/ags";
};
pkg = cfg.package.override {
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
4 changes: 1 addition & 3 deletions nix/template/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
default = pkgs.mkShell {
buildInputs = [
# includes astal3 astal4 astal-io by default
(ags.lib.wrap {
inherit pkgs;
agsPackage = ags.packages.${system}.default;
(ags.wrapAgs {
extraPackages = [
# cherry pick packages
];
Expand Down
26 changes: 15 additions & 11 deletions nix/wrap.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{ pkgs, agsPackage, extraPackages ? [], allowRewrap ? false }:
{pkgs, ags}: { extraPackages ? [], allowRewrap ? false }:

let
inherit (pkgs.lib) makeBinPath unique;

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

Expand All @@ -12,14 +15,12 @@ let

installPhase = ''
mkdir $out/
# If ags ever creates other top-level directories, it would be a
# a better idea to just link `${agsPackage}/*` and then remove
# the bin directory and recreate it ourselves
ln -s ${agsPackage}/share $out
ln -s ${ags}/* $out
# $out/bin must be created manually so wrapGAppsHook can work there
# $out/bin must be recreated manually so wrapGAppsHook can work there
rm $out/bin
mkdir $out/bin
ln -s ${agsPackage}/bin/ags $out/bin/
ln -s ${ags}/bin/ags $out/bin/
'';

preFixup = ''
Expand All @@ -28,15 +29,18 @@ let
)
'';

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

in

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

0 comments on commit 3d75342

Please sign in to comment.