Reproducible nix-env -i with only Nix, no NixOS

前端 未结 1 1891
伪装坚强ぢ
伪装坚强ぢ 2021-01-20 00:43

I am only using Nix as a package manager and not using all of NixOS. I would like a reproducible nix-env -i package installation whic

相关标签:
1条回答
  • 2021-01-20 00:49

    From Nixpkgs you can use the buildEnv function to construct symlink farms similar to how nix-env produces them.

    This lets you group packages together into groups that you want to update separately. Of course a single group is perfectly valid if that suits your applications.

    Here's an example greeting-tools.nix:

    let
      pkgs = import <nixpkgs> {};
      inherit (pkgs) buildEnv;
    
    in buildEnv {
      name = "greeting-tools";
      paths = [ pkgs.hello pkgs.cowsay pkgs.figlet ];
    }
    

    You can install it and remove it as follows

    $ nix-env -i -f greeting-tools.nix
    installing 'greeting-tools'
    $ hello
    Hello, world!
    $ nix-env -e greeting-tools
    uninstalling 'greeting-tools'
    $ hello
    The program ‘hello’ is currently not installed. [...]
    

    To update your packages, you have to re-run the installation command. nix-env -u will not work correctly because that only looks at Nixpkgs, which probably doesn't have anything named like that.

    An alternative may be home manager.

    0 讨论(0)
提交回复
热议问题