mach-nix icon indicating copy to clipboard operation
mach-nix copied to clipboard

When used in a flake: `error: attribute 'currentSystem' missing`

Open MatrixManAtYrService opened this issue 2 years ago • 3 comments

Hi, I'm a newbie, so I apologize if this question is in the wrong place. I'm trying to use mach-nix in this flake.nix

{
  outputs = {self, nixpkgs}:
    let
      mach-nix = import (builtins.fetchGit {
        url = "https://github.com/DavHau/mach-nix";
        ref = "refs/tags/3.5.0";
        rev = "7e14360bde07dcae32e5e24f366c83272f52923f";
      }) { };
    in
    {
      defaultPackage.x86_64-linux = mach-nix.mkPython rec {
        requirements =  ''
          numpy
          '';
        };
    };
}

But when I run nix shell . I get this error:

error: attribute 'currentSystem' missing

       at /nix/store/5n402azp0s9vza4rziv4z5y88v2cv1mq-nixpkgs/pkgs/top-level/impure.nix:17:43:

           16|   # (build, in GNU Autotools parlance) platform.
           17|   localSystem ? { system = args.system or builtins.currentSystem; }
             |                                           ^
           18|

I was reading a blog about this which said:

You may get an error like this:

error: attribute 'currentSystem' missing This happens because in the context of flakes, builtins.currentSystem does not exist (it is, after all, an impurity). If you come across this, try to refactor your legacy-nix portion so the system is always an argument, and provide that argument from your flake, as above.

From that I get the feeling that I need to provide x86_64-linux as a parameter somehow. But where do I put it?

MatrixManAtYrService avatar Aug 24 '22 06:08 MatrixManAtYrService

You should follow the example described here: https://github.com/DavHau/mach-nix/blob/master/examples.md#use-mach-nix-from-a-flake - generally you want to use flake inputs to "import" remote nix packages/code.

ryanswrt avatar Aug 24 '22 13:08 ryanswrt

You could try (untested):

{
  outputs = {self, nixpkgs}:
    let
      mach-nix = import (builtins.fetchGit {
        url = "https://github.com/DavHau/mach-nix";
        ref = "refs/tags/3.5.0";
        rev = "7e14360bde07dcae32e5e24f366c83272f52923f";
      }) {  inherit system; };
    in
    {
      defaultPackage.x86_64-linux = mach-nix.mkPython rec {
        requirements =  ''
          numpy
          '';
        };
    };
}

573 avatar Dec 16 '22 09:12 573

{ inherit system; } is not working.

What you can do as a workaround is to build your configuration with the --impure option.

GeorgesAlkhouri avatar Feb 01 '23 13:02 GeorgesAlkhouri