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

resholve: init at 0.4.0 #85827

Merged
merged 24 commits into from Jan 5, 2021
Merged

resholve: init at 0.4.0 #85827

merged 24 commits into from Jan 5, 2021

Conversation

abathur
Copy link
Member

@abathur abathur commented Apr 23, 2020

Motivation for this change

Give the Nix ecosystem a new superpower: resolving external dependencies in shell scripts.

Shell scripts/libraries with external dependencies are an odd duck in the Nix ecosystem. Packaging them with Nix doesn't ensure dependencies are available at runtime or address the possibility that the script could run executables provided by packages other than those specified as dependencies, for example.

More information

This PR packages a project of mine, https://github.com/abathur/resholve, and provides a Nix build function. resholve is built atop the parser from the Oil shell project. A fair portion of the Nix code in this PR is just packaging/building a development version of Oil.

The PR itself isn't terribly useful for seeing what it does; it'll help to look at some additional resources:

FWIW, I dogfood resholve in my own darwin-configuration, where it is responsible for building a chain of packages structured like:

  • my bashrc
    • a bash history-management module I'm developing
A question came up during review about whether some of the packages in `deps.nix` should be split out into standalone packages. I've resolved the thread, but others may have the same question so I'm keeping the answer somewhere easier to find:

BTW, having oilshell and maybe oildev available in all-packages is probably a good idea, since those packages are kinda interesting. You could, for example, open a PR with only oildshell, oildev and maybe py-yajl, making it easier to review only those dependencies. Afterwards you could make this PR depends on those dependencies.

I have reservations about this.

I'm happy to break these out if there's a clear imperative, but they are all pretty idiomatic (and all ultimately subservient to the oildev package itself). I don't anticipate them adding standalone value to nixpkgs in the short run.

  1. The Oil shell already has a binary user package included here: https://github.com/NixOS/nixpkgs/blob/master/pkgs/shells/oil/default.nix

  2. oildev isn't (for now) a real thing that the Oil project intentionally publishes--it's a fiction created by forcibly patching-and-packaging Oil's python code in order to build resholve

    • Because these Python APIs aren't intentionally published for external consumption and Oil is still a fast-changing young project, they aren't stable. I'd be very surprised if more than one consumer could share a single version of it for long.
    • AFAIK resholve is the only consumer of this. No one's asked me about using it.
    • resholve still needs ~140 lines of code just to monkeypatch all of oil's packages into a unified oil.* namespace. If anyone used it without this shim, all of its subpackages would leak into the root Python package namespace.
    • I can't guarantee any Oil code paths that resholve doesn't exercise actually work.
    • Because resholve is very tightly coupled to Oil's internal Python APIs, there's a fair chance any update of this would break resholve.
  3. py-yajl is Oil's fork of https://github.com/rtyler/py-yajl. They've modified it, dropped tests they don't need, and cut code they don't use. I have no idea how suitable it is or isn't for general use. Oil has made no attempt to promote their py-yajl fork, it has no stars, and I have zero reason to expect that Oil would support it in any way.

cc @grahamc @worldofpeace

Known issues

The current design of the Nix API assumes all of the shell files can be resolved with the same settings, and it won't be terribly obvious what to do (aside from break it up into multiple derivations, or override to manually invoke resholve) in these cases.

I'm not sure what the best approach here is. For reference, here's one possible approach from @grahamc: https://gsc.io/content-addressed/92d2781347e6e0d9b761ff2d4512d6885f48d8fb6a97db15f0ba5f4863ec91bd.nix

I have pushed a tentative fix for this; see #85827 (comment) and d36bb7d

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions (in CI)
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@abathur abathur force-pushed the add_resholved branch 2 times, most recently from e29da15 to b6b79b1 Compare April 23, 2020 00:36
@abathur abathur changed the title resholved: init at hopes and dreams [WIP] resholved: init at hopes and dreams May 10, 2020
@abathur abathur marked this pull request as draft May 10, 2020 15:28
@abathur abathur changed the title [WIP] resholved: init at hopes and dreams resholved: init at hopes and dreams May 10, 2020
@abathur abathur force-pushed the add_resholved branch 2 times, most recently from 55c6945 to 71d5ae4 Compare May 17, 2020 19:41
@abathur abathur marked this pull request as ready for review May 17, 2020 19:53
@abathur
Copy link
Member Author

abathur commented May 17, 2020

I marked this as draft for a few days while I refactored how it packages and consumes its Oil-shell dependency. Not super relevant, but the main changes are:

  • It previously built from a fork of Oil where I fixed a few issues and added a setup.py, but I collapsed these changes into a set of patches maintained in the resholved repo. It now builds against a commit in the official repo.
  • Oil isn't structured with being turned into a Python package in mind, so I also hacked through forcing an oil namespace on its subpackages, which were previously just leaking into the Python package namespace. Some of them have very generic names (like core, misc, frontend, tools, etc.) so I've been a little concerned about them causing namespace clashes. To make this work (without patching all of the oil source) resholved now rewrites oil's imports.

@SuperSandro2000 SuperSandro2000 marked this pull request as draft November 29, 2020 00:35
@abathur abathur marked this pull request as ready for review December 15, 2020 04:59
@abathur abathur changed the title resholved: init at hopes and dreams resholve: init at 0.1.0 Dec 15, 2020
@abathur
Copy link
Member Author

abathur commented Dec 15, 2020

@grahamc I have finally released version 0.1.0 0.1.1 of resholve, updated this PR accordingly, and marked it ready for review.

resholve attempts to resolve executables in shell scripts.
Includes Nix builder for resolving dependencies in Nix-built
shell projects.
@abathur abathur changed the title resholve: init at 0.1.0 resholve: init at 0.1.1 Dec 15, 2020
@abathur
Copy link
Member Author

abathur commented Dec 15, 2020

Edit: #84062 has been merged, so my maintainer entry is now in master.

I rewrote the Nix API to support multiple resholve invocations with
different settings.
@abathur
Copy link
Member Author

abathur commented Dec 18, 2020

I've pushed an update which reworks the Nix API so that it can specify more than one resholve invocation.

Here's a (very abbreviated) example of how I was handling a package with one sourceable profile script, and one executable utility script:

resholve.resholvePackage rec {
  # ...
  scripts = [ "bin/hag.bash" "bin/hag_import_history.bash" ];
  interpreter = "${bashInteractive_5}/bin/bash";
  # ...
}

Here's how it looks with the API update:

resholve.resholvePackage rec {
  # ...
  solutions = {
    profile = {
      scripts = [ "bin/hag.bash" ];
      interpreter = "none";
    };
    # profile/cmd are arbitrary names; could be a list
    # but I gather set is preferred for overridability
    cmd = {
      scripts = [ "bin/hag_import_history.bash" ];
      interpreter = "${bashInteractive_5}/bin/bash";
    };
  };
  #...
}

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/412

@abathur abathur changed the title resholve: init at 0.1.1 resholve: init at 0.2.1 Dec 27, 2020
Copy link
Contributor

@thiagokokada thiagokokada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code wise LGTM, I can also build with with nixpkgs-review but it conflicts with nixpkgs PATH so I can't post the result.

Anyway, approving, but I didn't test it very much (did run resholve --help and it works). Probably someone with more context of how the package is supposed to work can check the functionality.

Don't forget to squash the commits before merging.

@abathur
Copy link
Member Author

abathur commented Jan 3, 2021

@SuperSandro2000 I haven't had any luck fishing for feedback on how to document this in the short run, so I pushed a commit updating the doc/comments where I previously had TODOs.

That's the last thing I wanted to do here, so I think it is ready for a squash-and-merge (if you think they're okay?)

Copy link
Member

@SuperSandro2000 SuperSandro2000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Package should be fine after my suggestions. I am not to sure if the build support could be made easier or we have inbuild functions for some of the ones but it should be fine for now.

pkgs/development/misc/resholve/deps.nix Outdated Show resolved Hide resolved
pkgs/development/misc/resholve/deps.nix Outdated Show resolved Hide resolved
pkgs/development/misc/resholve/deps.nix Outdated Show resolved Hide resolved
pkgs/development/misc/resholve/deps.nix Outdated Show resolved Hide resolved
pkgs/development/misc/resholve/default.nix Show resolved Hide resolved
pkgs/development/misc/resholve/resholve.nix Outdated Show resolved Hide resolved
pkgs/development/misc/resholve/resholve.nix Outdated Show resolved Hide resolved
pkgs/development/misc/resholve/resholve.nix Outdated Show resolved Hide resolved
pkgs/development/misc/resholve/resholve-package.nix Outdated Show resolved Hide resolved
abathur and others added 12 commits January 3, 2021 19:20
Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
@abathur abathur changed the title resholve: init at 0.3.0 resholve: init at 0.4.0 Jan 4, 2021
@abathur
Copy link
Member Author

abathur commented Jan 4, 2021

@SuperSandro2000 I've pushed commits that:

  • mostly address the review comments here
  • add a README.md as informal documentation, and a step towards eventually documenting it in the nixpkgs manual
  • bump/release resholve 0.4.0 to track the breaking namespace change (the Nix API is included there as well; no other functionality change over the 0.3.0)

@SuperSandro2000
Copy link
Member

Didn't read the entire doc but if we find mistake/areas to improve we can always do that later.

Copy link
Member

@grahamc grahamc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am exceedingly excited to use this!

@grahamc grahamc merged commit 6fd9283 into NixOS:master Jan 5, 2021
@worldofpeace
Copy link
Contributor

It's a miracle ✨ @abathur I'm excited that you got this into nixpkgs ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants