Repository: NixOS/nixpkgs
Pull request #396506:  nixosTests: init cosmic modules
Author: login: thefossguy
Labels: name: 6.topic: nixos
description: Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS
name: 10.rebuild-darwin: 0
description: This PR does not cause any packages to rebuild on Darwin.
name: 10.rebuild-linux: 0
description: This PR does not cause any packages to rebuild on Linux.
name: 12.approvals: 2
description: This PR was reviewed and approved by two persons.
Created: 2025-04-06T08:00:27Z | Merged: 2025-04-07T14:48:46Z

## Things done

Supersedes #396131.
Given we want to test autologin and xwayland support (once #395817 gets merged), that brings us to 4 unique tests. So, instead of more than one out-of-sync test file, handle all logic in a single file. I hope I didn't go overboard with this.

- Built on platform(s)
  - [x] x86_64-linux
  - [ ] aarch64-linux
  - [ ] x86_64-darwin
  - [ ] aarch64-darwin
- For non-Linux: Is sandboxing enabled in `nix.conf`? (See [Nix manual](https://nixos.org/manual/nix/stable/command-ref/conf-file.html))
  - [ ] `sandbox = relaxed`
  - [ ] `sandbox = true`
- [ ] Tested, as applicable:
  - [NixOS test(s)](https://nixos.org/manual/nixos/unstable/index.html#sec-nixos-tests) (look inside [nixos/tests](https://github.com/NixOS/nixpkgs/blob/master/nixos/tests))
  - and/or [package tests](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#package-tests)
  - or, for functions and "core" functionality, tests in [lib/tests](https://github.com/NixOS/nixpkgs/blob/master/lib/tests) or [pkgs/test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/test)
  - made sure NixOS tests are [linked](https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#linking-nixos-module-tests-to-a-package) to the relevant packages
- [ ] 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](https://github.com/Mic92/nixpkgs-review#usage)
- [ ] Tested basic functionality of all binary files (usually in `./result/bin/`)
- [25.05 Release Notes](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2505.section.md) (or backporting [24.11](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2411.section.md) and [25.05](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2505.section.md) 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](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md).

<!--
To help with the large amounts of pull requests, we would appreciate your
reviews of other pull requests, especially simple package updates. Just leave a
comment describing what you have tested in the relevant package/service.
Reviewing helps to reduce the average time-to-merge for everyone.
Thanks a lot if you do!

List of open PRs: https://github.com/NixOS/nixpkgs/pulls
Reviewing guidelines: https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#reviewing-contributions
-->

---

cc: @nyabinary @a-kenji @HeitorAugustoLN @GaetanLepage @ahoneybun

Add a :+1: [reaction] to [pull requests you find important].

[reaction]: https://github.blog/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/
[pull requests you find important]: https://github.com/NixOS/nixpkgs/pulls?q=is%3Aopen+sort%3Areactions-%2B1-desc



Diff:
diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix
index c9de7c0c02495..d6ae0fd54243e 100644
--- a/nixos/tests/all-tests.nix
+++ b/nixos/tests/all-tests.nix
@@ -338,6 +338,30 @@ in
   containers-unified-hierarchy = handleTest ./containers-unified-hierarchy.nix { };
   convos = handleTest ./convos.nix { };
   corerad = handleTest ./corerad.nix { };
+  cosmic = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic";
+    _module.args.enableAutologin = false;
+    _module.args.enableXWayland = true;
+  };
+  cosmic-autologin = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-autologin";
+    _module.args.enableAutologin = true;
+    _module.args.enableXWayland = true;
+  };
+  cosmic-noxwayland = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-noxwayland";
+    _module.args.enableAutologin = false;
+    _module.args.enableXWayland = false;
+  };
+  cosmic-autologin-noxwayland = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-autologin-noxwayland";
+    _module.args.enableAutologin = true;
+    _module.args.enableXWayland = false;
+  };
   coturn = handleTest ./coturn.nix { };
   couchdb = handleTest ./couchdb.nix { };
   crabfit = handleTest ./crabfit.nix { };
diff --git a/nixos/tests/cosmic.nix b/nixos/tests/cosmic.nix
new file mode 100644
index 0000000000000..44df8fb1da490
--- /dev/null
+++ b/nixos/tests/cosmic.nix
@@ -0,0 +1,131 @@
+{
+  config,
+  lib,
+  testName,
+  enableAutologin,
+  enableXWayland,
+  ...
+}:
+
+{
+  name = testName;
+
+  meta = {
+    platforms = lib.platforms.linux;
+    maintainers = with lib.maintainers; [
+      thefossguy
+    ];
+  };
+
+  nodes.machine = {
+    imports = [ ./common/user-account.nix ];
+
+    services = {
+      # For `cosmic-store` to be added to `environment.systemPackages`
+      # and for it to work correctly because Flatpak is a runtime
+      # dependency of `cosmic-store`.
+      flatpak.enable = true;
+
+      displayManager.cosmic-greeter.enable = true;
+      desktopManager.cosmic = {
+        enable = true;
+        xwayland.enable = enableXWayland;
+      };
+    };
+
+    services.displayManager.autoLogin = lib.mkIf enableAutologin {
+      enable = true;
+      user = "alice";
+    };
+
+    environment.systemPackages = with config.node.pkgs; [
+      # These two packages are used to check if a window was opened
+      # under the COSMIC session or not. Kinda important.
+      # TODO: Move the check from the test module to
+      # `nixos/lib/test-driver/src/test_driver/machine.py` so more
+      # Wayland-only testing can be done using the existing testing
+      # infrastructure.
+      jq
+      lswt
+    ];
+
+    # So far, all COSMIC tests launch a few GUI applications. In doing
+    # so, the default allocated memory to the guest of 1024M quickly
+    # poses a very high risk of an OOM-shutdown which is worse than an
+    # OOM-kill. Because now, the test failed, but not for a genuine
+    # reason, but an OOM-shutdown. That's an inconclusive failure
+    # which might possibly mask an actual failure. Not enabling
+    # systemd-oomd because we need said applications running for a
+    # few seconds. So instead, bump the allocated memory to the guest
+    # from 1024M to 4x; 4096M.
+    virtualisation.memorySize = 4096;
+  };
+
+  testScript =
+    { nodes, ... }:
+    let
+      cfg = nodes.machine;
+      user = cfg.users.users.alice;
+      DISPLAY = lib.strings.optionalString enableXWayland (
+        if enableAutologin then "DISPLAY=:0" else "DISPLAY=:1"
+      );
+    in
+    ''
+      #testName: ${testName}
+    ''
+    + (
+      if (enableAutologin) then
+        ''
+          with subtest("cosmic-greeter initialisation"):
+              machine.wait_for_unit("graphical.target")
+        ''
+      else
+        ''
+          from time import sleep
+
+          machine.wait_for_unit("graphical.target")
+          machine.wait_until_succeeds("pgrep --uid ${toString cfg.users.users.cosmic-greeter.name} --full cosmic-greeter")
+          # Sleep for 10 seconds for ensuring that `greetd` loads the
+          # password prompt for the login screen properly.
+          sleep(10)
+
+          with subtest("cosmic-session login"):
+              machine.send_chars("${user.password}\n", delay=0.2)
+        ''
+    )
+    + ''
+          # _One_ of the final processes to start as part of the
+          # `cosmic-session` target is the Workspaces applet. So, wait
+          # for it to start. The process existing means that COSMIC
+          # now handles any opened windows from now on.
+          machine.wait_until_succeeds("pgrep --uid ${toString user.uid} --full 'cosmic-panel-button com.system76.CosmicWorkspaces'")
+
+      # The best way to test for Wayland and XWayland is to launch
+      # the GUI applications and see the results yourself.
+      with subtest("Launch applications"):
+          # key: binary_name
+          # value: "app-id" as reported by `lswt`
+          gui_apps_to_launch = {}
+
+          # We want to ensure that the first-party applications
+          # start/launch properly.
+          gui_apps_to_launch['cosmic-edit'] = 'com.system76.CosmicEdit'
+          gui_apps_to_launch['cosmic-files'] = 'com.system76.CosmicFiles'
+          gui_apps_to_launch['cosmic-player'] = 'com.system76.CosmicPlayer'
+          gui_apps_to_launch['cosmic-settings'] = 'com.system76.CosmicSettings'
+          gui_apps_to_launch['cosmic-store'] = 'com.system76.CosmicStore'
+          gui_apps_to_launch['cosmic-term'] = 'com.system76.CosmicTerm'
+
+          for gui_app, app_id in gui_apps_to_launch.items():
+              machine.succeed(f"su - ${user.name} -c 'WAYLAND_DISPLAY=wayland-1 XDG_RUNTIME_DIR=/run/user/${toString user.uid} ${DISPLAY} {gui_app} >&2 &'", timeout=5)
+              # Nix builds the following non-commented expression to the following:
+              #                              `su - alice -c 'WAYLAND_DISPLAY=wayland-1 XDG_RUNTIME_DIR=/run/user/1000 lswt --json | jq ".toplevels" | grep "^    \\"app-id\\": \\"{app_id}\\"$"' `
+              machine.wait_until_succeeds(f''''su - ${user.name} -c 'WAYLAND_DISPLAY=wayland-1 XDG_RUNTIME_DIR=/run/user/${toString user.uid} lswt --json | jq ".toplevels" | grep "^    \\"app-id\\": \\"{app_id}\\"$"' '''', timeout=30)
+              machine.succeed(f"pkill {gui_app}", timeout=5)
+
+      machine.succeed("echo 'test completed succeessfully' > /${testName}")
+      machine.copy_from_vm('/${testName}')
+
+      machine.shutdown()
+    '';
+}


Reviews:
user: login: JohnRTitor
body: https://github.com/NixOS/nixpkgs/pull/396131#issuecomment-2781494544

Lemme know if this is ready to merge @nyabinary 
state: APPROVED
author_association: MEMBER
submitted_at: 2025-04-06T17:35:53Z
user: login: JohnRTitor
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-06T17:51:53Z
user: login: a-kenji
body: Not a fan of essentially having the test configuration in `all-tests`.
Edit: Ah, nvm it actually seems recommended by the documentation.
state: APPROVED
author_association: MEMBER
submitted_at: 2025-04-06T18:37:30Z
user: login: nyabinary
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-07T01:29:55Z
user: login: thefossguy
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-07T02:48:01Z
user: login: JohnRTitor
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-07T03:59:48Z
user: login: thefossguy
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-07T04:06:29Z
user: login: GaetanLepage
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-07T05:15:44Z
user: login: JohnRTitor
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-07T08:37:27Z
user: login: JohnRTitor
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-07T13:09:30Z
user: login: thefossguy
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-07T13:30:09Z
user: login: JohnRTitor
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-07T14:11:17Z
user: login: thefossguy
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-07T14:20:42Z
user: login: JohnRTitor
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-07T14:32:07Z
user: login: thefossguy
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-07T14:34:16Z

Review comments:
diff_hunk: @@ -338,6 +338,30 @@ in
   containers-unified-hierarchy = handleTest ./containers-unified-hierarchy.nix { };
   convos = handleTest ./convos.nix { };
   corerad = handleTest ./corerad.nix { };
+  cosmic = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic";
+    _module.args.enableAutologin = false;
+    _module.args.enableXWayland = true;
+  };
+  cosmic-autologin = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-autologin";
+    _module.args.enableAutologin = true;
+    _module.args.enableXWayland = true;
+  };
+  cosmic-noxwayland = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-noxwayland";
+    _module.args.enableAutologin = false;
+    _module.args.enableXWayland = false;
+  };
+  cosmic-autologin-noxwayland = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-autologin-noxwayland";
+    _module.args.enableAutologin = true;
+    _module.args.enableXWayland = false;
+  };
path: nixos/tests/all-tests.nix
user: login: JohnRTitor
body: We need to inherit these in package passthru.tests, otherwise fine.
created_at: 2025-04-06T17:51:53Z
author_association: MEMBER
diff_hunk: @@ -338,6 +338,30 @@ in
   containers-unified-hierarchy = handleTest ./containers-unified-hierarchy.nix { };
   convos = handleTest ./convos.nix { };
   corerad = handleTest ./corerad.nix { };
+  cosmic = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic";
+    _module.args.enableAutologin = false;
+    _module.args.enableXWayland = true;
+  };
+  cosmic-autologin = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-autologin";
+    _module.args.enableAutologin = true;
+    _module.args.enableXWayland = true;
+  };
+  cosmic-noxwayland = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-noxwayland";
+    _module.args.enableAutologin = false;
+    _module.args.enableXWayland = false;
+  };
+  cosmic-autologin-noxwayland = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-autologin-noxwayland";
+    _module.args.enableAutologin = true;
+    _module.args.enableXWayland = false;
+  };
path: nixos/tests/all-tests.nix
user: login: thefossguy
body: I haven't yet understood `passthru` in nix properly. Can you point me to an example on what you are recommending here?
created_at: 2025-04-07T02:48:01Z
author_association: MEMBER
diff_hunk: @@ -338,6 +338,30 @@ in
   containers-unified-hierarchy = handleTest ./containers-unified-hierarchy.nix { };
   convos = handleTest ./convos.nix { };
   corerad = handleTest ./corerad.nix { };
+  cosmic = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic";
+    _module.args.enableAutologin = false;
+    _module.args.enableXWayland = true;
+  };
+  cosmic-autologin = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-autologin";
+    _module.args.enableAutologin = true;
+    _module.args.enableXWayland = true;
+  };
+  cosmic-noxwayland = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-noxwayland";
+    _module.args.enableAutologin = false;
+    _module.args.enableXWayland = false;
+  };
+  cosmic-autologin-noxwayland = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-autologin-noxwayland";
+    _module.args.enableAutologin = true;
+    _module.args.enableXWayland = false;
+  };
path: nixos/tests/all-tests.nix
user: login: JohnRTitor
body: https://nixos.org/manual/nixpkgs/stable/#var-passthru-tests-nixos

Let's say, cosmic-comp is used in nixosTest.cosmic, so you'd add:

```nix
{ nixosTests, ... }:
{
  # ...
  passthru.tests = {
    inherit (nixosTests) cosmic;
  };
}
```

to the .nix file of cosmic. 

After this running `cosmic-comp.passthru.tests` would run all the tests defined there. Usually Ofborg auto runs these tests after building the package. 
created_at: 2025-04-07T03:59:48Z
author_association: MEMBER
diff_hunk: @@ -338,6 +338,30 @@ in
   containers-unified-hierarchy = handleTest ./containers-unified-hierarchy.nix { };
   convos = handleTest ./convos.nix { };
   corerad = handleTest ./corerad.nix { };
+  cosmic = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic";
+    _module.args.enableAutologin = false;
+    _module.args.enableXWayland = true;
+  };
+  cosmic-autologin = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-autologin";
+    _module.args.enableAutologin = true;
+    _module.args.enableXWayland = true;
+  };
+  cosmic-noxwayland = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-noxwayland";
+    _module.args.enableAutologin = false;
+    _module.args.enableXWayland = false;
+  };
+  cosmic-autologin-noxwayland = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-autologin-noxwayland";
+    _module.args.enableAutologin = true;
+    _module.args.enableXWayland = false;
+  };
path: nixos/tests/all-tests.nix
user: login: thefossguy
body: Interesting. I didn't know this!

If I understand this correctly, once we add a `passthru.tests` to the `cosmic-comp` package, everytime it is updated, the tests mentioned inside it will be triggered by Ofborg in GitHub PR actions. Right?

If the above assumption is true, I think we need to add these tests to all packages consumed by the tests (and by extension, the packages used by the modules). Is that the correct assumption as well?
created_at: 2025-04-07T04:06:29Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,127 @@
+{
+  lib,
+  pkgs,
path: nixos/tests/cosmic.nix
user: login: GaetanLepage
body: ```
evaluation warning: Do not use the `pkgs` module argument in tests you want to run on darwin. It is ambiguous, and many tests are broken because of it. If you need to use a package on the VM host, use `hostPkgs`. Otherwise, use `config.node.pkgs`, or `config.nodes.<name>.nixpkgs.pkgs`.
```
I get this warning at evaluation.
created_at: 2025-04-07T05:15:44Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,127 @@
+{
+  lib,
+  pkgs,
path: nixos/tests/cosmic.nix
user: login: JohnRTitor
body: I would suggest specifically setting meta.platforms to Linux. 
created_at: 2025-04-07T08:37:27Z
author_association: MEMBER
diff_hunk: @@ -338,6 +338,30 @@ in
   containers-unified-hierarchy = handleTest ./containers-unified-hierarchy.nix { };
   convos = handleTest ./convos.nix { };
   corerad = handleTest ./corerad.nix { };
+  cosmic = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic";
+    _module.args.enableAutologin = false;
+    _module.args.enableXWayland = true;
+  };
+  cosmic-autologin = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-autologin";
+    _module.args.enableAutologin = true;
+    _module.args.enableXWayland = true;
+  };
+  cosmic-noxwayland = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-noxwayland";
+    _module.args.enableAutologin = false;
+    _module.args.enableXWayland = false;
+  };
+  cosmic-autologin-noxwayland = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-autologin-noxwayland";
+    _module.args.enableAutologin = true;
+    _module.args.enableXWayland = false;
+  };
path: nixos/tests/all-tests.nix
user: login: JohnRTitor
body: > everytime it is updated, the tests mentioned inside it will be triggered by Ofborg in GitHub PR actions

