Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating a flake will fail to load if it is in a subdirectory of a repository and depends on stuff above the flake.nix #226

Open
lf- opened this issue Feb 23, 2024 · 0 comments

Comments

@lf-
Copy link

lf- commented Feb 23, 2024

This is due to NixOS/nix#6767, where builtins.getFlake doesn't work on subdirectories.

The solution here, I think, is to use the top level of the repository with ?dir=blah/blah.

Output:

configs/nix » nix-update -F packages.x86_64-linux.jellyfin-plugin-sso                                                                                                                                                       main
$ nix eval --json --impure --expr
let

  inherit (builtins) getFlake stringLength substring;
  currentSystem = builtins.currentSystem;
  flake = getFlake "/home/jade/.dotfiles/configs/nix";
  pkg = flake.packages.${currentSystem}."packages"."x86_64-linux"."jellyfin-plugin-sso" or flake."packages"."x86_64-linux"."jellyfin-plugin-sso";
  inherit (flake) outPath;
  outPathLen = stringLength outPath;
  sanitizePosition = { file, ... }@pos:
    assert substring 0 outPathLen file != outPath
      -> throw "${file} is not in ${outPath}";
    pos // { file = "/home/jade/.dotfiles/configs/nix" + substring outPathLen (stringLength file - outPathLen) file; };

  raw_version_position = sanitizePosition (builtins.unsafeGetAttrPos "version" pkg);

  position = if pkg ? isRubyGem then
    raw_version_position
  else if pkg ? isPhpExtension then
    raw_version_position
   else
    sanitizePosition (builtins.unsafeGetAttrPos "src" pkg);
in {
  name = pkg.name;
  old_version = pkg.version or (builtins.parseDrvName pkg.name).version;
  inherit raw_version_position;
  filename = position.file;
  line = position.line;
  urls = pkg.src.urls or null;
  url = pkg.src.url or null;
  rev = pkg.src.rev or null;
  hash = pkg.src.outputHash or null;
  go_modules = pkg.goModules.outputHash or null;
  go_modules_old = pkg.go-modules.outputHash or null;
  cargo_deps = pkg.cargoDeps.outputHash or null;
  raw_cargo_lock =
    if pkg ? cargoDeps.lockFile then
      let
        inherit (pkg.cargoDeps) lockFile;
        res = builtins.tryEval (sanitizePosition {
          file = toString lockFile;
        });
      in
      if res.success then res.value.file else false
    else
      null;
  npm_deps = pkg.npmDeps.outputHash or null;
  yarn_deps = pkg.offlineCache.outputHash or null;
  tests = builtins.attrNames (pkg.passthru.tests or {});
  has_update_script = false;
  src_homepage = pkg.src.meta.homepage or null;
  changelog = pkg.meta.changelog or null;
} --extra-experimental-features flakes nix-command
error:
       … while evaluating attribute 'cargo_deps'

         at «string»:35:3:

           34|   go_modules_old = pkg.go-modules.outputHash or null;
           35|   cargo_deps = pkg.cargoDeps.outputHash or null;
             |   ^
           36|   raw_cargo_lock =

       … while evaluating the attribute 'packages.x86_64-linux.packages.x86_64-linux.jellyfin-plugin-sso'

         at /nix/store/kv5iqddpycxr6ydknp30qfdsl4a8zsr5-source/flake.nix:129:7:

          128|
          129|       packages.x86_64-linux =
             |       ^
          130|         let

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: getting status of '/nix/programs/hsutils/overlay.nix': No such file or directory
Traceback (most recent call last):
  File "/nix/store/yq22dg22s0f21jfqzi26937z96w749pr-nix-update-1.0.0/bin/.nix-update-wrapped", line 9, in <module>
    sys.exit(main())
             ^^^^^^
  File "/nix/store/yq22dg22s0f21jfqzi26937z96w749pr-nix-update-1.0.0/lib/python3.11/site-packages/nix_update/__init__.py", line 287, in main
    package = update(options)
              ^^^^^^^^^^^^^^^
  File "/nix/store/yq22dg22s0f21jfqzi26937z96w749pr-nix-update-1.0.0/lib/python3.11/site-packages/nix_update/update.py", line 322, in update
    package = eval_attr(opts)
              ^^^^^^^^^^^^^^^
  File "/nix/store/yq22dg22s0f21jfqzi26937z96w749pr-nix-update-1.0.0/lib/python3.11/site-packages/nix_update/eval.py", line 181, in eval_attr
    res = run(cmd)
          ^^^^^^^^
  File "/nix/store/yq22dg22s0f21jfqzi26937z96w749pr-nix-update-1.0.0/lib/python3.11/site-packages/nix_update/utils.py", line 37, in run
    return subprocess.run(
           ^^^^^^^^^^^^^^^
  File "/nix/store/y027d3bvlaizbri04c1bzh28hqd6lj01-python3-3.11.7/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['nix', 'eval', '--json', '--impure', '--expr', '\nlet\n  \n  inherit (builtins) getFlake stringLength substring;\n  currentSystem = builtins.currentSystem;\n  flake = getFlake "/home/jade/.dotfiles/configs/nix";\n  pkg = flake.packages.${currentSystem}."packages"."x86_64-linux"."jellyfin-plugin-sso" or flake."packages"."x86_64-linux"."jellyfin-plugin-sso";\n  inherit (flake) outPath;\n  outPathLen = stringLength outPath;\n  sanitizePosition = { file, ... }@pos:\n    assert substring 0 outPathLen file != outPath\n      -> throw "${file} is not in ${outPath}";\n    pos // { file = "/home/jade/.dotfiles/configs/nix" + substring outPathLen (stringLength file - outPathLen) file; };\n\n  raw_version_position = sanitizePosition (builtins.unsafeGetAttrPos "version" pkg);\n\n  position = if pkg ? isRubyGem then\n    raw_version_position\n  else if pkg ? isPhpExtension then\n    raw_version_position\n   else\n    sanitizePosition (builtins.unsafeGetAttrPos "src" pkg);\nin {\n  name = pkg.name;\n  old_version = pkg.version or (builtins.parseDrvName pkg.name).version;\n  inherit raw_version_position;\n  filename = position.file;\n  line = position.line;\n  urls = pkg.src.urls or null;\n  url = pkg.src.url or null;\n  rev = pkg.src.rev or null;\n  hash = pkg.src.outputHash or null;\n  go_modules = pkg.goModules.outputHash or null;\n  go_modules_old = pkg.go-modules.outputHash or null;\n  cargo_deps = pkg.cargoDeps.outputHash or null;\n  raw_cargo_lock =\n    if pkg ? cargoDeps.lockFile then\n      let\n        inherit (pkg.cargoDeps) lockFile;\n        res = builtins.tryEval (sanitizePosition {\n          file = toString lockFile;\n        });\n      in\n      if res.success then res.value.file else false\n    else\n      null;\n  npm_deps = pkg.npmDeps.outputHash or null;\n  yarn_deps = pkg.offlineCache.outputHash or null;\n  tests = builtins.attrNames (pkg.passthru.tests or {});\n  has_update_script = false;\n  src_homepage = pkg.src.meta.homepage or null;\n  changelog = pkg.meta.changelog or null;\n}', '--extra-experimental-features', 'flakes nix-command']' returned non-zero exit status 1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant