# Question Regarding configuration.nix

**URL:** https://discourse.nixos.org/t/question-regarding-configuration-nix/1619
**Category:** Help
**Created:** [December 7, 2018, 3:29am UTC](https://discourse.nixos.org/t/question-regarding-configuration-nix/1619 "2018-12-07T03:29:45Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![gpstrucker](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/g/f19dbf/32.png) [@gpstrucker](https://discourse.nixos.org/u/gpstrucker)
#### Post date: [December 7, 2018, 3:29am UTC](https://discourse.nixos.org/t/question-regarding-configuration-nix/1619/1 "2018-12-07T03:29:45Z")

</div>

Learning as I go and tweak things. Totally broke the system once, to the point I couldn’t log in as root or user, at which point I copied my configuration.nix file, edited out my mistakes, and reinstalled (rollback didn’t work). Learning from mistakes.

I’ve installed software via nix-env, some free, some unfree. My question is, should I be listing all of my software choices in the configuration.nix file? Just some of them? The basics? Still trying to get a handle of that part. I’m assuming the unfree stuff shouldn’t be listed as I don’t think it would install during rebuild, or am I wrong about that?

It’s a single user machine.

Thanks in advance for any and all input and advice.

---

<div class="post-metadata">

### Author: ![xte](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/x/7cd45c/32.png) [@xte](https://discourse.nixos.org/u/xte)
#### Post date: [December 7, 2018, 7:06am UTC](https://discourse.nixos.org/t/question-regarding-configuration-nix/1619/2 "2018-12-07T07:06:50Z")

</div>

Hi,  
relatively new NixOS user here, so… My strategy is simple: anything  
MUST go in configuration not done by hand, simply because doing so  
let you reinstall/replicate your _complete_ setup anywhere simply  
copying your config. IMO the ability to install stuff via CLI have to  
considered harmful…

To ease config reading I split in few files in /etc/nixos, more in  
details:

```nix
  imports =
    [
      ./hwconfig.nix
      ./pkgs.nix
      ./firewall.nix
      ./xserver.nix
      ./services.nix
      ./derivations.nix
      ./unstablepkg.nix
      ./cronjobs.nix
    ];

```

configuration.nix only contain boot setup, main user setup (since I’m  
on a personal desktop so I haven’t to deal with many users), network  
setup (just because, as above a personal desktop have a simple net  
setup) and very few other stuff, pkgs are

```nix
  environment.systemPackages = with pkgs; [
    ...
    zsh zsh-completions pavucontrol ...
  ];

```

plus settings like

```nix
  nixpkgs = {
    config = {
      packageOverrides ...

    allowUnfree = true;
    virtualbox.enableExtensionPack = true;

    ...

   };
  };

```

To have unstable pkg on NixOS stable

```nix
{ config, pkgs, ... }:

let
  unstableTarball =
    fetchTarball
      https://github.com/NixOS/nixpkgs-channels/archive/nixos-unstable.tar.gz;
in
{
  nixpkgs.config = {
    packageOverrides = pkgs: {
      unstable = import unstableTarball {
        config = config.nixpkgs.config;
      };
    };
  };

  environment.systemPackages = with pkgs; [
    unstable.masterpdfeditor unstable.anydesk
    # all pkg you want ... ... ... ...
  ];
}

```

You may also like homeManager when you start feeling at home with NixOS  
so a certain part of your config may go there. If you are an Emacs user  
perhaps you’ll like to put config in org-mode and sudo tangle to the  
right place so with a simple backup of your home/your datas you can also  
replicate the system that enable you to use those datas 🙂

– Ingmar

---

<div class="post-metadata">

### Author: ![mgttlinger](https://discourse.nixos.org/user_avatar/discourse.nixos.org/mgttlinger/32/392_2.png) [@mgttlinger](https://discourse.nixos.org/u/mgttlinger)
#### Post date: [December 7, 2018, 8:02am UTC](https://discourse.nixos.org/t/question-regarding-configuration-nix/1619/3 "2018-12-07T08:02:15Z")

</div>

My workflow the programs going into the configuration is this:

1. Install with nix-env and see if it is a useful addition to my system
2. From time to time I go though nix-env -q and uninstall or move to configuration if it has proven worthy

---

<div class="post-metadata">

### Author: ![7c6f434c](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/7/8e7dd6/32.png) [@7c6f434c](https://discourse.nixos.org/u/7c6f434c)
#### Post date: [December 7, 2018, 9:32am UTC](https://discourse.nixos.org/t/question-regarding-configuration-nix/1619/4 "2018-12-07T09:32:06Z")

</div>

> relatively new NixOS user here, so… My strategy is simple: anything  
> MUST go in configuration not done by hand, simply because doing so  
> let you reinstall/replicate your _complete_ setup anywhere simply  
> copying your config. IMO the ability to install stuff via CLI have to  
> considered harmful…

In general, of course, one can do some things via configuration and some  
things via separate expressions for use with nix-shell or just  
nix-build.

The reason for that might be that different subsets of things take  
different time to rebuild and have different freshness requirements, so  
rebuilding Chromium (used only for testing) doesn’t hold up the update  
of Firefox (which I actually care about).

nix-env … well, it has a lot of useful applications, but I am not sure  
plain `nix-env -i package` (and even `nix-env -iA package`) are  
something to use if you already want to use NixOS.

---

<div class="post-metadata">

### Author: ![qyliss](https://discourse.nixos.org/user_avatar/discourse.nixos.org/qyliss/32/34285_2.png) [@qyliss](https://discourse.nixos.org/u/qyliss)
#### Post date: [December 7, 2018, 10:33am UTC](https://discourse.nixos.org/t/question-regarding-configuration-nix/1619/5 "2018-12-07T10:33:52Z")

</div>

I agree that installing packages through `nix-env` is an antipattern. I go so far as to having an activation script that deletes `~/.nix-profile` so that I **can’t** use it, because otherwise things would collect in there that I would come to depend on, forget to update, and be stuck without if I rebuilt my system from scratch.

---

<div class="post-metadata">

### Author: ![gpstrucker](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/g/f19dbf/32.png) [@gpstrucker](https://discourse.nixos.org/u/gpstrucker)
#### Post date: [December 7, 2018, 3:06pm UTC](https://discourse.nixos.org/t/question-regarding-configuration-nix/1619/6 "2018-12-07T15:06:33Z")

</div>

Thanks for the replies. So as I understand it, many of you do not use nix-env to install software? What about “unFree” things like Google Chrome (which is my preferred browser)? Can those things be installed via configuration.nix along with the normal free stuff?

I appreciate your patience in answering my questions. I’m a long time Linux user but NixOS is a different animal entirely LOL.

The suggestion to create a separate file for packages makes a lot of sense to me.

---

<div class="post-metadata">

### Author: ![qyliss](https://discourse.nixos.org/user_avatar/discourse.nixos.org/qyliss/32/34285_2.png) [@qyliss](https://discourse.nixos.org/u/qyliss)
#### Post date: [December 7, 2018, 3:28pm UTC](https://discourse.nixos.org/t/question-regarding-configuration-nix/1619/7 "2018-12-07T15:28:03Z")

</div>

> Can those things be installed via configuration.nix along with the normal free stuff?

Yup! You just have to set an option in configuration.nix. I think it’s `nixpkgs.config.allowUnfree = true`.

---

<div class="post-metadata">

### Author: ![gpstrucker](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/g/f19dbf/32.png) [@gpstrucker](https://discourse.nixos.org/u/gpstrucker)
#### Post date: [December 7, 2018, 3:38pm UTC](https://discourse.nixos.org/t/question-regarding-configuration-nix/1619/8 "2018-12-07T15:38:14Z")

</div>

qyliss ok, thanks. I added that line but to actually install using nix-env I had to use NIXPKGS\_ALLOW\_UNFREE=1 nix-env -i to get them to install, so I assumed it wouldn’t work automatically via a nixos-rebuild.

I suppose I assumed incorrectly. I’ll give it a try.

---

<div class="post-metadata">

### Author: ![erictapen](https://discourse.nixos.org/user_avatar/discourse.nixos.org/erictapen/32/4190_2.png) [@erictapen](https://discourse.nixos.org/u/erictapen)
#### Post date: [December 7, 2018, 3:48pm UTC](https://discourse.nixos.org/t/question-regarding-configuration-nix/1619/9 "2018-12-07T15:48:06Z")

</div>

In your `configuration.nix`, you can allow all unfree packages with

```nix
nixpkgs.config.allowUnfree = true;

```

or allow specific packages with

```nix
nixpkgs.config.allowUnfreePredicate = (pkg: builtins.elem (builtins.parseDrvName pkg.name).name
  [
    "chromium"
  ]);

```

. You also need to add the package in environment.systemPackages.

---

<div class="post-metadata">

### Author: ![gpstrucker](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/g/f19dbf/32.png) [@gpstrucker](https://discourse.nixos.org/u/gpstrucker)
#### Post date: [December 7, 2018, 3:56pm UTC](https://discourse.nixos.org/t/question-regarding-configuration-nix/1619/10 "2018-12-07T15:56:00Z")

</div>

Ok, I’m listing stuff in configuration.nix and attempting to rebuild, but it keeps saying that cheese is an undefined variable. I keep looking at this and don’t see anything wrong, but perhaps I’m missing something obvious?

```auto
# List packages installed in system profile. To search, run:
  # $ nix search wget
 environment.systemPackages = with pkgs; [
   wget nano mc vlc ffmpeg gstreamer libdvdcss hplip git libreoffice handbrake pavucontrol gimp-with-plugins neofetch thunderbird transmission virtualbox weechat google-chrome skypeforlinux cheese ];

```

---

<div class="post-metadata">

### Author: ![erictapen](https://discourse.nixos.org/user_avatar/discourse.nixos.org/erictapen/32/4190_2.png) [@erictapen](https://discourse.nixos.org/u/erictapen)
#### Post date: [December 7, 2018, 4:02pm UTC](https://discourse.nixos.org/t/question-regarding-configuration-nix/1619/11 "2018-12-07T16:02:50Z")

</div>

Some packages are organised in separate sets, so they don’t pollute the root namespace.

In this case, `cheese` is supposed to be `gnome3.cheese`. You can find this out on [this site](https://nixos.org/nixos/packages.html#cheese) or by running `nix search cheese`.

---

<div class="post-metadata">

### Author: ![gpstrucker](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/g/f19dbf/32.png) [@gpstrucker](https://discourse.nixos.org/u/gpstrucker)
#### Post date: [December 7, 2018, 4:04pm UTC](https://discourse.nixos.org/t/question-regarding-configuration-nix/1619/12 "2018-12-07T16:04:34Z")

</div>

erictapen thank you! I saw that gnome3 prefix but didn’t realize it needed to be part of the name listed in configuration.nix.

I appreciate the help. I’m learning.

---

<div class="post-metadata">

### Author: ![gpstrucker](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/g/f19dbf/32.png) [@gpstrucker](https://discourse.nixos.org/u/gpstrucker)
#### Post date: [December 7, 2018, 4:05pm UTC](https://discourse.nixos.org/t/question-regarding-configuration-nix/1619/13 "2018-12-07T16:05:27Z")

</div>

Yep, that did the trick

---

<div class="post-metadata">

### Author: ![qyliss](https://discourse.nixos.org/user_avatar/discourse.nixos.org/qyliss/32/34285_2.png) [@qyliss](https://discourse.nixos.org/u/qyliss)
#### Post date: [December 7, 2018, 4:12pm UTC](https://discourse.nixos.org/t/question-regarding-configuration-nix/1619/14 "2018-12-07T16:12:08Z")

</div>

Oh, I didn’t know about `allowUnfreePredicate`. That’s really useful!

---

<div class="post-metadata">

### Author: ![bobvanderlinden](https://discourse.nixos.org/user_avatar/discourse.nixos.org/bobvanderlinden/32/59_2.png) [@bobvanderlinden](https://discourse.nixos.org/u/bobvanderlinden)
#### Post date: [December 7, 2018, 6:37pm UTC](https://discourse.nixos.org/t/question-regarding-configuration-nix/1619/15 "2018-12-07T18:37:25Z")

</div>

I still wish nix-env was gone and we had a simple `nix install` command to add a package to project/home/system Nix file. In addition, having a lock file that pins nixpkgs, again for project/home/nix.

Currently I’m using /etc/nixos/configuration.nix for anything that is needed to get a working system and a practical environment for root. I use home-manager for most other packages and configuration. Lastly I use direnv with shell.nix for project specific dependencies.

I still find the workflow a bit awkward, but regardless I’m using vim or vscode to edit these files and then rebuild the environment. For project files it rebuilds the environment automatically by direnv which is pretty cool.

---

<div class="post-metadata">

### Author: ![rycee](https://discourse.nixos.org/user_avatar/discourse.nixos.org/rycee/32/219_2.png) [@rycee](https://discourse.nixos.org/u/rycee)
#### Post date: [December 7, 2018, 10:28pm UTC](https://discourse.nixos.org/t/question-regarding-configuration-nix/1619/16 "2018-12-07T22:28:18Z")

</div>

> If you are an Emacs userperhaps you’ll like to put config in org-mode and sudo tangle to the right place so with a simple backup of your home/your datas you can also replicate the system that enable you to use those datas

Or [let Nix do it™](https://gitlab.com/rycee/configurations/blob/745260f1069b90156396d88797c9e56cfe484170/user/emacs.nix) 😉

---

<div class="post-metadata">

### Author: ![qyliss](https://discourse.nixos.org/user_avatar/discourse.nixos.org/qyliss/32/34285_2.png) [@qyliss](https://discourse.nixos.org/u/qyliss)
#### Post date: [December 8, 2018, 2:51pm UTC](https://discourse.nixos.org/t/question-regarding-configuration-nix/1619/17 "2018-12-08T14:51:23Z")

</div>

A nice simple solution that would cover this use-case would just be to have an `/etc/nixos/pkgs.json` that was imported into configuration.nix. Then it would be pretty straightforward to write a tool that could add/remove JSON entries in that file. Would be a nice start, and an improvement over `nix-env`, IMO.

Could even have per-user files that were included in the user configuration.

---

<div class="post-metadata">

### Author: ![pvgoran](https://discourse.nixos.org/user_avatar/discourse.nixos.org/pvgoran/32/1240_2.png) [@pvgoran](https://discourse.nixos.org/u/pvgoran)
#### Post date: [December 8, 2018, 3:01pm UTC](https://discourse.nixos.org/t/question-regarding-configuration-nix/1619/18 "2018-12-08T15:01:43Z")

</div>

There **are** certain uses for `nix-env -i`. For example, I use it on my NixOps-managed machines because running non-installed programs with `nix-shell` quickly becomes annoying, and rebuilding the entire NixOps network just to have something like `telnet` or `iftop` available for quick inspection is overkill.

---

<div class="post-metadata">

### Author: ![qyliss](https://discourse.nixos.org/user_avatar/discourse.nixos.org/qyliss/32/34285_2.png) [@qyliss](https://discourse.nixos.org/u/qyliss)
#### Post date: [December 8, 2018, 3:19pm UTC](https://discourse.nixos.org/t/question-regarding-configuration-nix/1619/19 "2018-12-08T15:19:37Z")

</div>

I’d say that rebuilding the networking feeling like overkill is a deficiency of NixOps rather than a good reason for `nix-env`.

---

<div class="post-metadata">

### Author: ![ryantm](https://discourse.nixos.org/user_avatar/discourse.nixos.org/ryantm/32/900_2.png) [@ryantm](https://discourse.nixos.org/u/ryantm)
#### Post date: [December 8, 2018, 10:15pm UTC](https://discourse.nixos.org/t/question-regarding-configuration-nix/1619/20 "2018-12-08T22:15:32Z")

</div>

The main use I see for `nix-env` is systems that serve two (or more) people who each want to manage their installed software in isolation from one another (But, those people could do it declaratively with home-manager). Since I don’t have a system like that that I manage, I also try to avoid using nix-env and channels too.

> [@mgttlinger](#):
>
> 1. From time to time I go though nix-env -q and uninstall or move to configuration if it has proven worthy

Thanks for the tip!

[Next page](https://discourse.nixos.org/t/question-regarding-configuration-nix/1619.md?page=2)
