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

一笑奈何 提交于 2019-12-12 13:05:04

问题


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 which can be shared and backed up.

I am aware of using config.nix for for NixOS but I am looking for similar functionality with just Nix packages.


回答1:


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.



来源:https://stackoverflow.com/questions/50802880/reproducible-nix-env-i-with-only-nix-no-nixos

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!