-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Allow patching dependency sources #151
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
58ed1f4
Remove unused sourceHashFunc arg from patchPackagefile
infinisil 9551a85
Convert internal sourceHashFunc argument to more general sourceOptions
infinisil a74e464
Add support for patching dependencies
infinisil bbb6fd4
Collect necessary integrity changes with Nix
infinisil 60e0c0e
Change interface from sourceAttrs to sourceOverrides
infinisil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "source-patching", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"custom-hello-world": "^1.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ npmlock2nix }: | ||
npmlock2nix.shell { | ||
src = ./.; | ||
node_modules_attrs = { | ||
sourceOverrides = { | ||
custom-hello-world = sourceInfo: drv: drv.overrideAttrs (old: { | ||
patches = builtins.toFile "custom-hello-world.patch" '' | ||
diff --git a/lib/index.js b/lib/index.js | ||
index 1f66513..64391a7 100644 | ||
--- a/lib/index.js | ||
+++ b/lib/index.js | ||
@@ -21,7 +21,7 @@ function generateHelloWorld({ comma, exclamation, lowercase }) { | ||
if (comma) | ||
helloWorldStr += ','; | ||
|
||
- helloWorldStr += ' World'; | ||
+ helloWorldStr += ' Nix'; | ||
|
||
if (exclamation) | ||
helloWorldStr += '!'; | ||
''; | ||
}); | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
{ lib, npmlock2nix, testLib }: | ||
let | ||
inherit (testLib) noGithubHashes; | ||
i = npmlock2nix.internal; | ||
in | ||
(testLib.runTests { | ||
testTurnsGitHubRefsToWildcards = { | ||
expr = (npmlock2nix.internal.patchPackagefile noGithubHashes ./examples-projects/github-dependency/package.json).dependencies.leftpad; | ||
expr = (npmlock2nix.internal.patchPackagefile ./examples-projects/github-dependency/package.json).dependencies.leftpad; | ||
expected = "*"; | ||
}; | ||
testHandlesBranches = { | ||
expr = (npmlock2nix.internal.patchPackagefile noGithubHashes ./examples-projects/github-dependency-branch/package.json).dependencies.leftpad; | ||
expr = (npmlock2nix.internal.patchPackagefile ./examples-projects/github-dependency-branch/package.json).dependencies.leftpad; | ||
expected = "*"; | ||
}; | ||
testHandlesDevDependencies = { | ||
expr = (npmlock2nix.internal.patchPackagefile noGithubHashes ./examples-projects/github-dev-dependency/package.json).devDependencies.leftpad; | ||
expr = (npmlock2nix.internal.patchPackagefile ./examples-projects/github-dev-dependency/package.json).devDependencies.leftpad; | ||
expected = "*"; | ||
}; | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The interface here is a very leaky abstraction. We just plug some additional variables into the
runCommand
but only some will ever actually have an impact. I'd rather prefer an interface that isn't passing everything through from the user but defines a stricter interface.The alternative is to provide an
overrideAttrs
interface here instead.I prefer the first approach as it comes with a more limited set of features that we have to take care of.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I think we can limit this to only
patches
andpostPatch
for now, but it could be extended with support for other attributes in the future (for now other attributes should give an error)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After another thought, I think it's probably better to just support all attributes, both to keep it simpler, but also because people might have different needs. Notably there's also
prePatch
, you can add dependencies inbuildInputs
as needed bypatchShebangs
, you may want to setNIX_DEBUG
for debugging, you may want to setsourceRoot
to only get a subdirectory, you may want to setdontUnpack
to preserve the original.tgz
and patch that withtar
directly, you may want to set environment variables.I pushed support for this in this PR now, along with documentation for it