Skip to content

qdiskinfo: add themes#336023

Merged
pbsds merged 2 commits intoNixOS:masterfrom
RoyDubnium:qdiskinfo-themes
Oct 11, 2024
Merged

qdiskinfo: add themes#336023
pbsds merged 2 commits intoNixOS:masterfrom
RoyDubnium:qdiskinfo-themes

Conversation

@RoyDubnium
Copy link
Contributor

Description of changes

Adds support for the CrystalDiskInfo themes that QDiskInfo supports.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@ofborg ofborg bot added 11.by: package-maintainer This PR was created by a maintainer of all the package it changes. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. labels Aug 20, 2024
@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one person. label Aug 20, 2024
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Sep 27, 2024
@RoyDubnium
Copy link
Contributor Author

Merge conflict resolved

@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Sep 29, 2024
@pbsds
Copy link
Member

pbsds commented Oct 6, 2024

please rebase rather than merge from master

@RoyDubnium
Copy link
Contributor Author

Done

@pbsds
Copy link
Member

pbsds commented Oct 7, 2024

This one took me a bit of time to understand, but the moment i renamed isTheme to isThemed it suddenly clicked.
The theme input is prone to collide with a future package (theme-sh already exists), and the logic around rightCharacter and "custom" is in my opinion a bit too convoluted.
I took the liberty of refactoring the theming logic to use an attribute set, and provide all the packaged themes via the passthru. In the process it also became trivial to add tests for each theme.

The usage pattern thus becomes

qdiskinfo.override { themeBundle = qdiskinfo.themeBundles.aoi; }

I ran the tests:

/nix/store/dlm4hxy3r8bvzv8s6xfjmzpb71m7fpkl-qdiskinfo-aoi-0.3
/nix/store/d55svzcp5ndjd89pk241lmwvr6jzhhbi-qdiskinfo-kureikei-0.3
/nix/store/x8jfbdldds1awd6csrv06gnpip3i395b-qdiskinfo-kureikeiAsyuihira-0.3
/nix/store/4qh8kb07vf2aa7qvw8lacwqgwamjbi09-qdiskinfo-kureikeiBikini-0.3
/nix/store/7bzb26l6pq1lks59b2lq8c9x5jgiri9c-qdiskinfo-kureikeiHasumikaoru-0.3
/nix/store/jz1hza6jvs4mqgznm57nn43rsmbxs2cf-qdiskinfo-kureikeiHomebuiltComputer-0.3
/nix/store/nkr4m5cv6jlbyzsb9f801q9hz614jk4x-qdiskinfo-kureikeiKohakumuro-0.3
/nix/store/xx4j5zi6rasmjn5dx4r3iyqx3vffbdzz-qdiskinfo-kureikeiKosake-0.3
/nix/store/r5smrgwha8lkilqkd44ypazh37adw6wf-qdiskinfo-kureikeiKunimi-0.3
/nix/store/b00nrsq2l978zzj2hmwd5ka7bcgwmzj7-qdiskinfo-kureikeiMaru-0.3
/nix/store/zp6rjc08spdvv12jv7rb5v3v4mpbvkpw-qdiskinfo-kureikeiMugya-0.3
/nix/store/0gyirm001sh42wayh36823anh7bhqz5s-qdiskinfo-kureikeiNanatunatu-0.3
/nix/store/h2x2awgbl5blcqzbxrkkqjzjx8q4wgw1-qdiskinfo-kureikeiNekopan-0.3
/nix/store/6zfbaqk8wga9bss17nqg3cnbvw6xk5py-qdiskinfo-kureikeiNyamco-0.3
/nix/store/v1l31fwfjmijhgrrws5adp0dk1kck3lv-qdiskinfo-kureikeiPoyoyonchihiro-0.3
/nix/store/v5xr53mdzizg1sj62xmpa9hlv0l564dl-qdiskinfo-kureikeiPresent-0.3
/nix/store/mbm4gsyrwy57spjhyni326jpwjpf2wq1-qdiskinfo-kureikeiRecoding-0.3
/nix/store/hb4iyf6xkfhkj38hcjnmy1wd20nbir6p-qdiskinfo-kureikeiRecodingKimiya-0.3
/nix/store/pwvh5x1j3bxvmpi05qpcanilwimbzwy9-qdiskinfo-kureikeiShitimiNanami-0.3
/nix/store/xzfkd05y2zzr8c9d950lrsx2hhib8qhc-qdiskinfo-kureikeiSummerKimono-0.3
/nix/store/561w7hapqk5gsyxcy24by4mqyw91yc5c-qdiskinfo-kureikeiTakiOuno-0.3
/nix/store/ddshwy5insf6izzkmhqz3qm5jqmy1zi7-qdiskinfo-kureikeiTori-0.3
/nix/store/pa6v5li0h33j697qk671rkr4bv3g1bs2-qdiskinfo-kureikeiUniform-0.3
/nix/store/x7vrsj97ks69xxw09aisqa1lp8xxzkxh-qdiskinfo-kureikeiYoite-0.3
/nix/store/8bh0ghw4xhmw3qvnr3ypwybvcbj21587-qdiskinfo-shizuku-0.3
/nix/store/q6f86dsfacvyyvgiwp1953daq4v6jlc6-qdiskinfo-shizuku5thAnniversary-0.3
/nix/store/w7i0bwvg6yfgmicyc32wv11p7cx2h99d-qdiskinfo-shizuku7thAnniversary-0.3
/nix/store/7f32ax4wyhh1zrwvfhgjfvw4gm0nfsyb-qdiskinfo-shizukuDate-0.3
/nix/store/da0b1gq4v3bvcim5lbzrv1fcl505lhh4-qdiskinfo-shizukuHanabi-0.3
/nix/store/yhhj6c2assabvp1fl9mw99siwqmwwzjx-qdiskinfo-shizukuHaregi-0.3
/nix/store/irq6x7dzwi3cfql7zgcb3698alnnps3n-qdiskinfo-shizukuHeianKomachi-0.3
/nix/store/n1n51pahjll11d1ax1vqb8n6zha1nc47-qdiskinfo-shizukuHotaru-0.3
/nix/store/kphn1lhicv70j1w1hg8f43zk5x8vb1d8-qdiskinfo-shizukuIdol-0.3
/nix/store/p0ms5v493224a8pkvwrwpa9rbibi1c12-qdiskinfo-shizukuKotatsu-0.3
/nix/store/lsqcpj34ikmhj6191hbiffxynyxmg2ac-qdiskinfo-shizukuKotatsuNight-0.3
/nix/store/m7nhyw62bv0wyrkdbs38d9x20qdrhb5w-qdiskinfo-shizukuLiteratureGirl-0.3
/nix/store/i6xcy4f3cbcy2wy6mdl20siwfaljlwg6-qdiskinfo-shizukuLiteratureGirlWithGlasses-0.3
/nix/store/iaw9vnqzvl4gvb4wd1r076kby0982bla-qdiskinfo-shizukuMaidCool-0.3
/nix/store/5lb7bdnn2lnkrrf5a40ka6475iw7477q-qdiskinfo-shizukuMaidCute-0.3
/nix/store/818zrcqf398qsgpclvrkkgg1wrmbxr2i-qdiskinfo-shizukuMeijiMizugi-0.3
/nix/store/2120s03mcjyf3h116698cpp9ki28x8jc-qdiskinfo-shizukuMermaid-0.3
/nix/store/a2mwl33dg2qs6l8b996wyxv5ncz35jyp-qdiskinfo-shizukuMiko-0.3
/nix/store/7dypi1p6qhack3wx395vldp29xx2bppy-qdiskinfo-shizukuOffice-0.3
/nix/store/7ihv344ymdyh1jgixqz4x3dkpld8yi4j-qdiskinfo-shizukuSakura-0.3
/nix/store/y6lrmik4lywvc0hsz1p6wkhfldn3lha8-qdiskinfo-shizukuTaishoRoman-0.3
/nix/store/m2q3fkqn09vk1hlnyikzbfpjv50h45ac-qdiskinfo-shizukuTeaBreak-0.3
/nix/store/7jsx40zvak79j0n4m34lbsh8y7xj42c8-qdiskinfo-shizukuWebRadio-0.3
/nix/store/1wiw7rfxdwr36ds19ii1afp88cn613xn-qdiskinfo-shizukuWinterLamp-0.3

I'm leaning towards wanting to inline sources.nix into themes.nix, but i leave that decision to you.

My proposed patch
diff --git a/pkgs/by-name/qd/qdiskinfo/package.nix b/pkgs/by-name/qd/qdiskinfo/package.nix
index 907d5c087362..343503f24082 100644
--- a/pkgs/by-name/qd/qdiskinfo/package.nix
+++ b/pkgs/by-name/qd/qdiskinfo/package.nix
@@ -6,36 +6,28 @@
   fetchzip,
   cmake,
   qt6,
-  theme ? "",
-  customBgDark ? "",
-  customBgLight ? "",
-  customStatusPath ? "",
-  customSrc ? "",
-  customRightCharacter ? false,
+  qdiskinfo,
+  themeBundle ? null,
 }:

 let
-  isTheme = theme != null && theme != "";
-
-  rightCharacter =
-    (builtins.elem theme [
-      "aoi"
-      "shizukuTeaBreak"
-    ])
-    || customRightCharacter;
-  themeSources = import ./sources.nix { inherit fetchzip; };
-  themes = import ./themes.nix {
-    inherit
-      customBgDark
-      customBgLight
-      customSrc
-      customStatusPath
-      lib
-      themeSources
-      ;
-  };
+  isThemed = themeBundle != null && themeBundle != { };
+  themeBundle' = {
+    rightCharacter = false;
+  } // themeBundle;
 in
-assert !isTheme || lib.attrsets.hasAttrByPath [ theme ] themes;
+
+# check theme bundle
+assert
+  isThemed
+  -> (
+    themeBundle' ? src
+    && themeBundle' ? paths.bgDark
+    && themeBundle' ? paths.bgLight
+    && themeBundle' ? paths.status
+    && themeBundle' ? rightCharacter
+  );
+
 stdenv.mkDerivation (finalAttrs: {
   pname = "qdiskinfo";
   version = "0.3";
@@ -64,33 +56,50 @@ stdenv.mkDerivation (finalAttrs: {
     [
       "-DQT_VERSION_MAJOR=6"
     ]
-    ++ lib.optionals isTheme [ "-DINCLUDE_OPTIONAL_RESOURCES=ON" ]
-    ++ (if rightCharacter then [ "-DCHARACTER_IS_RIGHT=ON" ] else [ "-DCHARACTER_IS_RIGHT=OFF" ]);
+    ++ lib.optionals isThemed [ "-DINCLUDE_OPTIONAL_RESOURCES=ON" ]
+    ++ (
+      if themeBundle'.rightCharacter then
+        [ "-DCHARACTER_IS_RIGHT=ON" ]
+      else
+        [ "-DCHARACTER_IS_RIGHT=OFF" ]
+    );

   postUnpack = ''
     cp -r $sourceRoot $TMPDIR/src
     sourceRoot=$TMPDIR/src
   '';
-  patchPhase = lib.optionalString isTheme ''
-    export SRCPATH=${themes."${theme}".src}/CdiResource/themes/
+  patchPhase = lib.optionalString isThemed ''
+    export SRCPATH=${themeBundle'.src}/CdiResource/themes/
     export DESTPATH=$sourceRoot/dist/theme/
     mkdir -p $DESTPATH
-    if [ -n "${themes."${theme}".paths.bgDark}" ]; then
-      cp $SRCPATH/${themes."${theme}".paths.bgDark} $DESTPATH/bg_dark.png
+    if [ -n "${themeBundle'.paths.bgDark}" ]; then
+      cp $SRCPATH/${themeBundle'.paths.bgDark} $DESTPATH/bg_dark.png
     fi
-    if  [ -n "${themes."${theme}".paths.bgLight}" ]; then
-      cp $SRCPATH/${themes."${theme}".paths.bgLight} $DESTPATH/bg_light.png
+    if  [ -n "${themeBundle'.paths.bgLight}" ]; then
+      cp $SRCPATH/${themeBundle'.paths.bgLight} $DESTPATH/bg_light.png
     fi
-    cp $SRCPATH/${themes."${theme}".paths.status}/SDdiskStatusBad-300.png $DESTPATH/bad.png
-    cp $SRCPATH/${themes."${theme}".paths.status}/SDdiskStatusCaution-300.png $DESTPATH/caution.png
-    cp $SRCPATH/${themes."${theme}".paths.status}/SDdiskStatusGood-300.png $DESTPATH/good.png
-    cp $SRCPATH/${themes."${theme}".paths.status}/SDdiskStatusUnknown-300.png $DESTPATH/unknown.png
+    cp $SRCPATH/${themeBundle'.paths.status}/SDdiskStatusBad-300.png $DESTPATH/bad.png
+    cp $SRCPATH/${themeBundle'.paths.status}/SDdiskStatusCaution-300.png $DESTPATH/caution.png
+    cp $SRCPATH/${themeBundle'.paths.status}/SDdiskStatusGood-300.png $DESTPATH/good.png
+    cp $SRCPATH/${themeBundle'.paths.status}/SDdiskStatusUnknown-300.png $DESTPATH/unknown.png
   '';
   postInstall = ''
     wrapProgram $out/bin/QDiskInfo \
       --suffix PATH : ${smartmontools}/bin
   '';

+  passthru =
+    let
+      themeSources = import ./sources.nix { inherit fetchzip; };
+    in
+    rec {
+      themeBundles = import ./themes.nix { inherit themeSources; };
+      tests = lib.flip lib.mapAttrs themeBundles (
+        themeName: themeBundle:
+        (qdiskinfo.override { inherit themeBundle; }).overrideAttrs { pname = "qdiskinfo-${themeName}"; }
+      );
+    };
+
   meta = {
     description = "CrystalDiskInfo alternative for Linux";
     homepage = "https://github.com/edisionnano/QDiskInfo";
diff --git a/pkgs/by-name/qd/qdiskinfo/themes.nix b/pkgs/by-name/qd/qdiskinfo/themes.nix
index 6cec442206d0..f02f4ce2887b 100644
--- a/pkgs/by-name/qd/qdiskinfo/themes.nix
+++ b/pkgs/by-name/qd/qdiskinfo/themes.nix
@@ -1,11 +1,4 @@
-{
-  customBgDark,
-  customBgLight,
-  customSrc,
-  customStatusPath,
-  lib,
-  themeSources,
-}:
+{ themeSources }:

 {
   aoi = {
@@ -15,14 +8,7 @@
       bgLight = "Aoi/AoiBackground-300.png";
       status = "Aoi";
     };
-  };
-  custom = {
-    src = themeSources."${customSrc}";
-    paths = {
-      bgDark = customBgDark;
-      bgLight = customBgLight;
-      status = customStatusPath;
-    };
+    rightCharacter = true;
   };
   kureikei = {
     src = themeSources.kureikei;
@@ -383,6 +369,7 @@
       bgLight = "ShizukuTeaBreak/ShizukuBackground-300.png";
       status = "Shizuku";
     };
+    rightCharacter = true;
   };
   shizukuWebRadio = {
     src = themeSources.shizuku;

How to apply (pick one):

a. curl -L "https://gist.github.com/pbsds/1db1f19cb7b98dc587180a418f1e10f6/raw" | git apply
b. copy the patch above, run git apply, paste (typically ctrl-shift-v), press enter, then end the input with ctrl-d_

@pbsds pbsds mentioned this pull request Oct 7, 2024
13 tasks
@RoyDubnium
Copy link
Contributor Author

RoyDubnium commented Oct 7, 2024

Thanks for the help! However, it seems that ofborg does not like the new changes, and the package fails to build. The source of the error appears to be from the definition of "cmakeFlags", but I can't see what the problem is.

@RoyDubnium
Copy link
Contributor Author

Well, the error no longer occurs. Not sure why it was happening in the first place, but it seems to be working now. Package builds with no issues I can find.

@pbsds pbsds merged commit 2e0f5c3 into NixOS:master Oct 11, 2024
@RoyDubnium RoyDubnium deleted the qdiskinfo-themes branch October 13, 2024 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. 11.by: package-maintainer This PR was created by a maintainer of all the package it changes. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants