2

In setting up NixOS (as of 22.11), I wanted to add Emacs to the system /etc/nixos/configuration.nix, so that it's always in the OS by default. In order to edit the system configuration with Emacs, I had to install Emacs first with:

nix-env -i emacs

As expected, after editing the environment.systemPackagesand a nixos-rebuild command, I have emacs in the OS and the next time I rebuild nixos, Emacs will be there (even if I nix-env --uninstall emacs).

Now, the question is, the stuff I installed with nix-env -i isn't reflected in the /etc/nixos/configuration.nix file. Since it's executed in the command line, these locally installed command set isn't very reproducible. (The same is true for the configurations that I will add in ~/.emacs.d)

My question is:

Is there a way to make local installs (e.g. emacs here) or local configurations (e.g. .emacs.d) also reproducible through a configuration file?

1

2 Answers 2

1

I do not recommend using nix-env -i to install any software, to make sure the system is reproducible, all system changes should be made by editing nixos-configuration.nix.

As for the configuration of emacs, it is recommended to modify it through home-manager.

If there are few configurations, you can manage them directly through home manager - programs.emacs.extraConfig).

If there are many configurations, it is recommended to use home manager - home.file.<name>.source for management.

To make the system more reproducible, I would recommend using NixOS with Flakes, here is a guide for that:

https://github.com/ryan4yin/nixos-and-flakes-book

2
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Jun 23, 2023 at 2:42
  • The first two links are 404. Can you fix them?
    – koppor
    Jan 23 at 14:52
0

Using nix-env to install packages for the system is not recommended. If you want to add packages to your system for all users, check this portion of the manual. In short, you edit your configuration.nix to have:

environment.systemPackages = with pkgs; [
    <your package here>
]

Then, if you want to edit the configuration for it, you can visit this website to see the options for that package. For example, in vim's case, an example config would be:

programs.vim = {
    enable = true;
    defaultEditor = true;
};

This way, you can have your entire configuration be declarative. If you want to have per-user programs and configs, you can follow the guide in @Vladimír Čunát's comment for home-manager. It's a little extra setup, but it's very similar to the way to install things for the entire system. Home-manager also has some extra options for some packages, so be sure to check them in the home-manager manual, one of which can be found here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .