Skip to content

nixosTests/cosmic: move core logic into a dedicated script#519448

Open
thefossguy wants to merge 3 commits into
NixOS:masterfrom
thefossguy:cosmic-test-improvement
Open

nixosTests/cosmic: move core logic into a dedicated script#519448
thefossguy wants to merge 3 commits into
NixOS:masterfrom
thefossguy:cosmic-test-improvement

Conversation

@thefossguy
Copy link
Copy Markdown
Member

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

@thefossguy
Copy link
Copy Markdown
Member Author

At the moment, the test fails because I added a new test for handling polkit degradation in the second commit.

But, once I apply https://github.com/pop-os/cosmic-osd/commit/cb9698c8536df05b7086115a071a3d3838b245f2.patch?full_index=1 to cosmic-osd, this new test passes.

@thefossguy
Copy link
Copy Markdown
Member Author

Part of #508829

@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: COSMIC COSMIC is a software platform for designing beautiful user experiences labels May 12, 2026
@a-kenji
Copy link
Copy Markdown
Member

a-kenji commented May 12, 2026

Maybe create a nixos/tests/cosmic/* directory in this PR or a follow up?

@thefossguy
Copy link
Copy Markdown
Member Author

I'm up for whatever we decide. Do we have any official guidelines on this?

@thefossguy
Copy link
Copy Markdown
Member Author

Additionally, I'd like to wait at least today before merging to see if upstream tags a new release. That way, we can get the cosmic-osd fix in, and can confidently verify that none of the tests fail.

@salva09
Copy link
Copy Markdown
Contributor

salva09 commented May 13, 2026

I created #519587 for the tagged release that should have the cosmic-osd fix. Is there a way I could run the new test?

@thefossguy thefossguy marked this pull request as draft May 13, 2026 02:02
@a-kenji
Copy link
Copy Markdown
Member

a-kenji commented May 13, 2026

I'm up for whatever we decide. Do we have any official guidelines on this?

I would guess its OK to just do it.

@thefossguy thefossguy force-pushed the cosmic-test-improvement branch 2 times, most recently from 11f2f8e to 4c4b064 Compare May 14, 2026 07:40
@thefossguy thefossguy changed the title nixosTests/cosmic: move NixOS VM test's core logic from testScript into dedicated script nixosTests/cosmic: move core logic into a dedicated script May 16, 2026
@thefossguy thefossguy force-pushed the cosmic-test-improvement branch from 4c4b064 to be7d86b Compare May 16, 2026 06:21
@thefossguy thefossguy marked this pull request as ready for review May 16, 2026 06:21
@thefossguy
Copy link
Copy Markdown
Member Author

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 519448 --extra-nixpkgs-config '{ allowBroken = false; }' --additional-package nixosTests.cosmic-noxwayland --additional-package nixosTests.cosmic-autologin --additional-package nixosTests.cosmic --additional-package nixosTests.cosmic-autologin-noxwayland
Commit: be7d86b57f927b91333fc691590a3db898581a91


x86_64-linux

✅ 4 tests built:
  • nixosTests.cosmic
  • nixosTests.cosmic-autologin
  • nixosTests.cosmic-autologin-noxwayland
  • nixosTests.cosmic-noxwayland

@thefossguy
Copy link
Copy Markdown
Member Author

For some reason, the tests now fail on aarch64-linux. Digging into it.

@thefossguy thefossguy marked this pull request as draft May 18, 2026 16:33
@thefossguy thefossguy force-pushed the cosmic-test-improvement branch 3 times, most recently from 449fde1 to 26087cf Compare May 19, 2026 14:07
@thefossguy
Copy link
Copy Markdown
Member Author

Aha, the tests were failing on aarch64 because software rending was too slow for cosmic-osd's pop-up dialog to render. Added a few more guardrails as well.

@thefossguy thefossguy marked this pull request as ready for review May 19, 2026 14:15
@thefossguy
Copy link
Copy Markdown
Member Author

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 519448 --extra-nixpkgs-config '{ allowBroken = false; }' --additional-package nixosTests.cosmic-autologin --additional-package nixosTests.cosmic-noxwayland --additional-package nixosTests.cosmic-autologin-noxwayland --additional-package nixosTests.cosmic
Commit: 26087cf158dfc13702b84316f2593f13b726d128


aarch64-linux

✅ 4 tests built:
  • nixosTests.cosmic
  • nixosTests.cosmic-autologin
  • nixosTests.cosmic-autologin-noxwayland
  • nixosTests.cosmic-noxwayland

@thefossguy
Copy link
Copy Markdown
Member Author

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 519448 --extra-nixpkgs-config '{ allowBroken = false; }' --additional-package nixosTests.cosmic-noxwayland --additional-package nixosTests.cosmic-autologin-noxwayland --additional-package nixosTests.cosmic --additional-package nixosTests.cosmic-autologin
Commit: 26087cf158dfc13702b84316f2593f13b726d128


x86_64-linux

✅ 4 tests built:
  • nixosTests.cosmic
  • nixosTests.cosmic-autologin
  • nixosTests.cosmic-autologin-noxwayland
  • nixosTests.cosmic-noxwayland

@thefossguy thefossguy force-pushed the cosmic-test-improvement branch from 26087cf to 7b412cc Compare May 20, 2026 08:25
@a-kenji
Copy link
Copy Markdown
Member

a-kenji commented May 22, 2026

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 519448 --additional-package nixosTests.cosmic-autologin-noxwayland --additional-package nixosTests.cosmic-noxwayland --additional-package nixosTests.cosmic-autologin --additional-package nixosTests.cosmic
Commit: 7b412ccc0f87c410fbaeba763b085e9d912be95a


x86_64-linux

✅ 4 tests built:
  • nixosTests.cosmic
  • nixosTests.cosmic-autologin
  • nixosTests.cosmic-autologin-noxwayland
  • nixosTests.cosmic-noxwayland

Comment thread nixos/tests/cosmic/default.nix
@thefossguy thefossguy requested review from alyssais and nyabinary May 23, 2026 05:32
Copy link
Copy Markdown
Member

@a-kenji a-kenji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Tested.

@nixpkgs-ci nixpkgs-ci Bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label May 23, 2026
@thefossguy
Copy link
Copy Markdown
Member Author

I'd appreciate a review from you both, if possible, @alyssais @nyabinary.

@alyssais
Copy link
Copy Markdown
Member

Maybe you could move the Nix file in a separate earlier commit, so git can recognize the rename?

@thefossguy
Copy link
Copy Markdown
Member Author

This is a git mv. But due to a large enough delta, it doesn't register as a rename. Want me to split it into two commits instead? One that renames it and the second with the actual change.

@alyssais
Copy link
Copy Markdown
Member

alyssais commented May 27, 2026 via email

@thefossguy thefossguy force-pushed the cosmic-test-improvement branch from 7b412cc to 7398dd7 Compare May 27, 2026 16:39
@thefossguy
Copy link
Copy Markdown
Member Author

Pushed the changes :)

Copy link
Copy Markdown
Member

@alyssais alyssais left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still really difficult to review. Not adding a new test in the same commit as porting the old ones might help, but even without all the polkit stuff I still have to wonder if this is really worth the explosion in length…

I haven't tried, so maybe it doesn't make sense, but would it be possible to avoid the long timeout by running a separate instance of a Python program for each application we want to test?

Comment thread nixos/tests/cosmic/default.nix Outdated
@thefossguy
Copy link
Copy Markdown
Member Author

This is still really difficult to review. Not adding a new test in the same commit as porting the old ones might help

Sorry about that, I'll split it further.

but even without all the polkit stuff I still have to wonder if this is really worth the explosion in length...

The primary reason behind this migration of test logic from testScript to a dedicated python script that is auto-started is this:

  1. The COSMIC DE session is different than the backdoor from testScript, forcing us to be creative in launching apps for our test.
  2. This worked up until we needed to add polkit testing, where we really need to either recreate the COSMIC DE session or launch it inside the session.
  3. I would be happy to keep polkit in testScript but I intend to add more tests in future (logout, re-login, lock, unlock, notifications, etc) and that complexity isn't worth it in testScript IMHO.

So yes, it isn't worth it right now given we haven't changed much, but I'd rather refactor now than later. The test for polkit was added as a matter of urgency since it is very much a core component that every user expects to work properly.

I haven't tried, so maybe it doesn't make sense, but would it be possible to avoid the long timeout by running a separate instance of a Python program for each application we want to test?

Do you mean some sort of multi-threading/parallelism with like a thread per app? We can't do this without also increasing our virtualisation.memorySize from 4GiB to something un-OOM-able.

@thefossguy thefossguy force-pushed the cosmic-test-improvement branch 2 times, most recently from ed323aa to a6e422d Compare May 28, 2026 09:13
@thefossguy thefossguy force-pushed the cosmic-test-improvement branch from a6e422d to 010f24d Compare May 28, 2026 13:01
@thefossguy thefossguy force-pushed the cosmic-test-improvement branch from 010f24d to 86fa08d Compare May 28, 2026 13:41
@thefossguy thefossguy requested a review from alyssais May 29, 2026 09:22
Copy link
Copy Markdown
Contributor

@nyabinary nyabinary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm :3

@nixpkgs-ci nixpkgs-ci Bot added 12.approvals: 2 This PR was reviewed and approved by two persons. and removed 12.approvals: 1 This PR was reviewed and approved by one person. labels May 29, 2026
@thefossguy
Copy link
Copy Markdown
Member Author

@alyssais do you have any current concerns unaddressed and/or any new concerns with this PR? I'd love to have this merged before #524670 so it can be tested with more coverage. :)

@thefossguy
Copy link
Copy Markdown
Member Author

If there are no concerns, could someone please merge this?

Copy link
Copy Markdown
Member

@Pandapip1 Pandapip1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM, just a few non-blocking nitpicks

Comment on lines +13 to +24
emptyPDF = config.node.pkgs.stdenvNoCC.mkDerivation {
name = "empty-pdf";
dontUnpack = true;
nativeBuildInputs = [ config.node.pkgs.imagemagick ];
buildPhase = ''
magick xc:none -page Letter empty.pdf
'';
installPhase = ''
mkdir $out
mv empty.pdf $out/empty.pdf
'';
};
Copy link
Copy Markdown
Member

@Pandapip1 Pandapip1 Jun 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about:

Suggested change
emptyPDF = config.node.pkgs.stdenvNoCC.mkDerivation {
name = "empty-pdf";
dontUnpack = true;
nativeBuildInputs = [ config.node.pkgs.imagemagick ];
buildPhase = ''
magick xc:none -page Letter empty.pdf
'';
installPhase = ''
mkdir $out
mv empty.pdf $out/empty.pdf
'';
};
emptyPDF = config.node.pkgs.stdenvNoCC.mkDerivation {
name = "empty.pdf";
dontUnpack = true;
dontConfigure = true;
nativeBuildInputs = [ config.node.pkgs.imagemagick ];
buildPhase = ''
runHook preBuild
magick xc:none -page Letter empty.pdf
runHook postBuild
'';
installPhase = ''
runHook preInstall
cp empty.pdf $out
runHook postInstall
'';
};

There's also an argument to be made for adding this to by-name.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to do this for a derivation that simply creates an empty PDF? I'm fine either way, though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well imo

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already precedent for helper/test derivations living in the main package set in the form of emptyFile and emptyDirectory.

cosmicTestDesktop = config.node.pkgs.makeDesktopItem {
name = "cosmicTest";
desktopName = "COSMIC NixOS VM test (${testName})";
exec = "${cosmicTest}/bin/cosmicTest";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
exec = "${cosmicTest}/bin/cosmicTest";
exec = lib.getExe' cosmicTest "cosmicTest";

That being said, this might even be better off as

Suggested change
exec = "${cosmicTest}/bin/cosmicTest";
exec = "cosmicTest";

See #308324

ydotool_daemon_socket_path = f"{xdg_runtime_dir}/.ydotool_socket"
ydotool_daemon_process = subprocess.Popen(
[
f"{cli_args.ydotool_drv_store_path}/bin/ydotoold",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we're not relying on PATH here? It would simplify this script quite a bit.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure that there was a reason during my testing but it may have changed after the cleanup. Let me test this out and get back.

notification_watcher_exists = False
while time.monotonic() < notification_watcher_wait_deadline:
busctl_process = subprocess.run(
["busctl", "--user", "status", "com.system76.CosmicStatusNotifierWatcher"],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we relying on the PATH here and not elsewhere?

cosmicTest = config.node.pkgs.writeShellScriptBin "cosmicTest" ''
exec ${config.node.pkgs.python3Minimal}/bin/python3 ${./test-script.py} \
--log-file-path ${logFilePath} \
--cosmic-reader-pdf ${emptyPDF}/empty.pdf \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be replaced with

Suggested change
--cosmic-reader-pdf ${emptyPDF}/empty.pdf \
--cosmic-reader-pdf ${emptyPDF} \

or

Suggested change
--cosmic-reader-pdf ${emptyPDF}/empty.pdf \
--cosmic-reader-pdf ${config.node.pkgs.emptyPDF} \

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 1st suggestion doesn't apply here because the installPhase copies the PDF to $out/empty.pdf. We could simply copy it to $out, will test that.

As for the 2nd suggestion, that doesn't work since emptyPDF is part of the let-in block, not part of nixpkgs' packages. And I don't see a reason to add it to pkgs/by-name for a derivation that doesn't provide an executable binary. I'm not opposed. Just not sure if adding it to nixkpgs is the right call here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is specifically if #519448 (comment) is applied

# Use `writeShellScriptBin` instead of `writeShellScript` so that the
# process name in the journald log appears as 'cosmicTest[$pid]'
cosmicTest = config.node.pkgs.writeShellScriptBin "cosmicTest" ''
exec ${config.node.pkgs.python3Minimal}/bin/python3 ${./test-script.py} \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
exec ${config.node.pkgs.python3Minimal}/bin/python3 ${./test-script.py} \
exec ${lib.getExe config.node.pkgs.python3Minimal} ${./test-script.py} \

@thefossguy
Copy link
Copy Markdown
Member Author

Thanks for the review @Pandapip1! I'll update this PR soon-ish.

@Pandapip1
Copy link
Copy Markdown
Member

Honestly given how much this PR has already been stalled, I'd probably prefer to see this merged first, then the improvements can be made in follow-up PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: COSMIC COSMIC is a software platform for designing beautiful user experiences 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. 12.approvals: 2 This PR was reviewed and approved by two persons.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants