From 7009462c3cce2795eaf03747c08309c72bf40f8a Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Thu, 1 Aug 2024 12:07:34 +0800 Subject: [PATCH] wrapper-manager-fds/modules: change basePackages to accept a bare package This will allow us to make changes to `programs..package`-type of options found in NixOS, home-manager, etc. but it is expensive at the cost of a rebuild which depends on the package. --- .../modules/wrapper-manager/base.nix | 16 +++++--- .../modules/wrapper-manager/build.nix | 38 +++++++++++++------ .../tests/configs/default.nix | 1 + .../tests/configs/single-basepackage.nix | 25 ++++++++++++ 4 files changed, 63 insertions(+), 17 deletions(-) create mode 100644 subprojects/wrapper-manager-fds/tests/configs/single-basepackage.nix diff --git a/subprojects/wrapper-manager-fds/modules/wrapper-manager/base.nix b/subprojects/wrapper-manager-fds/modules/wrapper-manager/base.nix index a06ef3e6..5c9a2557 100644 --- a/subprojects/wrapper-manager-fds/modules/wrapper-manager/base.nix +++ b/subprojects/wrapper-manager-fds/modules/wrapper-manager/base.nix @@ -196,14 +196,18 @@ in }; basePackages = lib.mkOption { - type = with lib.types; listOf package; + type = with lib.types; either package (listOf package); description = '' - A list of packages to be included in the wrapper package. + Packages to be included in the wrapper package. However, there are + differences in behavior when given certain values. - ::: {.note} - This can override some of the binaries included in this list which is - typically intended to be used as a wrapped package. - ::: + * When the value is a bare package, the build process will use + `$PACKAGE.overrideAttrs` to create the package. This makes it suitable + to be used as part of `programs..package` typically found on + other environments (e.g., NixOS). + + * When the value is a list of packages, the build process will use + `symlinkJoin` as the builder to create the derivation. ''; default = [ ]; example = lib.literalExpression '' diff --git a/subprojects/wrapper-manager-fds/modules/wrapper-manager/build.nix b/subprojects/wrapper-manager-fds/modules/wrapper-manager/build.nix index 788ce9f6..be627eb8 100644 --- a/subprojects/wrapper-manager-fds/modules/wrapper-manager/build.nix +++ b/subprojects/wrapper-manager-fds/modules/wrapper-manager/build.nix @@ -63,17 +63,33 @@ desktopEntries = mkDesktopEntries (lib.attrValues config.xdg.desktopEntries); in - pkgs.symlinkJoin { - passthru = config.build.extraPassthru; - name = "wrapper-manager-fds-wrapped-package"; - paths = desktopEntries ++ config.basePackages; - nativeBuildInputs = - if config.build.isBinary then [ pkgs.makeBinaryWrapper ] else [ pkgs.makeWrapper ]; - postBuild = '' - ${config.build.extraSetup} - ${mkWrapBuild (lib.attrValues config.wrappers)} - ''; - }; + if lib.isList config.basePackages then + pkgs.symlinkJoin { + passthru = config.build.extraPassthru; + name = "wrapper-manager-fds-wrapped-package"; + paths = desktopEntries ++ config.basePackages; + nativeBuildInputs = + if config.build.isBinary then [ pkgs.makeBinaryWrapper ] else [ pkgs.makeWrapper ]; + postBuild = '' + ${config.build.extraSetup} + ${mkWrapBuild (lib.attrValues config.wrappers)} + ''; + } + else + config.basePackages.overrideAttrs (final: prev: { + nativeBuildInputs = + (prev.nativeBuildInputs or [ ]) + ++ (if config.build.isBinary then [ pkgs.makeBinaryWrapper ] else [ pkgs.makeWrapper ]) + ++ lib.optionals (config.xdg.desktopEntries != { }) [ pkgs.copyDesktopItems ]; + desktopItems = (prev.desktopItems or [ ]) ++ desktopEntries; + postFixup = '' + ${prev.postFixup or ""} + ${mkWrapBuild (lib.attrValues config.wrappers)} + ''; + passthru = lib.recursiveUpdate (prev.passthru or { }) (config.build.extraPassthru // { + unwrapped = config.basePackages; + }); + }); }; }; } diff --git a/subprojects/wrapper-manager-fds/tests/configs/default.nix b/subprojects/wrapper-manager-fds/tests/configs/default.nix index b8b90c63..8877bb14 100644 --- a/subprojects/wrapper-manager-fds/tests/configs/default.nix +++ b/subprojects/wrapper-manager-fds/tests/configs/default.nix @@ -12,4 +12,5 @@ in { fastfetch = build [ ./wrapper-fastfetch.nix ]; neofetch = build [ ./wrapper-neofetch.nix ]; + single-basepackage = build [ ./single-basepackage.nix ]; } diff --git a/subprojects/wrapper-manager-fds/tests/configs/single-basepackage.nix b/subprojects/wrapper-manager-fds/tests/configs/single-basepackage.nix new file mode 100644 index 00000000..50637861 --- /dev/null +++ b/subprojects/wrapper-manager-fds/tests/configs/single-basepackage.nix @@ -0,0 +1,25 @@ +{ config, lib, pkgs, ... }: + +{ + basePackages = pkgs.fastfetch; + + wrappers.fastfetch-guix = { + arg0 = lib.getExe' pkgs.fastfetch "fastfetch"; + appendArgs = [ + "--logo" + "Guix" + ]; + env.NO_COLOR.value = "1"; + xdg.desktopEntry.enable = true; + }; + + build.extraPassthru.tests = { + singleBasePackage = + let + wrapper = config.build.toplevel; + in + pkgs.runCommand "wrapper-manager-fastfetch-actually-built" { } '' + [ -e "${wrapper}/share/applications/fastfetch-guix.desktop" ] && [ -x "${wrapper}/bin/${config.wrappers.fastfetch-guix.executableName}" ] && touch $out + ''; + }; +}