nix-community / nix-on-droid

Nix-enabled environment for your Android device. [maintainers=@t184256,@Gerschtli]
https://nix-on-droid.unboiled.info
MIT License
1.25k stars 69 forks source link

Nix Flake configuration needs --impure #99

Closed c4dr01d closed 3 years ago

c4dr01d commented 3 years ago

Hi, I just saw the README, nix-on-droid can be configurable by nix flakes but not in pure eval. I don't know the nix-on-droid configuration can or not can be merge to my nix configuration collection. because my nix configuration is pure eval. :(

t184256 commented 3 years ago

This is pretty fresh stuff, merged just yesterday.

I recall @bbigras giving a bit more details here:

builtins.storePath' is not allowed in pure evaluation mode

Not sure where that is coming from though.

bbigras commented 3 years ago

Does this help?

❯ nix build .#pixel2 --show-trace
warning: Git tree '/home/bbigras/nix-config' is dirty
error: --- EvalError ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- nix
builtins.storePath' is not allowed in pure evaluation mode
--------------------------------------------------------------------------------------------------- show-trace ---------------------------------------------------------------------------------------------------
trace: while evaluating the attribute 'installProotStatic'
at: (71:7) in file: /nix/store/9rqzlbiwyqh50fcx77rnx1l3yx99f76n-source/modules/environment/login/default.nix

    70|
    71|       installProotStatic = ''
      |       ^
    72|         if (test -e /bin/.proot-static.new && ! diff /bin/.proot-static.new ${cfg.prootStatic}/bin/proot-static > /dev/null) || \

