I want to use nix declaratively, as described in NixOS - Nixpkgs 21.11 manual. I have a single-user-installation on a ubuntu machine.
Here is something that I have written in my nixpkgs-config-file:
myCollection = pkgs.buildEnv {
name = "my-collection";
paths = [
go_1_18
bat
];
extraOutputsToInstall = [ "man" "doc" ];
Installing this package works quite well:
% nix-env --install --attr nixpkgs.myCollection
installing 'my-collection'
these derivations will be built:
/nix/store/l10j8fgnzrj9ppmhs3xzfy2ql3jdf9fr-my-collection.drv
these paths will be fetched (2.32 MiB download, 5.82 MiB unpacked):
/nix/store/8q43hvxghly0r3c7i2qd7069lh5axzk5-less-600
/nix/store/az5qvil5l9vqbg0frni29727zacx4wbq-bat-0.21.0
copying path '/nix/store/8q43hvxghly0r3c7i2qd7069lh5axzk5-less-600' from 'https://cache.nixos.org'...
copying path '/nix/store/az5qvil5l9vqbg0frni29727zacx4wbq-bat-0.21.0' from 'https://cache.nixos.org'...
building '/nix/store/l10j8fgnzrj9ppmhs3xzfy2ql3jdf9fr-my-collection.drv'...
created 9 symlinks in user environment
building '/nix/store/gk1zvxrsxrb5pv77zwpn0br003l2pg3y-user-environment.drv'...
created 71 symlinks in user environment
However updating does not work well:
% nix-env --upgrade --always
error: undefined variable 'go_1_18' at /home/user/.config/nixpkgs/config.nix:117:9
(use '--show-trace' to show detailed location information)
nix-env --upgrade --always 23.35s user 8.76s system 57% cpu 55.473 total
What is the reason for this behaviour? I want to comfortably update the self-created package. How can I do this?
Adding with pkgs; seems to be not the only issue I have. Could you help me again? Probably it is something small. I tried it out with the following file:
{
allowUnfree = true;
packageOverrides = pkgs: with pkgs; {
myCollection = pkgs.buildEnv {
name = "my-collection";
paths = with pkgs; [
go_1_18
bat
];
extraOutputsToInstall = [ "man" "doc" ];
};
};
}
Then the following failing sequence happened:
% nix-env --install --attr nixpkgs.myCollection
installing 'my-collection'
these derivations will be built:
/nix/store/nqi401122xck6g4s40waxrm5f0gf682r-my-collection.drv
these paths will be fetched (2.33 MiB download, 5.87 MiB unpacked):
/nix/store/1wgqhayxkifd1aiq3c4lqwinbplrrxm0-less-600
/nix/store/s86dg0d7pp4wrxx34bmxfkf2xayv21jb-bat-0.21.0
copying path '/nix/store/1wgqhayxkifd1aiq3c4lqwinbplrrxm0-less-600' from 'https://cache.nixos.org'...
# […]
created 71 symlinks in user environment
% nix-env --upgrade --always
error: undefined variable 'go_1_18' at /home/user/.config/nixpkgs/config.nix:7:9
(use '--show-trace' to show detailed location information)
I think you have found the issue. I installed “go_1_18” because just mentioning “go” as a package did not work and installed me go-1.16 in the past. Here is the reason: