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

nix profile pins nixpkgs per package #7964

Open
bobvanderlinden opened this issue Mar 4, 2023 · 5 comments
Open

nix profile pins nixpkgs per package #7964

bobvanderlinden opened this issue Mar 4, 2023 · 5 comments
Labels
bug new-cli Relating to the "nix" command

Comments

@bobvanderlinden
Copy link
Member

Installing packages from different sources results in huge downloads. I think it's not what most new users would anticipate, as it deviates from how other package managers deal with this. To make this worse, it's hard to avoid.

For example:

$ nix profile install github:nixos/nixpkgs/nixpkgs-unstable#cowsay
# A week later:
$ nix profile install github:nixos/nixpkgs/nixpkgs-unstable#vim

Now 2 different versions of nixpkgs are pinned. This behavior has a number of downsides:

  • It results in huge downloads (long waiting time)
  • It results in huge disk space usage (until all packages are upgraded and store GCed)
  • It behaves differently from most package managers, where the package manager is usually pinned to a single package set until you explicitly tell it to update the package set (apt update, pacman -y, etc).
  • It can result in incompatibilities when plugin-like libraries (like in lib/gtk-3.0, lib/qt4/plugins) are used across multiple packages from differently pinned nixpkgs. These libraries are linked against different versions of glibc, which can result in runtime problems. It's fine if the user explicitly wants to do this, but currently it's the default with nix profile.

There are some advantages to having a nixpkgs-pin per package, but currently it is the default and shouldn't be something new users need to be aware of.

  • The advantages are that the packages in nix profile are kept as-is, thus stable.
  • Upgrading individual packages is possible, usually without major problems.
@bobvanderlinden
Copy link
Member Author

bobvanderlinden commented Mar 8, 2023

After keeping this in the back of my mind for some time I now think there are no advantages to pinning invidiual packages.

What if we represent a profile as a flake with inputs (the repositories) and a single output (the profile).

When installing using nix profile install github:nixos/nixpkgs/nixpkgs-unstable#hello, the repository is github:nixos/nixpkgs/nixpkgs-unstable. If this repository isn't in the inputs yet, it is added, otherwise the existing input it used. hello is a package of that input.

This way whenever you're upgrading your packages, they'll all be on the same repository with minimal extra disk space usage.

If you want to upgrade/downgrade a package, you just use:

nix profile remove 0 # Index of previously installed "hello" package
nix profile install github:nixos/nixpkgs/nixos-22.05#hello

It'll keep tracking that version of the repository.

If you want to pin a package, you can do so using:

nix profile remove 0
nix profile install github:nixos/nixpkgs/ba0486f045d4f7f304bd8c4a939ca2e658affcc8#hello

There is no need to deviate from flakes for profiles. I think manifest.json may be deprecated and a flake-based approach chosen for profiles.

This also makes Nix profiles more reproducible, as we can handle flakes quite easily. The only thing missing is a flag to specify which flake to alter when using nix profile. nix profile --flake ~/.config/nix/profiles/default install hello.

What about introducing a profiles output in flakes?

{
  inputs = {
    nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
  };
  outputs = { nixpkgs-unstable, ... }: {
    profiles.default = (system: [
      nixpkgs-unstable.packages.${system}.hello
    ]);
  };
}

nix profile can use nix edit and an AST to alter the flake.nix file.

@roberth roberth added the new-cli Relating to the "nix" command label Mar 16, 2023
@andrewhamon
Copy link

To add to this... nix profile has started to remind me of one of my least favorite package manager anti features - homebrew auto-updates!

I'd prefer if the chosen flake was fixed until I explicitly asked to fetch a new one (maybe using a mechanism like nix-channel, though I never liked nix-channel).

@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/flakes-as-a-unified-format-for-profiles/29476/1

@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/flakes-as-a-unified-format-for-profiles/29476/2

@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/flakes-as-a-unified-format-for-profiles/29476/6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug new-cli Relating to the "nix" command
Projects
None yet
Development

No branches or pull requests

4 participants