Repository: ngi-nix/ngipkgs
Pull request #817: mCaptcha: Projects-old -> Projects
Author: login: Axler1
Created: 2025-04-14T17:51:32Z | Merged: 2025-04-17T07:55:21Z

To resolve https://github.com/ngi-nix/ngipkgs/issues/736


Diff:
diff --git a/projects-old/mCaptcha/default.nix b/projects-old/mCaptcha/default.nix
deleted file mode 100644
index b580f4cc2..000000000
--- a/projects-old/mCaptcha/default.nix
+++ /dev/null
@@ -1,16 +0,0 @@
-{
-  pkgs,
-  lib,
-  sources,
-}@args:
-{
-  packages = { inherit (pkgs) mcaptcha mcaptcha-cache; };
-  nixos = {
-    modules.services.mcaptcha = ./service.nix;
-    tests = {
-      create-locally = import ./tests/create-locally.nix args;
-      bring-your-own-services = import ./tests/bring-your-own-services.nix args;
-    };
-    examples = null;
-  };
-}
diff --git a/projects/mCaptcha/default.nix b/projects/mCaptcha/default.nix
new file mode 100644
index 000000000..b86d709db
--- /dev/null
+++ b/projects/mCaptcha/default.nix
@@ -0,0 +1,49 @@
+{
+  lib,
+  pkgs,
+  sources,
+}@args:
+
+{
+  metadata = {
+    summary = "Privacy-friendly Proof of Work (PoW) based CAPTCHA system";
+    subgrants = [
+      "mCaptcha"
+    ];
+    links = {
+      website = {
+        text = "Official website";
+        url = "https://mcaptcha.org/";
+      };
+      documentation = {
+        text = "Official documentation";
+        url = "https://mcaptcha.org/docs/";
+      };
+    };
+  };
+
+  nixos.modules.services = {
+    mcaptcha = {
+      name = "mcaptcha";
+      module = ./services/mcaptcha/module.nix;
+      examples.basic = null;
+      links = {
+        setup = {
+          text = "Development setup";
+          url = "https://github.com/mCaptcha/mCaptcha/blob/master/docs/HACKING.md";
+        };
+        deployment = {
+          text = "Deployment instructions";
+          url = "https://github.com/mCaptcha/mCaptcha/blob/master/docs/DEPLOYMENT.md";
+        };
+        configuration = {
+          text = "Configuration instructions";
+          url = "https://github.com/mCaptcha/mCaptcha/blob/master/docs/CONFIGURATION.md";
+        };
+      };
+    };
+  };
+
+  nixos.tests.bring-your-own-services = import ./services/mcaptcha/tests/bring-your-own-services.nix args;
+  nixos.tests.create-locally = import ./services/mcaptcha/tests/create-locally.nix args;
+}
diff --git a/projects-old/mCaptcha/service.nix b/projects/mCaptcha/services/mcaptcha/module.nix
similarity index 100%
rename from projects-old/mCaptcha/service.nix
rename to projects/mCaptcha/services/mcaptcha/module.nix
diff --git a/projects-old/mCaptcha/tests/bring-your-own-services.nix b/projects/mCaptcha/services/mcaptcha/tests/bring-your-own-services.nix
similarity index 100%
rename from projects-old/mCaptcha/tests/bring-your-own-services.nix
rename to projects/mCaptcha/services/mcaptcha/tests/bring-your-own-services.nix
diff --git a/projects-old/mCaptcha/tests/create-locally.nix b/projects/mCaptcha/services/mcaptcha/tests/create-locally.nix
similarity index 100%
rename from projects-old/mCaptcha/tests/create-locally.nix
rename to projects/mCaptcha/services/mcaptcha/tests/create-locally.nix


Reviews:
user: login: eljamm
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-14T20:26:27Z
user: login: eljamm
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-15T07:26:54Z
user: login: eljamm
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-16T07:50:00Z
user: login: eljamm
body: Looks good, nice!
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-17T07:54:42Z

Review comments:
diff_hunk: @@ -0,0 +1,66 @@
+{
+  lib,
+  pkgs,
+  sources,
+}@args:
+
+{
+  # NOTE:
+  # - Each program/service must have at least one example
+  # - Set attributes to `null` to indicate that they're needed, but not available
+  # - Remove comments that are only relevant to the template when using it
path: projects/mcaptcha/default.nix
user: login: eljamm
body: ```suggestion
```
created_at: 2025-04-14T20:01:39Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,66 @@
+{
+  lib,
+  pkgs,
+  sources,
+}@args:
+
+{
+  # NOTE:
+  # - Each program/service must have at least one example
+  # - Set attributes to `null` to indicate that they're needed, but not available
+  # - Remove comments that are only relevant to the template when using it
+  metadata = {
+    summary = "mCaptcha is a backend component for a CAPTCHA system designed to provide a seamless user experience without unnecessary complexity.";
path: projects/mcaptcha/default.nix
user: login: eljamm
body: Let's keep it short

```suggestion
    summary = "Privacy-friendly Proof of Work (PoW) based CAPTCHA system";
```
created_at: 2025-04-14T20:03:35Z
author_association: CONTRIBUTOR
path: projects/mcaptcha/programs/mcaptcha/tests/basic.nix
user: login: eljamm
body: Let's remove this file, since it's not testing anything
created_at: 2025-04-14T20:05:15Z
author_association: CONTRIBUTOR
path: projects/mcaptcha/services/mcaptcha/module.nix
user: login: eljamm
body: Please delete the `projects-old/mCaptcha` directory
created_at: 2025-04-14T20:06:10Z
author_association: CONTRIBUTOR
path: projects/mcaptcha/default.nix
user: login: eljamm
body: The directory should be `projects/mCaptcha`, not `projects/mcaptcha`. Please mind the letter's case.
created_at: 2025-04-14T20:07:33Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,66 @@
+{
+  lib,
+  pkgs,
+  sources,
+}@args:
+
+{
+  # NOTE:
+  # - Each program/service must have at least one example
+  # - Set attributes to `null` to indicate that they're needed, but not available
+  # - Remove comments that are only relevant to the template when using it
+  metadata = {
+    summary = "mCaptcha is a backend component for a CAPTCHA system designed to provide a seamless user experience without unnecessary complexity.";
+    subgrants = [
+      "mCaptcha"
+    ];
+    links = {
+      website = {
+        text = "Official website";
+        url = "https://mcaptcha.org/";
+      };
+      documentation = {
+        text = "Official documentation";
+        url = "https://mcaptcha.org/docs/";
+      };
+    };
+  };
+
+  nixos.modules.services = {
+    mcaptcha = {
+      name = "mcaptcha";
+      module = ./services/mcaptcha/module.nix;
+      examples.basic = {
+        module = ./services/mcaptcha/examples/basic.nix;
+        description = "Basic example of mCaptcha service.";
+        tests.basic = import ./services/mcaptcha/tests/basic.nix args;
+      };
+      # examples = {
+      #   bringService = {
+      #     description = "use a database and other services running on a different node";
+      #     module = ./services/mcaptcha/examples/basic.nix;
+      #     tests.bringService = import ./services/mcaptcha/tests/bring-your-own-services.nix args;
+      #   };
+      #   createLocally = {
+      #     description = "use a database and other services running on the same node";
+      #     module = ./services/mcaptcha/examples/basic.nix;
+      #     tests.createLocally = import ./services/mcaptcha/tests/create-locally.nix args;
+      #   };
+      # };
path: projects/mcaptcha/default.nix
user: login: eljamm
body: Let's just make these free-standing tests (see [here](https://github.com/ngi-nix/ngipkgs/pull/817#discussion_r2042875298))

```suggestion
```
created_at: 2025-04-14T20:21:58Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,66 @@
+{
+  lib,
+  pkgs,
+  sources,
+}@args:
+
+{
+  # NOTE:
+  # - Each program/service must have at least one example
+  # - Set attributes to `null` to indicate that they're needed, but not available
+  # - Remove comments that are only relevant to the template when using it
+  metadata = {
+    summary = "mCaptcha is a backend component for a CAPTCHA system designed to provide a seamless user experience without unnecessary complexity.";
+    subgrants = [
+      "mCaptcha"
+    ];
+    links = {
+      website = {
+        text = "Official website";
+        url = "https://mcaptcha.org/";
+      };
+      documentation = {
+        text = "Official documentation";
+        url = "https://mcaptcha.org/docs/";
+      };
+    };
+  };
+
+  nixos.modules.services = {
+    mcaptcha = {
+      name = "mcaptcha";
+      module = ./services/mcaptcha/module.nix;
+      examples.basic = {
+        module = ./services/mcaptcha/examples/basic.nix;
+        description = "Basic example of mCaptcha service.";
+        tests.basic = import ./services/mcaptcha/tests/basic.nix args;
+      };
+      # examples = {
+      #   bringService = {
+      #     description = "use a database and other services running on a different node";
+      #     module = ./services/mcaptcha/examples/basic.nix;
+      #     tests.bringService = import ./services/mcaptcha/tests/bring-your-own-services.nix args;
+      #   };
+      #   createLocally = {
+      #     description = "use a database and other services running on the same node";
+      #     module = ./services/mcaptcha/examples/basic.nix;
+      #     tests.createLocally = import ./services/mcaptcha/tests/create-locally.nix args;
+      #   };
+      # };
+      links = {
+        setup = {
+          text = "Development setup";
+          url = "https://github.com/mCaptcha/mCaptcha/blob/master/docs/HACKING.md";
+        };
+        deployment = {
+          text = "Deployment instructions";
+          url = "https://github.com/mCaptcha/mCaptcha/blob/master/docs/DEPLOYMENT.md";
+        };
+        configuration = {
+          text = "Configuration instructions";
+          url = "https://github.com/mCaptcha/mCaptcha/blob/master/docs/CONFIGURATION.md";
+        };
+      };
+    };
+  };
path: projects/mcaptcha/default.nix
user: login: eljamm
body: ```suggestion
  };
  
  nixos.tests.bring-your-own-services = import ./services/mcaptcha/tests/bring-your-own-services.nix args;
  nixos.tests.create-locally = import ./services/mcaptcha/tests/create-locally.nix args;
  nixos.tests.basic = import ./services/mcaptcha/tests/basic.nix args;
```
created_at: 2025-04-14T20:22:42Z
author_association: CONTRIBUTOR
path: projects/mcaptcha/services/mcaptcha/examples/basic.nix
user: login: eljamm
body: From the error you got, we know that this example is not going to be enough to set up the service. Lets just delete this file and set the example attribute to null `examples.basic = null;` to indicate that it's something we want, but is not available, yet.

```shellSession
       error: attribute 'database' missing
       at /nix/store/nmsrnrwd7yw953rsr23myp2xcjwcvixp-source/projects/mcaptcha/services/mcaptcha/module.nix:155:81:
          154|         assertion = (!cfg.database.createLocally) -> (cfg.settings.database.username != null);
          155|         message = "If `${opt.database.createLocally}` is not specified, then `${opt.settings.database.username}` must be specified";
             |                                                                                 ^
          156|       }
```

created_at: 2025-04-14T20:25:03Z
author_association: CONTRIBUTOR
path: projects/mcaptcha/programs/mcaptcha/examples/basic.nix
user: login: eljamm
body: Same comment as the service example. Let's remove this since it's not simple to set up.
created_at: 2025-04-14T20:25:38Z
author_association: CONTRIBUTOR
diff_hunk: @@ -25,6 +25,7 @@ in
       imports = [
         sources.modules.ngipkgs
         sources.modules.services.mcaptcha
+        sources.examples.mcaptcha.basic
path: projects/mCaptcha/services/mcaptcha/tests/bring-your-own-services.nix
user: login: eljamm
body: If `examples.basic = null;` then there is no example to import.

```suggestion
```
created_at: 2025-04-15T07:23:49Z
author_association: CONTRIBUTOR
path: projects/mCaptcha/services/mcaptcha/tests/basic.nix
user: login: eljamm
body: I though the basic test did something, but apparently that wasn't the case. Let's just remove this file.
created_at: 2025-04-15T07:26:01Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,50 @@
+{
+  lib,
+  pkgs,
+  sources,
+}@args:
+
+{
+  metadata = {
+    summary = "Privacy-friendly Proof of Work (PoW) based CAPTCHA system";
+    subgrants = [
+      "mCaptcha"
+    ];
+    links = {
+      website = {
+        text = "Official website";
+        url = "https://mcaptcha.org/";
+      };
+      documentation = {
+        text = "Official documentation";
+        url = "https://mcaptcha.org/docs/";
+      };
+    };
+  };
+
+  nixos.modules.services = {
+    mcaptcha = {
+      name = "mcaptcha";
+      module = ./services/mcaptcha/module.nix;
+      examples.basic = null;
+      links = {
+        setup = {
+          text = "Development setup";
+          url = "https://github.com/mCaptcha/mCaptcha/blob/master/docs/HACKING.md";
+        };
+        deployment = {
+          text = "Deployment instructions";
+          url = "https://github.com/mCaptcha/mCaptcha/blob/master/docs/DEPLOYMENT.md";
+        };
+        configuration = {
+          text = "Configuration instructions";
+          url = "https://github.com/mCaptcha/mCaptcha/blob/master/docs/CONFIGURATION.md";
+        };
+      };
+    };
+  };
+
+  nixos.tests.bring-your-own-services = import ./services/mcaptcha/tests/bring-your-own-services.nix args;
+  nixos.tests.create-locally = import ./services/mcaptcha/tests/create-locally.nix args;
+  nixos.tests.basic = import ./services/mcaptcha/tests/basic.nix args;
path: projects/mCaptcha/default.nix
user: login: eljamm
body: ```suggestion
```
created_at: 2025-04-15T07:26:46Z
author_association: CONTRIBUTOR
path: projects/mCaptcha/programs/mcaptcha/module.nix
user: login: eljamm
body: We don't need `projects/mCaptcha/programs` since I think the `mcaptcha` and `mcaptcha-cache` artefacts only run properly in the context of the [service module](https://github.com/ngi-nix/ngipkgs/blob/0c7d3b5828333210d0ab0317667f5cec4333cd84/projects-old/mCaptcha/service.nix).
created_at: 2025-04-16T07:50:00Z
author_association: CONTRIBUTOR

PR comments:
user: login: Axler1
created_at: 2025-04-14T17:56:54Z
body: @eljamm , could you please review it? I am encountering some problems when running the example and the test.

For the test, I get the following error when executing this command: nix --extra-experimental-features "nix-command flakes" build .\#checks.x86_64-linux.projects/mcaptcha/nixos/tests/basic

```
error: suspicious ownership or permission on '/nix/store/i9dmdq6rxhapj7jndvi19h60lr430qcf-boot.json.drv.chroot/root/nix/store/235hwkfrhxjgzwms9cis8h58f7ilb3qq-boot.json' for output 'out'; rejecting this build output
error: 1 dependencies of derivation '/nix/store/56gi4friqw2yp1jbv00bfkfwldwdz812-nixos-system-mcaptcha-test.drv' failed to build
error: 1 dependencies of derivation '/nix/store/l07w7albsckfnqxf7bg8aifv2x7k99yj-nixos-vm.drv' failed to build
error: 1 dependencies of derivation '/nix/store/vrhbhxni5gjdqq9b8sgbjsd6nmxdfxr0-nixos-test-driver-test-of-mcaptcha-with-database-and-other-services-running-on-a-different-node.drv' failed to build
error: 1 dependencies of derivation '/nix/store/3svh4s6ychfxhgpzgv4nkc78a3cai8lk-vm-test-run-test-of-mcaptcha-with-database-and-other-services-running-on-a-different-node.drv' failed to build
```

For the example, I get the following error when executing this command: nix --extra-experimental-features "nix-command flakes" build .\#checks.x86_64-linux.projects/mcaptcha/nixos/examples/basic

```
error:
       … while calling the 'head' builtin
         at /nix/store/dn9smqqg60pn1a3c1sk2m0m8iakm84zs-source/lib/attrsets.nix:1534:13:
         1533|           if length values == 1 || pred here (elemAt values 1) (head values) then
         1534|             head values
             | ^ |
         1535|           else

       … while evaluating the attribute 'value'
         at /nix/store/dn9smqqg60pn1a3c1sk2m0m8iakm84zs-source/lib/modules.nix:1083:7:
         1082|     // {
         1083|       value = addErrorContext "while evaluating the option `${showOption loc}':" value;
             | ^ |
         1084|       inherit (res.defsFinal') highestPrio;

       … while evaluating the option `system.build.toplevel':

       … while evaluating definitions from `/nix/store/dn9smqqg60pn1a3c1sk2m0m8iakm84zs-source/nixos/modules/system/activation/top-level.nix':

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: attribute 'database' missing
       at /nix/store/k94aj0a7wig0s4s91yd8rvb9hkdv5pqq-source/projects/mcaptcha/services/mcaptcha/module.nix:155:81:
          154|         assertion = (!cfg.database.createLocally) -> (cfg.settings.database.username != null);
          155|         message = "If `${opt.database.createLocally}` is not specified, then `${opt.settings.database.username}` must be specified";
             | ^ |
          156|       }
```

author_association: CONTRIBUTOR
user: login: Axler1
created_at: 2025-04-15T04:04:51Z
body: @eljamm I still have issues when I run the tests :(

`nix --extra-experimental-features "nix-command flakes" build .#checks.x86_64-linux.projects/mCaptcha/nixos/tests/create-locally`

```
error: suspicious ownership or permission on '/nix/store/i9dmdq6rxhapj7jndvi19h60lr430qcf-boot.json.drv.chroot/root/nix/store/235hwkfrhxjgzwms9cis8h58f7ilb3qq-boot.json' for output 'out'; rejecting this build output
error: 1 dependencies of derivation '/nix/store/iy8b5a9sl47vn9mxp45b9fag7jah8a4k-nixos-system-mcaptcha-test.drv' failed to build
error: 1 dependencies of derivation '/nix/store/f4fwfnmdwkc9im554gmrg4qyq16gx311-nixos-vm.drv' failed to build
error: 1 dependencies of derivation '/nix/store/js0c8lf973fb1zd36dfsqv6zcskkd5c6-nixos-test-driver-test-of-mcaptcha-with-database-and-other-services-all-running-on-the-same-node.drv' failed to build
error: 1 dependencies of derivation '/nix/store/ds2fkgn56chm300q4q89rhkc5r2ahm7s-vm-test-run-test-of-mcaptcha-with-database-and-other-services-all-running-on-the-same-node.drv' failed to build
```

`nix --extra-experimental-features "nix-command flakes" build .#checks.x86_64-linux.projects/mCaptcha/nixos/tests/build-your-own-services`

```
error: flake 'git+file:///workspaces/ngipkgs' does not provide attribute 'packages.x86_64-linux.checks.x86_64-linux.projects/mCaptcha/nixos/tests/build-your-own-services', 'legacyPackages.x86_64-linux.checks.x86_64-linux.projects/mCaptcha/nixos/tests/build-your-own-services' or 'checks.x86_64-linux.projects/mCaptcha/nixos/tests/build-your-own-services'
```
author_association: CONTRIBUTOR
user: login: Axler1
created_at: 2025-04-15T21:30:11Z
body: @eljamm I've been trying different ways but I keep getting the same error. Even disabling the sandbox, but the issue persists.

`nix --extra-experimental-features "nix-command flakes" build .\#checks.x86_64-linux.projects/mCaptcha/nixos/tests/bring-your-own-services --option sandbox relaxed`

```
error: suspicious ownership or permission on '/nix/store/i9dmdq6rxhapj7jndvi19h60lr430qcf-boot.json.drv.chroot/root/nix/store/235hwkfrhxjgzwms9cis8h58f7ilb3qq-boot.json' for output 'out'; rejecting this build output
error: 1 dependencies of derivation '/nix/store/56gi4friqw2yp1jbv00bfkfwldwdz812-nixos-system-mcaptcha-test.drv' failed to build
error: 1 dependencies of derivation '/nix/store/l07w7albsckfnqxf7bg8aifv2x7k99yj-nixos-vm.drv' failed to build
error: 1 dependencies of derivation '/nix/store/vrhbhxni5gjdqq9b8sgbjsd6nmxdfxr0-nixos-test-driver-test-of-mcaptcha-with-database-and-other-services-running-on-a-different-node.drv' failed to build
error: 1 dependencies of derivation '/nix/store/3svh4s6ychfxhgpzgv4nkc78a3cai8lk-vm-test-run-test-of-mcaptcha-with-database-and-other-services-running-on-a-different-node.drv' failed to build
```

`nix --extra-experimental-features "nix-command flakes" build .\#checks.x86_64-linux.projects/mCaptcha/nixos/tests/create-locally --option sandbox false`

```
error: suspicious ownership or permission on '/nix/store/235hwkfrhxjgzwms9cis8h58f7ilb3qq-boot.json' for output 'out'; rejecting this build output
error: 1 dependencies of derivation '/nix/store/iy8b5a9sl47vn9mxp45b9fag7jah8a4k-nixos-system-mcaptcha-test.drv' failed to build
error: 1 dependencies of derivation '/nix/store/f4fwfnmdwkc9im554gmrg4qyq16gx311-nixos-vm.drv' failed to build
error: 1 dependencies of derivation '/nix/store/js0c8lf973fb1zd36dfsqv6zcskkd5c6-nixos-test-driver-test-of-mcaptcha-with-database-and-other-services-all-running-on-the-same-node.drv' failed to build
error: 1 dependencies of derivation '/nix/store/ds2fkgn56chm300q4q89rhkc5r2ahm7s-vm-test-run-test-of-mcaptcha-with-database-and-other-services-all-running-on-the-same-node.drv' failed to build
```
Could you please run the tests to see if it's my system that is causing the issues? 🙏
author_association: CONTRIBUTOR
user: login: eljamm
created_at: 2025-04-16T07:40:33Z
body: I think the command fails because the Nix store isn't properly supported when it's mounted on an NFS/NTFS filesystem [0](https://github.com/NixOS/nix/issues/7170) [1](https://github.com/NixOS/nix/issues/10062), if that's what you're doing. The project tests themselves are fine, since they're passing in CI.
author_association: CONTRIBUTOR
user: login: Axler1
created_at: 2025-04-16T18:14:43Z
body: > I think the command fails because the Nix store isn't properly supported when it's mounted on an NFS/NTFS filesystem [0](https://github.com/NixOS/nix/issues/7170) [1](https://github.com/NixOS/nix/issues/10062), if that's what you're doing. The project tests themselves are fine, since they're passing in CI.

Yeah, so that's what it was about.
author_association: CONTRIBUTOR