How to use builtins.currentSystem in flake output?

Hi,

I’m trying to put builtins.currentSystem in my flake output but it pops error.

error: --- EvalError -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- nix
at: (35:31) in file: /nix/store/rr223k3r9cavnjq8pxqqqh2q0jzqxbyh-source/flake.nix

    34|
    35|       system = builtins.trace builtins.currentSystem "x86_64-linux";
      |                               ^
    36|

attribute 'currentSystem' missing

Are builtins not injected in flake? How can I use this or do something similar if I want to genereate some different output based on different os?

Thanks!

Some “impure” builtins are not available, currentSystem is one of them.

Instead most ouputs have the system as part of their attribute path, eg. packages.x86_64-linux.hello. You can also use flake-utils to easily write a function, which takes the system as an argument and provide a proper attribute set for the outputs.

@NobbZ Thanks! That’s great.

Is there anyway to assign different nixpkgs.url in the inputs? I’m using darwin and nixos at the same time, and I’m trying to build both system.

I’m using master branch now but I don’t know if there is any risk. My understanding is all the packages are wrap up with platform attributes now and it can select the right package’s tarball for your platform. So it should be fine to use the master branch. Correct me if I’m wrong.

    nixpkgs.url = "nixpkgs/master";
    nixpkgs-unstable.url = "nixpkgs/master";

flake-utils seems to be a nice tool, but it can only applied to flake output, right?

If it’s not safe to use master branch for both systems, is there a way to define different nixpkgs.url in the inputs so that I don’t need to do something like this nixpkgs-darwin.url = "nixpkgs/nixpkgs-20.09-darwin";, overlay my packages and put nixpkgs-darwin before all my packages.

Thanks!