nixos-module failing to build on darwin #103

Closed
opened 2025-12-22 11:49:58 +00:00 by dibenzepin · 5 comments

#101 uses NixOS-specific settings which prevents it from being built on macOS:

$ sudo darwin-rebuild switch
building the system configuration...
warning: Git tree '/Users/fum/dots' is dirty
warning: updating lock file '/Users/fum/dots/flake.lock':
• Updated input 'lix-module/flake-utils':
    follows 'flake-utils''github:numtide/flake-utils/11707dc2f618dd54ca8739b309ec4fc024de578b' (2024-11-13)
• Added input 'lix-module/flake-utils/systems':
    'github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e' (2023-04-09)
warning: Git tree '/Users/fum/dots' is dirty
error:
       … while evaluating the attribute 'config.system.build.toplevel'
         at /nix/store/h1i4134mxff6pv5zzfkzj3h4qyass2jr-source/lib/modules.nix:361:9:
          360|         options = checked options;
          361|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          362|         _module = checked (config._module);while evaluating an expression to select 'system' on it
         at /nix/store/4s8pqscjlrhv3jf6gnwd3mhm31kwyr52-source/eval-config.nix:88:35:
           87|     inherit (configuration._module.args) pkgs;
           88|     system = configuration.config.system.build.toplevel;
             |                                   ^
           89|     extendModules = args: withExtraAttrs (configuration.extendModules args);

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'systemd' missing
       at /nix/store/fqx55c2c6wcp01al17asszchx13az4ls-source/module.nix:6:25:
            5|   lixModuleMerged = lib.pathExists "${modulesPath}/programs/lix.nix";
            6|   nixDaemonCfg = config.systemd.services.nix-daemon;
             |                         ^
            7| in
       Did you mean system?

see Matrix discussion here.

#101 uses NixOS-specific settings which prevents it from being built on macOS: ```bash $ sudo darwin-rebuild switch building the system configuration... warning: Git tree '/Users/fum/dots' is dirty warning: updating lock file '/Users/fum/dots/flake.lock': • Updated input 'lix-module/flake-utils': follows 'flake-utils' → 'github:numtide/flake-utils/11707dc2f618dd54ca8739b309ec4fc024de578b' (2024-11-13) • Added input 'lix-module/flake-utils/systems': 'github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e' (2023-04-09) warning: Git tree '/Users/fum/dots' is dirty error: … while evaluating the attribute 'config.system.build.toplevel' at /nix/store/h1i4134mxff6pv5zzfkzj3h4qyass2jr-source/lib/modules.nix:361:9: 360| options = checked options; 361| config = checked (removeAttrs config [ "_module" ]); | ^ 362| _module = checked (config._module); … while evaluating an expression to select 'system' on it at /nix/store/4s8pqscjlrhv3jf6gnwd3mhm31kwyr52-source/eval-config.nix:88:35: 87| inherit (configuration._module.args) pkgs; 88| system = configuration.config.system.build.toplevel; | ^ 89| extendModules = args: withExtraAttrs (configuration.extendModules args); (stack trace truncated; use '--show-trace' to show the full trace) error: attribute 'systemd' missing at /nix/store/fqx55c2c6wcp01al17asszchx13az4ls-source/module.nix:6:25: 5| lixModuleMerged = lib.pathExists "${modulesPath}/programs/lix.nix"; 6| nixDaemonCfg = config.systemd.services.nix-daemon; | ^ 7| in Did you mean system? ``` see Matrix discussion [here](https://matrix.to/#/!KCM2lsE0d3vhMQY0:lix.systems/$qSPQusnFF2yHTdZFDJK7iyBDDL1_fXzSBEW-jBtYLC0?via=lix.systems&via=matrix.org&via=catgirl.cloud).
Owner

That's definitely a bug! When someone fixes this, we need to add an evaluation test to the checks that verifies it evaluates on nix-darwin.

That's definitely a bug! When someone fixes this, we need to add an evaluation test to the checks that verifies it evaluates on nix-darwin.
Member

@dibenzepin it should be fixed with #104

@dibenzepin it should be fixed with #104
Author

hm, nope still happens on 862e78b074:

$ jj diff --git flake.lock
diff --git a/flake.lock b/flake.lock
index de9d898c34..0862c901ad 100755
--- a/flake.lock
+++ b/flake.lock
@@ -125,11 +125,11 @@
[...]
},
       "locked": {
-        "lastModified": 1764519849,
-        "narHash": "sha256-XnNABKfIYKSimQVvKc9FnlC2H0LurOhd9MS6l0Z67lE=",
-        "rev": "6c95c0b6f73f831226453fc6905c216ab634c30f",
+        "lastModified": 1766482918,
+        "narHash": "sha256-0TGU/SZslVxyYLvZU7n+3gaZApbhQYAzNXYv4CbVPRU=",
+        "rev": "862e78b074d6d7dc9913a87bdb78070fcd0ecc34",
         "type": "tarball",
-        "url": "https://git.lix.systems/api/v1/repos/lix-project/nixos-module/archive/6c95c0b6f73f831226453fc6905c216ab634c30f.tar.gz?rev=6c95c0b6f73f831226453fc6905c216ab634c30f"
+        "url": "https://git.lix.systems/api/v1/repos/lix-project/nixos-module/archive/862e78b074d6d7dc9913a87bdb78070fcd0ecc34.tar.gz?rev=862e78b074d6d7dc9913a87bdb78070fcd0ecc34"
       },
 [...]

$ sudo darwin-rebuild switch
building the system configuration...
warning: Git tree '/Users/fum/dots' is dirty
error:
       … while evaluating the attribute 'config.system.build.toplevel'
         at /nix/store/ggja2nj25jzzx1ispbfy4h12xk4jz86j-source/lib/modules.nix:361:9:
          360|         options = checked options;
          361|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          362|         _module = checked (config._module);while evaluating an expression to select 'system' on it
         at /nix/store/72gyg5wk5pa3wgabb4fxb413s7c1jh23-source/eval-config.nix:88:35:
           87|     inherit (configuration._module.args) pkgs;
           88|     system = configuration.config.system.build.toplevel;
             |                                   ^
           89|     extendModules = args: withExtraAttrs (configuration.extendModules args);

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'systemd' missing
       at /nix/store/spsqx10jwcdbr5yxcx8174yz5r1j5rwd-source/module.nix:34:31:
           33|         lixModuleMerged = lib.pathExists "${modulesPath}/programs/lix.nix";
           34|         nixDaemonCfg = config.systemd.services.nix-daemon;
             |                               ^
           35|       in
       Did you mean system?
hm, nope still happens on 862e78b074d6d7dc9913a87bdb78070fcd0ecc34: ```shell $ jj diff --git flake.lock diff --git a/flake.lock b/flake.lock index de9d898c34..0862c901ad 100755 --- a/flake.lock +++ b/flake.lock @@ -125,11 +125,11 @@ [...] }, "locked": { - "lastModified": 1764519849, - "narHash": "sha256-XnNABKfIYKSimQVvKc9FnlC2H0LurOhd9MS6l0Z67lE=", - "rev": "6c95c0b6f73f831226453fc6905c216ab634c30f", + "lastModified": 1766482918, + "narHash": "sha256-0TGU/SZslVxyYLvZU7n+3gaZApbhQYAzNXYv4CbVPRU=", + "rev": "862e78b074d6d7dc9913a87bdb78070fcd0ecc34", "type": "tarball", - "url": "https://git.lix.systems/api/v1/repos/lix-project/nixos-module/archive/6c95c0b6f73f831226453fc6905c216ab634c30f.tar.gz?rev=6c95c0b6f73f831226453fc6905c216ab634c30f" + "url": "https://git.lix.systems/api/v1/repos/lix-project/nixos-module/archive/862e78b074d6d7dc9913a87bdb78070fcd0ecc34.tar.gz?rev=862e78b074d6d7dc9913a87bdb78070fcd0ecc34" }, [...] $ sudo darwin-rebuild switch building the system configuration... warning: Git tree '/Users/fum/dots' is dirty error: … while evaluating the attribute 'config.system.build.toplevel' at /nix/store/ggja2nj25jzzx1ispbfy4h12xk4jz86j-source/lib/modules.nix:361:9: 360| options = checked options; 361| config = checked (removeAttrs config [ "_module" ]); | ^ 362| _module = checked (config._module); … while evaluating an expression to select 'system' on it at /nix/store/72gyg5wk5pa3wgabb4fxb413s7c1jh23-source/eval-config.nix:88:35: 87| inherit (configuration._module.args) pkgs; 88| system = configuration.config.system.build.toplevel; | ^ 89| extendModules = args: withExtraAttrs (configuration.extendModules args); (stack trace truncated; use '--show-trace' to show the full trace) error: attribute 'systemd' missing at /nix/store/spsqx10jwcdbr5yxcx8174yz5r1j5rwd-source/module.nix:34:31: 33| lixModuleMerged = lib.pathExists "${modulesPath}/programs/lix.nix"; 34| nixDaemonCfg = config.systemd.services.nix-daemon; | ^ 35| in Did you mean system? ```
Author

@tom-hubrecht is there a reason #104 doesn't use stdenv.isDarwin and instead checks for the existence of systemd in the global config? (there probably is but i can't tell lol)

@tom-hubrecht is there a reason #104 doesn't use `stdenv.isDarwin` and instead checks for the existence of `systemd` in the global config? (there probably is but i can't tell lol)
Owner

I am pretty sure the module system does not allow for this.

nix-repl> (lib.evalModules {
  modules = [
    ({ options, ... }: {
      config = lib.mkIf (options ? foo) { foo = true; };
    })
  ];
}).config
       
    error: The option `foo' does not exist. Definition values:
    - In `<unknown-file>':
        {
          _type = "if";
          condition = false;
          content = true;
        }

    It seems as if you're trying to declare an option by placing it into `config' rather than `options'!

The module system's typechecking resolves what options are defined in all places, with a _type = "if"; simply being a "conditional definition", but conditional definitions still can't reference options that don't exist. And we can't simply use lib.optionalAttrs because that causes infinite recursion.

I'm pretty sure this is why Flakes have different outputs for nixosModules and darwinModules in the first place.

I am pretty sure the module system does not allow for this. ```nix nix-repl> (lib.evalModules { modules = [ ({ options, ... }: { config = lib.mkIf (options ? foo) { foo = true; }; }) ]; }).config error: The option `foo' does not exist. Definition values: - In `<unknown-file>': { _type = "if"; condition = false; content = true; } It seems as if you're trying to declare an option by placing it into `config' rather than `options'! ``` The module system's typechecking resolves what options are defined in all places, with a `_type = "if";` simply being a "conditional definition", but conditional definitions still can't reference options that don't exist. And we can't simply use `lib.optionalAttrs` because that causes infinite recursion. I'm pretty sure this is why Flakes have different outputs for `nixosModules` and `darwinModules` in the first place.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lix-project/nixos-module#103
No description provided.