Let’s say I want to create a PR for a project; in that case, I want to access the source code, make changes, and compile it.
Can I use Nix to improve my workflow?
If I run nix develop nixpkgs#package --debug, how can I access the source code, change it, and then compile it?
It would also be fine for me to clone the repo via VCS normally, and then use nix build against the local folder while sourcing the package.nix from nixpkgs, without having to copy it into the cloned folder or add a flake.nix.
I hope I expressed myself well. I tried searching the documentation for something like this but only found nix develop - Nix Reference Manual, which led me to --redirect. It’s not obvious to me what I should do after running nix develop nixpkgs#PACKAGE --redirect nixpkgs#PACKAGE ..
I obviously need to learn more about Nix, but I thought asking here might lead me to good study directions.
I’ve actually never known about this --redirect flag, though I suppose you could use it to redirect the src attribute of a derivation, make your changes to the sources, and then override the derivation to use your modified source tree.
error: flake 'flake:nixpkgs' does not provide attribute 'devShells.x86_64-linux.PACKAGE.src',
'packages.x86_64-linux.PACKAGE.src', 'legacyPackages.x86_64-linux.PACKAGE.src'
or 'PACKAGE.src'
If I may ask, how do you usually contribute to a project, leveraging nix [flakes] for building?
$ cd $(mktemp -d)
$ nix develop nixpkgs#hello
$ unpackPhase
$ cd hello-2.12.2
# do whatever you want
$ configurePhase
$ buildPhase
$ installPhase
# show outputs
$ ls outputs/out/
If you want to use a local source, skip the unpackPhase.
Okay thank you @oldshensheep. I was trying this the other day, but I had a problem with the source. Which I guess “the derivation I used didn’t provide”
> nix develop nixpkgs#telegram-desktop
[nix] > unpackPhase
variable $src or $srcs should point to the source
exit
> nix develop nixpkgs#telegram-desktop
[nix] > src=$(nix build nixpkgs#telegram-desktop --no-link --print-out-paths)
[nix] > unpackPhase
unpacking source archive /nix/store/nrzwszjsxpggdwkxsz04d92sr4a9s8vm-telegram-desktop-6.2.3
source root is telegram-desktop-6.2.3
[nix] > stat -c "%a %n" telegram-desktop-6.2.3/
755 telegram-desktop-6.2.3/
I think like this is okay or I could have cloned the repo via vcs as you said. But why does hello provide the source directly while telegram-desktop doesn’t?
I thought I would have been the one defined at
PS: I think I understand after pasting the last url. It is in unwrapped.nix, but src doesn’t get inherited in default.nix
I agree it would be tedious for a nixos configuration having it rebuilt everytime, but also for my use case (contributing a PR to a project) since it is unwrapped.
Because now I have:
> nix develop nixpkgs#telegram-desktop.unwrapped
[nix] > unpackPhase
unpacking source archive /nix/store/7m1f6hwsyqkihhpz5ps6bnpnl288xp0c-source
source root is source
[nix] > cd source/
[nix] > configurePhase
no configure script, doing nothing
[nix] > buildPhase
no Makefile or custom buildPhase, doing nothing
Because those would come from the wrapping derivation I believe.
This seems a weird corner case though, in a normal derivation I would have all phases in the default.nix of my package I guess.
There seem to be only 15 wrapped package if I search repo:NixOS/nixpkgs unwrapped.nix context:global repo:NixO… - Sourcegraph
Thank you again.
The tip about cmake and ninja configuring the phases was perfect thank you.
Where is it defined though? in unwrapped.nix I only see the cmakeFlags attribute and ninja as a nativeBuildInput is that all that’s needed for them to hook the phases?
The runHook portion didn’t work for me though:
> nix develop nixpkgs#telegram-desktop.unwrapped
[nix] > type runHook
runHook is a function
runHook ()
{
local hookName="$1";
shift;
local hooksSlice="${hookName%Hook}Hooks[@]";
local hook;
for hook in "_callImplicitHook 0 $hookName" ${!hooksSlice+"${!hooksSlice}"};
do
_logHook "$hookName" "$hook" "$@";
_eval "$hook" "$@";
done;
return 0
}
[nix] > runHook configurePhase
no configure script, doing nothing
[nix] > runHook buildPhase
no Makefile or custom buildPhase, doing nothing
Mistyped. It’s runPhase.
It’s implemented in stdenv.mkDerivation and will run the hooks in <pkgs>/nix-support/<hook> (I don’t quite remember exactly), so you only need to include the package.