Is evalution twice forbidden?

I’m trying to configure separate setups for NixOS, WSL, and macOS (Darwin).

I discovered that I can use the WSL_DISTRO_NAME environment variable together

with the native flags pkgs.stdenv.isLinux and pkgs.stdenv.isDarwin to detect each platform.

Here’s my flake.nix

{
  description = "Custom basic linux configuration";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    nixos-wsl.url = "github:nix-community/NixOS-WSL/main";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    system-manager = {
      url = "github:numtide/system-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { self, nixpkgs, home-manager, system-manager, nixos-wsl, ... }:
    let
      lib = nixpkgs.lib;
      system = "x86_64-linux";
      # Overlays
      pkgs = import nixpkgs { 
        inherit system;
        overlays = [(final: prev: {
          google-chrome = prev.google-chrome.override {
            commandLineArgs =
              "--ozone-platform-hint=auto --enable-wayland-ime --enable-features=TouchpadOverscrollHistoryNavigation --wayland-text-input-version=3";
          };
          slack = prev.symlinkJoin {
            name = "slack";
            paths = [ prev.slack ];
            buildInputs = [ prev.makeWrapper ];
            postBuild = ''
              wrapProgram $out/bin/slack \
                --add-flags "--ozone-platform-hint=auto --enable-wayland-ime --enable-features=TouchpadOverscrollHistoryNavigation --wayland-text-input-version=3"
            '';
          };
        })];
        config.allowUnfree = true;
      };
      # Flags of OS
      isWsl = !builtins.isNull (builtins.getEnv "WSL_DISTRO_NAME");
      isLinux = pkgs.stdenv.isLinux;
      isDarwin = pkgs.stdenv.isDarwin;
      # Build home-manager by os flag
      home = import ./home.nix {
        inherit lib pkgs isWsl isLinux isDarwin;
        config = {};
      };
    in {
      # Define nixos configuration
      nixosConfigurations = {
        nixos = nixpkgs.lib.nixosSystem {
          inherit system;
          inherit pkgs;
          modules = [
            ./configuration.nix
          ];
        };
      };
      # Define the home-manager configuration
      homeConfigurations = {
        limjihoon = home-manager.lib.homeManagerConfiguration {
          inherit pkgs;
          modules = [ 
            home
            ./limjihoon-user.nix
          ];
        };
      };
      # Define system manager to cope with linux distro system
      systemConfigs.default = system-manager.lib.makeSystemConfig {
        modules = [
          ./modules
        ];
      };
    };
}

As I’ve set these flags, I get an error like this

❯ home-manager switch --flake .#limjihoon -b back --show-trace
error:
       … from call site
         at /nix/store/czr9ncbrnp8dj3ih1zjy4hb3bsxyfwhy-source/modules/default.nix:57:16:
           56|     let
           57|       module = moduleChecks rawModule;
             |                ^
           58|     in

       … while calling 'moduleChecks'
         at /nix/store/czr9ncbrnp8dj3ih1zjy4hb3bsxyfwhy-source/modules/default.nix:39:5:
           38|   moduleChecks =
           39|     raw:
             |     ^
           40|     showWarnings (

       … from call site
         at /nix/store/czr9ncbrnp8dj3ih1zjy4hb3bsxyfwhy-source/modules/default.nix:40:5:
           39|     raw:
           40|     showWarnings (
             |     ^
           41|       let

       … while calling 'showWarnings'
         at /nix/store/czr9ncbrnp8dj3ih1zjy4hb3bsxyfwhy-source/modules/default.nix:17:5:
           16|   showWarnings =
           17|     res:
             |     ^
           18|     let

       … from call site
         at /nix/store/czr9ncbrnp8dj3ih1zjy4hb3bsxyfwhy-source/modules/default.nix:21:5:
           20|     in
           21|     lib.fold f res res.config.warnings;
             |     ^
           22|

       … while calling 'foldr'
         at /nix/store/nfqw3h3qc2mq37v6amw80b1rpi0g9x61-source/lib/lists.nix:139:14:
          138|   foldr =
          139|     op: nul: list:
             |              ^
          140|     let

       … from call site
         at /nix/store/nfqw3h3qc2mq37v6amw80b1rpi0g9x61-source/lib/lists.nix:144:5:
          143|     in
          144|     fold' 0;
             |     ^
          145|

       … while calling 'fold''
         at /nix/store/nfqw3h3qc2mq37v6amw80b1rpi0g9x61-source/lib/lists.nix:142:15:
          141|       len = length list;
          142|       fold' = n: if n == len then nul else op (elemAt list n) (fold' (n + 1));
             |               ^
          143|     in

       … while evaluating a branch condition
         at /nix/store/nfqw3h3qc2mq37v6amw80b1rpi0g9x61-source/lib/lists.nix:142:18:
          141|       len = length list;
          142|       fold' = n: if n == len then nul else op (elemAt list n) (fold' (n + 1));
             |                  ^
          143|     in

       … while calling the 'length' builtin
         at /nix/store/nfqw3h3qc2mq37v6amw80b1rpi0g9x61-source/lib/lists.nix:141:13:
          140|     let
          141|       len = length list;
             |             ^
          142|       fold' = n: if n == len then nul else op (elemAt list n) (fold' (n + 1));

       … while evaluating a branch condition
         at /nix/store/czr9ncbrnp8dj3ih1zjy4hb3bsxyfwhy-source/modules/default.nix:45:7:
           44|       in
           45|       if failed == [ ] then
             |       ^
           46|         raw

       … from call site
         at /nix/store/czr9ncbrnp8dj3ih1zjy4hb3bsxyfwhy-source/modules/default.nix:42:18:
           41|       let
           42|         failed = collectFailed raw.config;
             |                  ^
           43|         failedStr = lib.concatStringsSep "\n" (map (x: "- ${x}") failed);

       … while calling 'collectFailed'
         at /nix/store/czr9ncbrnp8dj3ih1zjy4hb3bsxyfwhy-source/modules/default.nix:14:19:
           13|
           14|   collectFailed = cfg: map (x: x.message) (lib.filter (x: !x.assertion) cfg.assertions);
             |                   ^
           15|

       … while calling the 'map' builtin
         at /nix/store/czr9ncbrnp8dj3ih1zjy4hb3bsxyfwhy-source/modules/default.nix:14:24:
           13|
           14|   collectFailed = cfg: map (x: x.message) (lib.filter (x: !x.assertion) cfg.assertions);
             |                        ^
           15|

       … while calling the 'filter' builtin
         at /nix/store/czr9ncbrnp8dj3ih1zjy4hb3bsxyfwhy-source/modules/default.nix:14:44:
           13|
           14|   collectFailed = cfg: map (x: x.message) (lib.filter (x: !x.assertion) cfg.assertions);
             |                                            ^
           15|

       … while evaluating the attribute 'config'
         at /nix/store/nfqw3h3qc2mq37v6amw80b1rpi0g9x61-source/lib/modules.nix:359:9:
          358|         options = checked options;
          359|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          360|         _module = checked (config._module);

       … while calling the 'seq' builtin
         at /nix/store/nfqw3h3qc2mq37v6amw80b1rpi0g9x61-source/lib/modules.nix:359:18:
          358|         options = checked options;
          359|         config = checked (removeAttrs config [ "_module" ]);
             |                  ^
          360|         _module = checked (config._module);

       … while calling the 'throw' builtin
         at /nix/store/nfqw3h3qc2mq37v6amw80b1rpi0g9x61-source/lib/modules.nix:331:13:
          330|           else
          331|             throw baseMsg
             |             ^
          332|         else

       error: The option `NIX_CFLAGS_COMPILE' does not exist. Definition values:
       - In `<unknown-file>': ""

Although nix’s pleasent error message, I could not get a clue why it won’t evaluated.

In my assumption, nix won’t evaluate pkgs.stdenv twice.

Does my assumption valid, or is it the other problem ?

FYI : home.nix wasn’t the culprit: I tested it by replacing the OS flags with plain boolean values and saw the same error.

You hardcoded system to be linux so the rest is a bit nonsensical.

Also, your overlays should use final wherever possible except where it would lead to infrec.

2 Likes

Fyi, !builtins.isNull (builtins.getEnv "WSL_DISTRO_NAME"); is always true.

1 Like

Thx for the reply.

Not only did I hardcode system, but I was also unaware that Nix runs in a completely isolated environment from the host system.

I’ve come across configuring multiple configuration modules per system and invoking them with a script ,which is just a script for my case.

Hope this would help for beginner just like me :slight_smile: