Skip to content

Declarative env management with nix profile is too hard #11544

Open
@dukc

Description

Describe the bug

So, I'm wanting to migrate my personal Nix configurations to flakes. I figured out that since the new-gen nix commands are needed to understand flakes, I should migrate my commands before I start rewriting my .nix files.

I'm managing my user environment declaratively, pretty much how the NixPkgs manual suggests except I put the buildEnv derivation as the top-level expression of the file. By running nix-env -irf file.nix the user environment gets rebuilt transactionally in a single step, just like NixOS gets with sudo nixos-rebuild switch.

Now, turns out the experience of trying to do the same with nix profile is subpar. First off, I can't do it transactionally with one command. I have to write nix profile remove '.*' followed by nix profile install -f file.nix.

If I try writing a bash script to automate this there's another problem. If the installation of the new profile fails, I want to roll back. But how is the script supposed to know what profile number to roll back to? There is no (documented) command to query the number of the current profile before the remove command. nix profile history indicates the current generation only by colour of the profile number in question.

Maybe with enough bash-fu I could extract the coloured number but frankly, this is way too hard. Unless I'm mistaken, I should be able to use nix profile as a drop-in replacement for nix-env. This is pretty far from it.

nix-env --version output
nix-env (Nix) 2.18.5

Metadata

Assignees

No one assigned

    Labels

    new-cliRelating to the "nix" commandprofilesVersioned gc root symlinks; nix profile, nix-env

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions