I’m modifying an existing program and I want to use a copy of the default.nix from nixpkgs to build my software. I don’t know how to expand pkgs or stdenv for use with callPackage and get the error:
error: evaluation aborted with the following error message: 'lib.customisation.callPackageWith: Function called without required argument "mkDerivation" at /nix/store/8yl19vnr44klhwjs0yr1ksjzj992z8yc-source/pkgs/my_openscad/default.nix:29'
I could manually pass in mkDerivation or modify default.nix to use pkgs.mkDerivation, but that can get tedious on large projects and makes upstream submissions harder.
Is there a way I can use callPackage that will work with the upstream nix file unmodified?
If you want to use it unmodified you’d use pkgs.openscad. If you want to modify it you’d use pkgs.openscad.override (or overrideAttrs as per the usecase). I find it unclear what you want to achieve though.
I want to change src in default.nix to point to a modified repository but I don’t want to make other changes to default.nix. This is a general issue I have with modifying nixpkgs.
I want to be able to call default.nix the way nixpkgs does, but from inside a flake.
That sounds like a bog-standard overrideAttrs use case. You aren’t ‘calling default.nix’, you’re taking an existing derivation and changing one of its attributes. You just need to do this:
pkgs.openscad.overrideAttrs {
src = <fetcher for your modified repository here>;
}
That’s helpful for this specific case, but I still have the problem of testing packages when writing new packages for nixpkgs. I want to pass in whatever nixpkgs does when it calls these packages.
I absolutely cannot figure out what you are trying to accomplish. If you want to modify nixpkgs, just clone it / modify it, build it? I have a copy of nixpkgs with a modified copy of the metals pkg on it, if I want to build it I just do?
~/src/thirdparty/nixpkgs metals-final-attrs ✘ 128
❯ nix repl --file './.'
Nix 2.24.14
Type :? for help.
Loading installable ''...
Added 24387 variables.
nix-repl> :b metals
This derivation produced the following outputs:
out -> /nix/store/lcn2bqsdh40ly4niym2jdigk4jwc5xsp-metals-1.5.2
[159 copied (1074.6 MiB), 585.5 MiB DL]
nix-repl>
I guess if you want to understand how to make something stand-alone then does this help? Here is some rando non-nixpkgs nix file that I found kicking around my src directory.