yes

> we need to add these tests to all packages consumed by the tests

also yes, but only cosmic packages of course.
created_at: 2025-04-07T13:09:30Z
author_association: MEMBER
diff_hunk: @@ -338,6 +338,30 @@ in
   containers-unified-hierarchy = handleTest ./containers-unified-hierarchy.nix { };
   convos = handleTest ./convos.nix { };
   corerad = handleTest ./corerad.nix { };
+  cosmic = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic";
+    _module.args.enableAutologin = false;
+    _module.args.enableXWayland = true;
+  };
+  cosmic-autologin = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-autologin";
+    _module.args.enableAutologin = true;
+    _module.args.enableXWayland = true;
+  };
+  cosmic-noxwayland = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-noxwayland";
+    _module.args.enableAutologin = false;
+    _module.args.enableXWayland = false;
+  };
+  cosmic-autologin-noxwayland = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-autologin-noxwayland";
+    _module.args.enableAutologin = true;
+    _module.args.enableXWayland = false;
+  };
path: nixos/tests/all-tests.nix
user: login: thefossguy
body: @JohnRTitor and what about the packages? I assume we need to add `passthru.tests` to all packages used by the `cosmic.nix` and `cosmic-greeter.nix` modules?
created_at: 2025-04-07T13:30:09Z
author_association: MEMBER
diff_hunk: @@ -338,6 +338,30 @@ in
   containers-unified-hierarchy = handleTest ./containers-unified-hierarchy.nix { };
   convos = handleTest ./convos.nix { };
   corerad = handleTest ./corerad.nix { };
+  cosmic = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic";
+    _module.args.enableAutologin = false;
+    _module.args.enableXWayland = true;
+  };
+  cosmic-autologin = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-autologin";
+    _module.args.enableAutologin = true;
+    _module.args.enableXWayland = true;
+  };
+  cosmic-noxwayland = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-noxwayland";
+    _module.args.enableAutologin = false;
+    _module.args.enableXWayland = false;
+  };
+  cosmic-autologin-noxwayland = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-autologin-noxwayland";
+    _module.args.enableAutologin = true;
+    _module.args.enableXWayland = false;
+  };
path: nixos/tests/all-tests.nix
user: login: JohnRTitor
body: Not all cosmic packages, for example, we are not testing cosmic-files functionality.
created_at: 2025-04-07T14:11:17Z
author_association: MEMBER
diff_hunk: @@ -338,6 +338,30 @@ in
   containers-unified-hierarchy = handleTest ./containers-unified-hierarchy.nix { };
   convos = handleTest ./convos.nix { };
   corerad = handleTest ./corerad.nix { };
+  cosmic = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic";
+    _module.args.enableAutologin = false;
+    _module.args.enableXWayland = true;
+  };
+  cosmic-autologin = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-autologin";
+    _module.args.enableAutologin = true;
+    _module.args.enableXWayland = true;
+  };
+  cosmic-noxwayland = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-noxwayland";
+    _module.args.enableAutologin = false;
+    _module.args.enableXWayland = false;
+  };
+  cosmic-autologin-noxwayland = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-autologin-noxwayland";
+    _module.args.enableAutologin = true;
+    _module.args.enableXWayland = false;
+  };
path: nixos/tests/all-tests.nix
user: login: thefossguy
body: Yes and no. We are testing it by checking if it launches or not. It may crash for some reason. That is something we want to monitor for. In that case, is a `passthru.tests` still necessary?
created_at: 2025-04-07T14:20:42Z
author_association: MEMBER
diff_hunk: @@ -338,6 +338,30 @@ in
   containers-unified-hierarchy = handleTest ./containers-unified-hierarchy.nix { };
   convos = handleTest ./convos.nix { };
   corerad = handleTest ./corerad.nix { };
+  cosmic = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic";
+    _module.args.enableAutologin = false;
+    _module.args.enableXWayland = true;
+  };
+  cosmic-autologin = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-autologin";
+    _module.args.enableAutologin = true;
+    _module.args.enableXWayland = true;
+  };
+  cosmic-noxwayland = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-noxwayland";
+    _module.args.enableAutologin = false;
+    _module.args.enableXWayland = false;
+  };
+  cosmic-autologin-noxwayland = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-autologin-noxwayland";
+    _module.args.enableAutologin = true;
+    _module.args.enableXWayland = false;
+  };
path: nixos/tests/all-tests.nix
user: login: JohnRTitor
body: Yes. 
created_at: 2025-04-07T14:32:07Z
author_association: MEMBER
diff_hunk: @@ -338,6 +338,30 @@ in
   containers-unified-hierarchy = handleTest ./containers-unified-hierarchy.nix { };
   convos = handleTest ./convos.nix { };
   corerad = handleTest ./corerad.nix { };
+  cosmic = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic";
+    _module.args.enableAutologin = false;
+    _module.args.enableXWayland = true;
+  };
+  cosmic-autologin = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-autologin";
+    _module.args.enableAutologin = true;
+    _module.args.enableXWayland = true;
+  };
+  cosmic-noxwayland = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-noxwayland";
+    _module.args.enableAutologin = false;
+    _module.args.enableXWayland = false;
+  };
+  cosmic-autologin-noxwayland = runTest {
+    imports = [ ./cosmic.nix ];
+    _module.args.testName = "cosmic-autologin-noxwayland";
+    _module.args.enableAutologin = true;
+    _module.args.enableXWayland = false;
+  };
path: nixos/tests/all-tests.nix
user: login: thefossguy
body: Ack and **thank you**, will add it once we merge this. Don't want to cause too much noise. :)
created_at: 2025-04-07T14:34:16Z
author_association: MEMBER

PR comments:
user: login: thefossguy
created_at: 2025-04-06T08:02:21Z
body: Created a separate PR because I wasn't sure force pushing this in #396131 would be a good idea. Plus, helps keep two conversations separate.
author_association: MEMBER
user: login: nyabinary
created_at: 2025-04-06T17:49:34Z
body: > [#396131 (comment)](https://github.com/NixOS/nixpkgs/pull/396131#issuecomment-2781494544)
> 
> Lemme know if this is ready to merge @nyabinary

Yeah this is fine :3 
author_association: CONTRIBUTOR
user: login: thefossguy
created_at: 2025-04-07T04:01:02Z
body: Given that there are enough approvals, let's merge this? I'll handle the `passthru` later on. Merging this will fix the cache miss.
author_association: MEMBER
user: login: JohnRTitor
created_at: 2025-04-07T04:06:24Z
body: > Merging this will fix the cache miss.

You mean merging the other PR (https://github.com/NixOS/nixpkgs/pull/395817). I am just [building the tests](https://github.com/JohnRTitor/nixpkgs-review-gha/actions/runs/14300443387). 
author_association: MEMBER
user: login: thefossguy
created_at: 2025-04-07T04:11:22Z
body: > > Merging this will fix the cache miss.
> 
> You mean merging the other PR (#395817). I am just [building the tests](https://github.com/JohnRTitor/nixpkgs-review-gha/actions/runs/14300443387).

No. At the moment, the `cosmic-comp` package is built with XWayland support by Hydra because that's what is in the package definition. But the NixOS module has an _unconditional override_ to disable XWayland support for the `cosmic-comp` package. That's what is triggering a rebuild on users' machines. But hydra isn't consuming the overridden package in any way, hence causing the cache miss.

So, if we add a test, hydra will build that overridden `cosmic-comp` package and we will resolve the cache miss that way. But ideally we want to merge #395817 too because it removes an unnecessary "build flag" (`useXWayland`).
author_association: MEMBER
user: login: thefossguy
created_at: 2025-04-07T04:13:42Z
body: Should we limit the test only to Linux? It's not like we are in any capacity to support Darwin. Unsure if upstream supports Darwin either.
author_association: MEMBER
user: login: JohnRTitor
created_at: 2025-04-07T04:56:33Z
body: https://logs.ofborg.org/?key=nixos/nixpkgs.396506&attempt_id=ffb5dfd1-0f5a-41aa-b80c-efcebdf17310

Test on aarch64-linux fails. 
author_association: MEMBER
user: login: GaetanLepage
created_at: 2025-04-07T06:20:25Z
body: Tests built fine on `x86_64-linux` but are either hanging or failing on `aarch64-linux`.

Here is a first failure log (`autologin-noxwayland`): https://paste.glepage.com/raw/sloth-wolf-pig

cc @RossComputerGuy for your knowledge about Cosmic+NixOS+`aarch64-linux`

EDIT: I have just realized that they are actually marked as broken on this platform.
author_association: CONTRIBUTOR
user: login: GaetanLepage
created_at: 2025-04-07T06:29:54Z
body: ## `nixpkgs-review` result

Generated using [`nixpkgs-review`](https://github.com/Mic92/nixpkgs-review).

Command: `nixpkgs-review pr 396506 --package nixosTests.cosmic --package nixosTests.cosmic-autologin-noxwayland --package nixosTests.cosmic-noxwayland --package nixosTests.cosmic-autologin`

---
### `x86_64-linux`
<details>
  <summary>:white_check_mark: 4 tests built:</summary>
  <ul>
    <li>nixosTests.cosmic</li>
    <li>nixosTests.cosmic-autologin</li>
    <li>nixosTests.cosmic-autologin-noxwayland</li>
    <li>nixosTests.cosmic-noxwayland</li>
  </ul>
</details>

---
### `aarch64-linux`
<details>
  <summary>:white_check_mark: 4 tests built:</summary>
  <ul>
    <li>nixosTests.cosmic</li>
    <li>nixosTests.cosmic-autologin</li>
    <li>nixosTests.cosmic-autologin-noxwayland</li>
    <li>nixosTests.cosmic-noxwayland</li>
  </ul>
</details>

---
### `x86_64-darwin`
<details>
  <summary>:fast_forward: 4 packages marked as broken and skipped:</summary>
  <ul>
    <li>nixosTests.cosmic</li>
    <li>nixosTests.cosmic-autologin</li>
    <li>nixosTests.cosmic-autologin-noxwayland</li>
    <li>nixosTests.cosmic-noxwayland</li>
  </ul>
</details>

---
### `aarch64-darwin`
<details>
  <summary>:fast_forward: 4 packages marked as broken and skipped:</summary>
  <ul>
    <li>nixosTests.cosmic</li>
    <li>nixosTests.cosmic-autologin</li>
    <li>nixosTests.cosmic-autologin-noxwayland</li>
    <li>nixosTests.cosmic-noxwayland</li>
  </ul>
</details>

author_association: CONTRIBUTOR
user: login: thefossguy
created_at: 2025-04-07T09:28:01Z
body: > https://logs.ofborg.org/?key=nixos/nixpkgs.396506&attempt_id=ffb5dfd1-0f5a-41aa-b80c-efcebdf17310
> 
> Test on aarch64-linux fails.

Yeah, that's because of this:

```
(finished: sending keys 'foobar\n', in 1.42 seconds)
machine: waiting for success: pgrep --uid 1000 --full 'cosmic-panel-button com.system76.CosmicWorkspaces'
machine # [  440.031975] cosmic-session[1045]: Starting cosmic-session
machine # [  440.435153] cosmic-greeter[1025]: 2025-04-06T08:41:55.448357Z  WARN cosmic_comp::backend::kms: Failed to add device /dev/dri/card0: Failed to optain file descriptor for drm device: /dev/dri/card0
machine # [  440.110290] cosmic-session[1045]: starting process ' COSMIC_SESSION_SOCK=12 cosmic-comp '
machine # [  440.503429] cosmic-greeter[1025]: Caused by:
machine # [  440.531943] cosmic-greeter[1025]:     Failed to open device: Resource temporarily unavailable (os error 11)
machine # [  440.181858] cosmic-session[1045]: 2025-04-06T08:41:55.217633Z  INFO cosmic_session: Starting cosmic-session
machine # [  440.209682] cosmic-session[1045]: 2025-04-06T08:41:55.342603Z  INFO launch_pad: starting process ' COSMIC_SESSION_SOCK=12 cosmic-comp '
machine # [  440.603766] .cosmic-comp-wrapped[1025]: Failed to add device /dev/dri/card0: Failed to optain file descriptor for drm device: /dev/dri/card0
machine # 
machine # Caused by:
machine #     Failed to open device: Resource temporarily unavailable (os error 11)
```

It fails locally for me on my RK3588 and M4 devices too. I tried adding the following options and yet I still get a missing `/dev/dri/cardX` error:

```
    virtualisation.graphics = true;
    virtualisation.qemu.options = [
      "-device virtio-gpu-pci"
    ];
```

I'm not a QEMU expert so not sure how I should enable 3d-accel.
author_association: MEMBER
user: login: thefossguy
created_at: 2025-04-07T10:05:58Z
body: Commits I just pushed have added linux under `meta.platforms` and `s/pkgs/hostPkgs/g`.
author_association: MEMBER
user: login: thefossguy
created_at: 2025-04-07T10:11:42Z
body: Re failing AArch64 tests:

I added the following to the `nixos/tests/cosmic.nix` file:
```
    virtualisation.qemu.options = [
      "-display dbus,gl=on"
    ];
```

And it gave me the following error:
```
qemu-system-aarch64: OpenGL support was not enabled in this build of QEMU
```
author_association: MEMBER
user: login: thefossguy
created_at: 2025-04-07T10:22:32Z
body: I realized that the correct way to get `pkgs` is with `config.node.pkgs` and not `hostPkgs`. Pushed again.
author_association: MEMBER
user: login: thefossguy
created_at: 2025-04-07T13:29:08Z
body: It appears that QEMU is not at fault here. I've opened an issue upstream: https://github.com/pop-os/cosmic-comp/issues/1343
author_association: MEMBER