Nixos config in flakes: crash on impure.nix

Hello,
I’ve been trying to flake-ize my configuration for some days now. The main obstacle I found is to use two different versions of nixpkgs in the same configuration: I tried building an overlay and then use a module to configure nixpkgs but without success until I stumbled into nixpkgs.config.allowUnfreePredicate does not work with flakes · Issue #118115 · NixOS/nixpkgs · GitHub which taught me about extraArgs.

Now I’m struggling with this error:
error: assertion '(((args) ? localSystem) -> (! ((args) ? system)))' failed at /nix/store/scc6czs36gj535cwqgv7l8sb3bn8g1k2-source/pkgs/top-level/impure.nix:80:1:

This is the gist of it: (See files below)

What’s happening here?


EDIT to include source code of the question

flake.nix

{ 
  description = "my config";

  inputs = {
    vscode-pkgs.url = "nixpkgs/f9e81f7ad8795503a55e8f90836d31c04f282af8";
    tantra-nixos.url = "nixpkgs/79c970a7bbc686467e49f707db803703b4d61ecb";
  };

  outputs = { self, ... }@inputs:
  {
    nixosConfigurations.tantra = inputs.tantra-nixos.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        ./nixos/tantra.nix
      ];
      extraArgs = {
        inherit (inputs) vscode-pkgs;
      };
    };
  };
}

tantra.nix

{ config, pkgs, ... }:
{
imports = [
 # other imports
 ./modules/vscode.nix
]
# rest of config, no nixpgs.XYZ options
}

vscode.nix

{ config, pkgs, vscode-pkgs, ... }:
let
  # import vscode-pkgs and 
  vscode-channel = import vscode-pkgs config.nixpkgs;
  # used to build the vscode with extensions - replaced with comment to prove point
  # my-vscode-with-extensions = vscode-channel.callPackage ../packages/vscode.nix {};
  my-vscode-with-extensions = vscode-channel.vscode;
in
{
  environment.systemPackages = [ 
    my-vscode-with-extensions
    pkgs.dhall-lsp-server
  ];
  # needed by liveshare to log in
  services.gnome.gnome-keyring.enable = true;
}

Error originates from here:

You are importing vscode-pkgs like this

  vscode-channel = import vscode-pkgs config.nixpkgs;

where config.nixpkgs is a set with the following attributes

- config
- crossSystem
- initialSystem
- localSystem
- overlays
- pkgs
- system

So you are actually passing both system and localSystem to import vscode-pkgs, which is actually pkgs/top-level/impure.nix and the assertion fails.

You should do something like

  vscode-channel = import vscode-pkgs {
    inherit (config.nixpkgs)
      config
      system
    ;
  };
2 Likes

Yeah that’s definitely the solution to my issue! Thank you! I was expecting config.nixpkgs to be the configuration of nixpkgs but actually it’s a lot more