trace: while evaluating anonymous lambda
at: (26:27) in file: /nix/store/9rqzlbiwyqh50fcx77rnx1l3yx99f76n-source/modules/build/activation.nix

    25|   mkActivationCmds = activation: concatStringsSep "\n" (
    26|     mapAttrsToList (name: value: ''
      |                           ^
    27|       noteEcho "Activating ${name}"

trace: from call site
at: (234:16) in file: /nix/store/qh1497vqx38yl6qcpdgf83jd45i96ahi-source/lib/attrsets.nix

   233|   mapAttrsToList = f: attrs:
   234|     map (name: f name attrs.${name}) (attrNames attrs);
      |                ^
   235|

trace: while evaluating anonymous lambda
at: (234:10) in file: /nix/store/qh1497vqx38yl6qcpdgf83jd45i96ahi-source/lib/attrsets.nix

   233|   mapAttrsToList = f: attrs:
   234|     map (name: f name attrs.${name}) (attrNames attrs);
      |          ^
   235|

trace: from call site
trace: while evaluating 'mkActivationCmds'
at: (25:22) in file: /nix/store/9rqzlbiwyqh50fcx77rnx1l3yx99f76n-source/modules/build/activation.nix

    24|
    25|   mkActivationCmds = activation: concatStringsSep "\n" (
      |                      ^
    26|     mapAttrsToList (name: value: ''

trace: from call site
at: (46:7) in file: /nix/store/9rqzlbiwyqh50fcx77rnx1l3yx99f76n-source/modules/build/activation.nix

    45|     ${mkActivationCmds cfg.activationBefore}
    46|     ${mkActivationCmds cfg.activation}
      |       ^
    47|     ${mkActivationCmds cfg.activationAfter}

trace: while evaluating the attribute 'text' of the derivation 'activation-script'
at: (7:7) in file: /nix/store/qh1497vqx38yl6qcpdgf83jd45i96ahi-source/pkgs/build-support/trivial-builders.nix

     6|     stdenv.mkDerivation ({
     7|       name = lib.strings.sanitizeDerivationName name;
      |       ^
     8|       inherit buildCommand;

trace: while evaluating the attribute 'buildCommand' of the derivation 'nix-on-droid-generation'
at: (7:7) in file: /nix/store/qh1497vqx38yl6qcpdgf83jd45i96ahi-source/pkgs/build-support/trivial-builders.nix

     6|     stdenv.mkDerivation ({
     7|       name = lib.strings.sanitizeDerivationName name;
      |       ^
     8|       inherit buildCommand;

trace: while evaluating the attribute 'passAsFile' of the derivation 'activatable-nix-on-droid-generation'
at: (7:7) in file: /nix/store/qh1497vqx38yl6qcpdgf83jd45i96ahi-source/pkgs/build-support/trivial-builders.nix

     6|     stdenv.mkDerivation ({
     7|       name = lib.strings.sanitizeDerivationName name;
      |       ^
     8|       inherit buildCommand;
c4dr01d commented 3 years ago

@bbigras suggest run nix flake check at nix config directory to check error before build

bbigras commented 3 years ago
❯ nix flake check --show-trace
warning: Git tree '/home/bbigras/nix-config' is dirty
error: --- EvalError ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- nix
builtins.storePath' is not allowed in pure evaluation mode
--------------------------------------------------------------------------------------------------- show-trace ---------------------------------------------------------------------------------------------------
trace: while evaluating the attribute 'installProotStatic'
at: (71:7) in file: /nix/store/9rqzlbiwyqh50fcx77rnx1l3yx99f76n-source/modules/environment/login/default.nix

    70|
    71|       installProotStatic = ''
      |       ^
    72|         if (test -e /bin/.proot-static.new && ! diff /bin/.proot-static.new ${cfg.prootStatic}/bin/proot-static > /dev/null) || \

trace: while evaluating anonymous lambda
at: (26:27) in file: /nix/store/9rqzlbiwyqh50fcx77rnx1l3yx99f76n-source/modules/build/activation.nix

    25|   mkActivationCmds = activation: concatStringsSep "\n" (
    26|     mapAttrsToList (name: value: ''
      |                           ^
    27|       noteEcho "Activating ${name}"

trace: from call site
at: (234:16) in file: /nix/store/qh1497vqx38yl6qcpdgf83jd45i96ahi-source/lib/attrsets.nix

   233|   mapAttrsToList = f: attrs:
   234|     map (name: f name attrs.${name}) (attrNames attrs);
      |                ^
   235|

trace: while evaluating anonymous lambda
at: (234:10) in file: /nix/store/qh1497vqx38yl6qcpdgf83jd45i96ahi-source/lib/attrsets.nix

   233|   mapAttrsToList = f: attrs:
   234|     map (name: f name attrs.${name}) (attrNames attrs);
      |          ^
   235|

trace: from call site
trace: while evaluating 'mkActivationCmds'
at: (25:22) in file: /nix/store/9rqzlbiwyqh50fcx77rnx1l3yx99f76n-source/modules/build/activation.nix

    24|
    25|   mkActivationCmds = activation: concatStringsSep "\n" (
      |                      ^
    26|     mapAttrsToList (name: value: ''

trace: from call site
at: (46:7) in file: /nix/store/9rqzlbiwyqh50fcx77rnx1l3yx99f76n-source/modules/build/activation.nix

    45|     ${mkActivationCmds cfg.activationBefore}
    46|     ${mkActivationCmds cfg.activation}
      |       ^
    47|     ${mkActivationCmds cfg.activationAfter}

trace: while evaluating the attribute 'text' of the derivation 'activation-script'
at: (7:7) in file: /nix/store/qh1497vqx38yl6qcpdgf83jd45i96ahi-source/pkgs/build-support/trivial-builders.nix

     6|     stdenv.mkDerivation ({
     7|       name = lib.strings.sanitizeDerivationName name;
      |       ^
     8|       inherit buildCommand;

trace: while evaluating the attribute 'buildCommand' of the derivation 'nix-on-droid-generation'
at: (7:7) in file: /nix/store/qh1497vqx38yl6qcpdgf83jd45i96ahi-source/pkgs/build-support/trivial-builders.nix

     6|     stdenv.mkDerivation ({
     7|       name = lib.strings.sanitizeDerivationName name;
      |       ^
     8|       inherit buildCommand;

trace: while evaluating the attribute 'passAsFile' of the derivation 'activatable-nix-on-droid-generation'
at: (7:7) in file: /nix/store/qh1497vqx38yl6qcpdgf83jd45i96ahi-source/pkgs/build-support/trivial-builders.nix

     6|     stdenv.mkDerivation ({
     7|       name = lib.strings.sanitizeDerivationName name;
      |       ^
     8|       inherit buildCommand;

trace: while evaluating 'escapeShellArg'
at: (318:20) in file: /nix/store/qh1497vqx38yl6qcpdgf83jd45i96ahi-source/lib/strings.nix

   317|   */
   318|   escapeShellArg = arg: "'${replaceStrings ["'"] ["'\\''"] (toString arg)}'";
      |                    ^
   319|

trace: from call site
at: (332:19) in file: /nix/store/qh1497vqx38yl6qcpdgf83jd45i96ahi-source/pkgs/build-support/trivial-builders.nix

   331|           mkdir -p "$(dirname ${lib.escapeShellArg x.name})"
   332|           ln -s ${lib.escapeShellArg x.path} ${lib.escapeShellArg x.name}
      |                   ^
   333|       '') entries}

trace: while evaluating anonymous lambda
at: (330:31) in file: /nix/store/qh1497vqx38yl6qcpdgf83jd45i96ahi-source/pkgs/build-support/trivial-builders.nix

   329|       cd $out
   330|       ${lib.concatMapStrings (x: ''
      |                               ^
   331|           mkdir -p "$(dirname ${lib.escapeShellArg x.name})"

trace: from call site
trace: while evaluating 'concatMapStrings'
at: (53:25) in file: /nix/store/qh1497vqx38yl6qcpdgf83jd45i96ahi-source/lib/strings.nix

    52|   */
    53|   concatMapStrings = f: list: concatStrings (map f list);
      |                         ^
    54|

trace: from call site
at: (330:9) in file: /nix/store/qh1497vqx38yl6qcpdgf83jd45i96ahi-source/pkgs/build-support/trivial-builders.nix

   329|       cd $out
   330|       ${lib.concatMapStrings (x: ''
      |         ^
   331|           mkdir -p "$(dirname ${lib.escapeShellArg x.name})"

trace: while evaluating the attribute 'buildCommand' of the derivation 'nix-config'
at: (7:7) in file: /nix/store/qh1497vqx38yl6qcpdgf83jd45i96ahi-source/pkgs/build-support/trivial-builders.nix

     6|     stdenv.mkDerivation ({
     7|       name = lib.strings.sanitizeDerivationName name;
      |       ^
     8|       inherit buildCommand;

trace: while checking the derivation 'defaultPackage.x86_64-linux'
at: (73:51) in file: /nix/store/m3qzm0c5r708l5h8gn7dwrlciib37x0d-source/default.nix

    72|             {
    73|               ${key} = (attrs.${key} or { }) // { ${system} = ret.${key}; };
      |                                                   ^
    74|             }

trace: while checking flake output 'defaultPackage'
at: (73:15) in file: /nix/store/m3qzm0c5r708l5h8gn7dwrlciib37x0d-source/default.nix

    72|             {
    73|               ${key} = (attrs.${key} or { }) // { ${system} = ret.${key}; };
      |               ^
    74|             }
c4dr01d commented 3 years ago

@bbigras Can I see /nix/store/9rqzlbiwyqh50fcx77rnx1l3yx99f76n-source/modules/environment/login/default.nix content? I think error is happen in there.

bbigras commented 3 years ago

/nix/store/qk3igkglx29yhi3b83pd8v06gv5alwn2-source/modules/environment/login/default.nix (the old path was removed by the gc)

# Copyright (c) 2019-2020, see AUTHORS. Licensed under MIT License, see LICENSE.

{ config, lib, pkgs, customPkgs, ... }:

with lib;

let
  cfg = config.environment.files;

  login = pkgs.callPackage ./login.nix { inherit config; };

  loginInner = pkgs.callPackage ./login-inner.nix { inherit config customPkgs; };
in

{

  ###### interface

  options = {

    environment.files = {
      login = mkOption {
        type = types.package;
        readOnly = true;
        internal = true;
        description = "Login script.";
      };

      loginInner = mkOption {
        type = types.package;
        readOnly = true;
        internal = true;
        description = "Login-inner script.";
      };

      prootStatic = mkOption {
        type = types.package;
        readOnly = true;
        internal = true;
        description = "proot-static package.";
      };
    };

  };

  ###### implementation

  config = {

    build.activation = {
      installLogin = ''
        if ! diff /bin/login ${login} > /dev/null; then
          $DRY_RUN_CMD mkdir $VERBOSE_ARG --parents /bin
          $DRY_RUN_CMD cp $VERBOSE_ARG ${login} /bin/.login.tmp
          $DRY_RUN_CMD chmod $VERBOSE_ARG u+w /bin/.login.tmp
          $DRY_RUN_CMD mv $VERBOSE_ARG /bin/.login.tmp /bin/login
        fi
      '';

      installLoginInner = ''
        if (test -e /usr/lib/.login-inner.new && ! diff /usr/lib/.login-inner.new ${loginInner} > /dev/null) || \
            (! test -e /usr/lib/.login-inner.new && ! diff /usr/lib/login-inner ${loginInner} > /dev/null); then
          $DRY_RUN_CMD mkdir $VERBOSE_ARG --parents /usr/lib
          $DRY_RUN_CMD cp $VERBOSE_ARG ${loginInner} /usr/lib/.login-inner.tmp
          $DRY_RUN_CMD chmod $VERBOSE_ARG u+w /usr/lib/.login-inner.tmp
          $DRY_RUN_CMD mv $VERBOSE_ARG /usr/lib/.login-inner.tmp /usr/lib/.login-inner.new
        fi
      '';

      installProotStatic = ''
        if (test -e /bin/.proot-static.new && ! diff /bin/.proot-static.new ${cfg.prootStatic}/bin/proot-static > /dev/null) || \
            (! test -e /bin/.proot-static.new && ! diff /bin/proot-static ${cfg.prootStatic}/bin/proot-static > /dev/null); then
          $DRY_RUN_CMD mkdir $VERBOSE_ARG --parents /bin
          $DRY_RUN_CMD cp $VERBOSE_ARG ${cfg.prootStatic}/bin/proot-static /bin/.proot-static.tmp
          $DRY_RUN_CMD chmod $VERBOSE_ARG u+w /bin/.proot-static.tmp
          $DRY_RUN_CMD mv $VERBOSE_ARG /bin/.proot-static.tmp /bin/.proot-static.new
        fi
      '';
    };

    environment.files = {
      inherit login loginInner;

      prootStatic =
        let
          crossCompiledPaths = {
           aarch64 = "/nix/store/ly8ffgwwg7xsgqfcw865vdi0bqaj4vp9-proot-termux-unstable-2020-10-25-aarch64-unknown-linux-android";
           i686 = "/nix/store/9kgif2f321vrbjd7x0pj7rcyg84zrhgz-proot-termux-unstable-2020-10-25-i686-unknown-linux-android";
          };
        in
          "${crossCompiledPaths.${config.build.arch}}";
    };

  };

}
c4dr01d commented 3 years ago

@bbigras seem is hardcoded nix path, if cannot resolve this problem, the module still cannot compile without --impure flake option

c4dr01d commented 3 years ago

or transform storePath to stringContext

c4dr01d commented 3 years ago

@t184256 I just forked repository, this branch is the branch for this issue?

t184256 commented 3 years ago

Building proot on device is a long-standing unsolvable problem for me: #19.

Problem is, if I don't compile it with bionic using Android NDK toolchain, it mysteriously fails to work in many ways beyond my knowledge level (#1, #8, ...). Thus the separately cross-compiled derivation with hardcoded path, supplied through bootstrap tarball and updated through cachix.

Yeah, if somebody manages to compile a working proot on-device, that'd simplify things a lot.

c4dr01d commented 3 years ago

@t184256 You can create a cross-compile toolchain and using bionic to create bootstrap, not Android NDK builtin clang

Gerschtli commented 2 years ago

I tried to flakify my nix-on-droid config and ran into the same problem.

@c4dr01d Can you elaborate on what you mean with

or transform storePath to stringContext