Compiling and adding program not in nixpkgs to PC, compiling error

I’m trying to add this program to my PC: GitHub - playit-cloud/playit-agent: The playit program

And I’m able to compile and run by downloading the tar.gz, extracting it, cd into the folder and running nix-shell -p cargo --command "cargo run --release --bin=playit-cli -- --help"

Now I was trying to add it to my configuration.nix file. (I use my flake, but it shouldn’t be relevant). So I added this to my configuration.nix file:

  imports = [
    (import ./nixFiles/playit-cli.nix)
  ];

and this is my playit-cli.nix file:

{ stdenv, fetchurl, pkgs, ... }:

let
  version = "1.0.0-rc2";
  src = fetchurl {
    url = "https://github.com/playit-cloud/playit-agent/releases/download/v${version}/playit-cli";
    sha256 = "1rb4jlwbixv0r1pak83prvsa79mj4096jdzjiyngdp5p9khcims9";
  };

in stdenv.mkDerivation {
  name = "playit-cli-${version}";
  buildInputs = [ pkgs.cargo ];
  src = src;
  installPhase = ''
    tar xfz $src
    cd playit-agent-${version}
    cargo build --release --bin=playit-cli
    mkdir -p $out/bin
    cp target/release/playit-cli $out/bin
  '';
  meta = with stdenv.lib; {
    description = "Playit-cli agent ${version}";
    homepage = "https://github.com/playit-cloud/playit-agent";
    license = licenses.gpl3;
    platform = platforms.unix;
  };
}

but I get this error on compile:

error: infinite recursion encountered

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:483:28:

          482|         builtins.addErrorContext (context name)
          483|           (args.${name} or config._module.args.${name})
             |                            ^
          484|       ) (lib.functionArgs f);
(use '--show-trace' to show detailed location information)

this is with --show-trace:

error: infinite recursion encountered

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:483:28:

          482|         builtins.addErrorContext (context name)
          483|           (args.${name} or config._module.args.${name})
             |                            ^
          484|       ) (lib.functionArgs f);

       … while evaluating the module argument `stdenv' in "/nix/store/valpmr7fq5485xlw6adzwpwpfgx84ng9-source/hosts/configuration.nix:anon-1":

       … while evaluating anonymous lambda

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:481:44:

          480|       context = name: ''while evaluating the module argument `${name}' in "${key}":'';
          481|       extraArgs = builtins.mapAttrs (name: _:
             |                                            ^
          482|         builtins.addErrorContext (context name)

       … from call site

       … while evaluating anonymous lambda

       at /nix/store/valpmr7fq5485xlw6adzwpwpfgx84ng9-source/hosts/nixFiles/playit-cli.nix:1:1:

            1| { stdenv, fetchurl, pkgs, ... }:
             | ^
            2|

       … from call site

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:490:8:

          489|       # works.
          490|     in f (args // extraArgs)
             |        ^
          491|   else

       … while evaluating 'applyModuleArgsIfFunction'

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:466:39:

          465|
          466|   applyModuleArgsIfFunction = key: f: args@{ config, options, lib, ... }: if isFunction f then
             |                                       ^
          467|     let

       … from call site

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:361:55:

          360|         if isFunction m || isAttrs m then
          361|           unifyModuleSyntax fallbackFile fallbackKey (applyModuleArgsIfFunction fallbackKey m args)
             |                                                       ^
          362|         else if isList m then

       … while evaluating 'unifyModuleSyntax'

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:434:34:

          433|      of ‘options’, ‘config’ and ‘imports’ attributes. */
          434|   unifyModuleSyntax = file: key: m:
             |                                  ^
          435|     let

       … from call site

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:361:11:

          360|         if isFunction m || isAttrs m then
          361|           unifyModuleSyntax fallbackFile fallbackKey (applyModuleArgsIfFunction fallbackKey m args)
             |           ^
          362|         else if isList m then

       … while evaluating 'loadModule'

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:359:53:

          358|       # Like unifyModuleSyntax, but also imports paths and calls functions if necessary
          359|       loadModule = args: fallbackFile: fallbackKey: m:
             |                                                     ^
          360|         if isFunction m || isAttrs m then

       … from call site

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:400:22:

          399|           let
          400|             module = loadModule args parentFile "${parentKey}:anon-${toString n}" x;
             |                      ^
          401|             collectedImports = collectStructuredModules module._file module.key module.imports args;

       … while evaluating the attribute 'disabled'

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:395:13:

          394|           collectResults = modules: {
          395|             disabled = concatLists (catAttrs "disabled" modules);
             |             ^
          396|             inherit modules;

       … while evaluating the attribute 'disabled'

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:395:13:

          394|           collectResults = modules: {
          395|             disabled = concatLists (catAttrs "disabled" modules);
             |             ^
          396|             inherit modules;

       … while evaluating anonymous lambda

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:419:31:

          418|           disabledKeys = map moduleKey disabled;
          419|           keyFilter = filter (attrs: ! elem attrs.key disabledKeys);
             |                               ^
          420|         in map (attrs: attrs.module) (builtins.genericClosure {

       … from call site

       … while evaluating 'filterModules'

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:413:36:

          412|       # modules recursively. It returns the final list of unique-by-key modules
          413|       filterModules = modulesPath: { disabled, modules }:
             |                                    ^
          414|         let

       … from call site

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:426:7:

          425|     in modulesPath: initialModules: args:
          426|       filterModules modulesPath (collectStructuredModules unknownModule "" initialModules args);
             |       ^
          427|

       … while evaluating anonymous lambda

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:425:37:

          424|
          425|     in modulesPath: initialModules: args:
             |                                     ^
          426|       filterModules modulesPath (collectStructuredModules unknownModule "" initialModules args);

       … from call site

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:258:25:

          257|       merged =
          258|         let collected = collectModules
             |                         ^
          259|           (specialArgs.modulesPath or "")

       … while evaluating 'reverseList'

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/lists.nix:394:17:

          393|   */
          394|   reverseList = xs:
             |                 ^
          395|     let l = length xs; in genList (n: elemAt xs (l - n - 1)) l;

       … from call site

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:262:33:

          261|           ({ inherit lib options config specialArgs; } // specialArgs);
          262|         in mergeModules prefix (reverseList collected);
             |                                 ^
          263|

       … while evaluating 'byName'

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:542:25:

          541|       */
          542|       byName = attr: f: modules:
             |                         ^
          543|         zipAttrsWith (n: concatLists)

       … from call site

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:559:21:

          558|       # an attrset 'name' => list of submodules that declare ‘name’.
          559|       declsByName = byName "options" (module: option:
             |                     ^
          560|           [{ inherit (module) _file; options = option; }]

       … while evaluating the attribute 'matchedOptions'

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:637:14:

          636|     in {
          637|       inherit matchedOptions;
             |              ^
          638|

       … while evaluating 'mapAttrsRecursiveCond'

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/attrsets.nix:412:36:

          411|   */
          412|   mapAttrsRecursiveCond = cond: f: set:
             |                                    ^
          413|     let

       … from call site

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:270:28:

          269|           # For definitions that have an associated option
          270|           declaredConfig = mapAttrsRecursiveCond (v: ! isOption v) (_: v: v.value) options;
             |                            ^
          271|

If I remove the three dots from the first line, so it is:
{ stdenv, fetchurl, pkgs }:

I get this error instead:

error: anonymous function at /nix/store/k7gngghwv7qh4klijlvjpg9n50pbb504-source/hosts/nixFiles/playit-cli.nix:1:1 called with unexpected argument 'inputs'

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:490:8:

          489|       # works.
          490|     in f (args // extraArgs)
             |        ^
          491|   else
(use '--show-trace' to show detailed location information)

this is with --show-trace:

error: anonymous function at /nix/store/k7gngghwv7qh4klijlvjpg9n50pbb504-source/hosts/nixFiles/playit-cli.nix:1:1 called with unexpected argument 'inputs'

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:490:8:

          489|       # works.
          490|     in f (args // extraArgs)
             |        ^
          491|   else

       … while evaluating 'applyModuleArgsIfFunction'

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:466:39:

          465|
          466|   applyModuleArgsIfFunction = key: f: args@{ config, options, lib, ... }: if isFunction f then
             |                                       ^
          467|     let

       … from call site

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:361:55:

          360|         if isFunction m || isAttrs m then
          361|           unifyModuleSyntax fallbackFile fallbackKey (applyModuleArgsIfFunction fallbackKey m args)
             |                                                       ^
          362|         else if isList m then

       … while evaluating 'unifyModuleSyntax'

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:434:34:

          433|      of ‘options’, ‘config’ and ‘imports’ attributes. */
          434|   unifyModuleSyntax = file: key: m:
             |                                  ^
          435|     let

       … from call site

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:361:11:

          360|         if isFunction m || isAttrs m then
          361|           unifyModuleSyntax fallbackFile fallbackKey (applyModuleArgsIfFunction fallbackKey m args)
             |           ^
          362|         else if isList m then

       … while evaluating 'loadModule'

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:359:53:

          358|       # Like unifyModuleSyntax, but also imports paths and calls functions if necessary
          359|       loadModule = args: fallbackFile: fallbackKey: m:
             |                                                     ^
          360|         if isFunction m || isAttrs m then

       … from call site

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:400:22:

          399|           let
          400|             module = loadModule args parentFile "${parentKey}:anon-${toString n}" x;
             |                      ^
          401|             collectedImports = collectStructuredModules module._file module.key module.imports args;

       … while evaluating the attribute 'disabled'

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:395:13:

          394|           collectResults = modules: {
          395|             disabled = concatLists (catAttrs "disabled" modules);
             |             ^
          396|             inherit modules;

       … while evaluating the attribute 'disabled'

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:395:13:

          394|           collectResults = modules: {
          395|             disabled = concatLists (catAttrs "disabled" modules);
             |             ^
          396|             inherit modules;

       … while evaluating anonymous lambda

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:419:31:

          418|           disabledKeys = map moduleKey disabled;
          419|           keyFilter = filter (attrs: ! elem attrs.key disabledKeys);
             |                               ^
          420|         in map (attrs: attrs.module) (builtins.genericClosure {

       … from call site

       … while evaluating 'filterModules'

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:413:36:

          412|       # modules recursively. It returns the final list of unique-by-key modules
          413|       filterModules = modulesPath: { disabled, modules }:
             |                                    ^
          414|         let

       … from call site

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:426:7:

          425|     in modulesPath: initialModules: args:
          426|       filterModules modulesPath (collectStructuredModules unknownModule "" initialModules args);
             |       ^
          427|

       … while evaluating anonymous lambda

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:425:37:

          424|
          425|     in modulesPath: initialModules: args:
             |                                     ^
          426|       filterModules modulesPath (collectStructuredModules unknownModule "" initialModules args);

       … from call site

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:258:25:

          257|       merged =
          258|         let collected = collectModules
             |                         ^
          259|           (specialArgs.modulesPath or "")

       … while evaluating 'reverseList'

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/lists.nix:394:17:

          393|   */
          394|   reverseList = xs:
             |                 ^
          395|     let l = length xs; in genList (n: elemAt xs (l - n - 1)) l;

       … from call site

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:262:33:

          261|           ({ inherit lib options config specialArgs; } // specialArgs);
          262|         in mergeModules prefix (reverseList collected);
             |                                 ^
          263|

       … while evaluating 'byName'

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:542:25:

          541|       */
          542|       byName = attr: f: modules:
             |                         ^
          543|         zipAttrsWith (n: concatLists)

       … from call site

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:559:21:

          558|       # an attrset 'name' => list of submodules that declare ‘name’.
          559|       declsByName = byName "options" (module: option:
             |                     ^
          560|           [{ inherit (module) _file; options = option; }]

       … while evaluating the attribute 'matchedOptions'

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:637:14:

          636|     in {
          637|       inherit matchedOptions;
             |              ^
          638|

       … while evaluating 'mapAttrsRecursiveCond'

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/attrsets.nix:412:36:

          411|   */
          412|   mapAttrsRecursiveCond = cond: f: set:
             |                                    ^
          413|     let

       … from call site

       at /nix/store/f30dcvgm875ksqbhmp97wqvxmrzlbbjc-source/lib/modules.nix:270:28:

          269|           # For definitions that have an associated option
          270|           declaredConfig = mapAttrsRecursiveCond (v: ! isOption v) (_: v: v.value) options;
             |                            ^
          271|

I’ve tried changing the contents of playit-cli.nix to the GNU Hello package, and I get the same error as the one immediately above

I’m not proficient with nix, and these error messages leave me at a loss, I can’t find anything in google about them
Thanks in advance! :slight_smile:

Few remarks:

  • the file that you try to import is a derivation, not a module, so you don’t want to put it in imports (also in this section you should not call import in the list, it’s just a list of file). Instead it’s a program. So you should do something like:
system.environmentPackages = with pkgs; [
  (callPackage ./playit-cli.nix {})
];
  • I have never used cargo, so I’m not sure if your derivation will work. But it could be easier to directly build the package from source using rustPlatform.buildRustPackage as explained here Rust | nixpkgs.

Thank you so much @tobiasBora :slight_smile:

You were right, with callPackage I’m now able to compile if I use the code from GNU Hello Package, my derivation isn’t working yet tho, it’s giving me:

error: attribute 'lib' missing

       at /nix/store/a087mviyq1a4qn6ylprw2zr1n68ywdjk-source/hosts/nixFiles/playit-cli.nix:22:15:

           21|   '';
           22|   meta = with stdenv.lib; {
             |               ^
           23|     description = "Playit-cli agent ${version}";
(use '--show-trace' to show detailed location information)

I’ll take a look at your suggestion about rustPlatform.buildRustPackage. Thanks a lot again :slight_smile:

Made it work in the end liek this :+1:

# Derivation, not a module!
{ lib, fetchFromGitHub, rustPlatform }:

rustPlatform.buildRustPackage rec {
  pname = "playit-agent";
  version = "1.0.0"; # for release 1.0.0-rc2;
  doCheck = false; # the tests weren't letting it build?
  # You should change this to disable just the test that wasn't making it work: https://github.com/NixOS/nixpkgs/blob/f06b88d6d0911d31c75a2324522b4ff5a04826df/doc/languages-frameworks/rust.section.md#running-package-tests-running-package-tests

  src = fetchFromGitHub {
    owner = "playit-cloud";
    repo = pname;
    rev = version;
    sha256 = "sha256-25j17LQn12Vm7Ybp0qKFN+nYQ9w3ys8RsM3ROy83V/w=";
  };

  cargoSha256 = "sha256-M5zO31AfuyX9zfyYiI2X3gFgEYhTQA95pmHSii+jNGY=";

  meta = with lib; {
    description = "game client to run servers without portforwarding";
    homepage = "https://github.com/playit-cloud/playit-agent";
    license = licenses.unlicense;
    maintainers = [ "Yeshey" ];
  };
}
1 Like