Skip to main content
123 votes
Accepted

Different methods to run a non-nixos executable on Nixos

Related answers If you plan to package a binary and not just run it, you might like this other answer of mine: How to package my software in nix or write my own package derivation for nixpkgs Short ...
tobiasBora's user avatar
  • 4,671
52 votes
Accepted

How to package my software in nix or write my own package derivation for nixpkgs

NB: this answer is not yet fully complete, but it's already a good starting point. I plan to add more language-specific stuff later (or maybe to create one question per language too keep this answer… &...
tobiasBora's user avatar
  • 4,671
43 votes
Accepted

How do I modify my hosts file in Nixos?

Modify the nixos config (usually in /etc/nixos/configuration.nix) with: networking.extraHosts = '' 127.0.0.2 other-localhost 10.0.0.1 server ''; This is documented at NixOS Wiki and ...
Chris Stryczynski's user avatar
37 votes
Accepted

What are the main differences between GuixSD and NixOS?

As a Guix user, the primary differences seemingly are: Guix does not package proprietary software in the official repo; Nix does. Nix use systemd; Guix use GNU Shepherd. Nix configuration is in a ...
ces's user avatar
  • 546
33 votes

How to find out which (not installed) package a file belongs to on NixOS?

nix-index is what you need. Install and build the index: nix-env -iA nixos.nix-index nix-index Locate libgtk-x11-2.0.so.0: nix-locate -w libgtk-x11-2.0.so.0 Output: (zed.out) ...
R. Taukulis's user avatar
30 votes
Accepted

How do I upgrade Nixos to use a new channel nixos version?

To upgrade NixOS: Ensure you have a backup of your NixOS installation and that you know how to restore from the backup, if the need arises. Review the NixOS release notes to ensure you account for any ...
Emmanuel Rosa's user avatar
25 votes

How to add a file to /etc in NixOS?

To create a file in /etc on NixOS, use environment.etc in configuration.nix. Here's an example: environment.etc = { # Creates /etc/nanorc nanorc = { text = '' whatever you want to put ...
Emmanuel Rosa's user avatar
18 votes

How to disable suspend on close laptop lid on NixOS?

While the solution proposed by Mirzhan will probably work, there is a much more elegant way using the services.logind.lidSwitch and services.logind.lidSwitchDocked options. Now, you can just write ...
lschuermann's user avatar
18 votes

How can I set a custom DNS server within Nixos?

networking.nameservers = [ "1.1.1.1" "9.9.9.9" ];
0fnt's user avatar
  • 447
17 votes

How to add a file to /etc in NixOS?

Additionally, you can also add a file from a path with: environment.etc = { somerc.source = /etc/somerc; }; Or a directory: environment.etc = { aDir.source = ./aDir; }; Or a package path: ...
Steve Chavez's user avatar
11 votes

In NixOS, how to add a user to the sudoers file?

Adding a user to the wheel group should be sufficient to gain sudo privileges. users.extraUsers.matthew = { isNormalUser = true; home = "/home/matthew"; extraGroups = [ "...
Chris Stryczynski's user avatar
11 votes
Accepted

How to replace OpenSSL with LibreSSL globally?

From the official GitHub page: Compatibility with OpenSSL: LibreSSL is API compatible with OpenSSL 1.0.1, but does not yet include all new APIs from OpenSSL 1.0.2 and later. LibreSSL also includes ...
Artem S. Tashkinov's user avatar
11 votes
Accepted

Do GUIX and NixOS differ architecturally?

Basically, there aren't any architectural differences between the two distributions, except for the way they handle the init system: Guix System uses GNU Sheperd while NixOS uses System D. To the best ...
Loïc Reynier's user avatar
10 votes
Accepted

Warning about ownership of "/var/db/sudo/lectured" whenever using sudo

The directory and what's created inside is what presents the message to the user upon becoming sudo which is normally something along the lines of: We trust you have received the usual lecture from ...
Nasir Riley's user avatar
  • 12.3k
9 votes

How to install npm packages in NixOS?

As an alternative, I also found CMCDragonkai's comment on the Nixpkgs issue #3393: I just found out that you can change NPM's prefix directory. Something like: npm config set prefix '~/...
toraritte's user avatar
  • 1,222
9 votes

How to set the default browser in NixOS?

For Apps Following the XDG Spec As of NixOS 21.11 or later, one may now set xdg.mime.defaultApplications. For example, to make Qutebrowser the default web browser: xdg.mime.defaultApplications = { &...
nrdxp's user avatar
  • 191
9 votes

How to force Nix to “install packages” by building them locally instead of downloading a pre-built binary?

Either set the substitute option to false in nix.conf (the default is true) or use --option substitute false when invoking a Nix command. nix-env --options substitute false -i hello nix-shell --...
toraritte's user avatar
  • 1,222
8 votes

Command to view which version of NixOS my machine is running?

$ nix-info -m - system: `"x86_64-linux"` - host os: `Linux 5.10.79, NixOS, 21.05.4116.46251a79f75 (Okapi)` - multi-user?: `yes` - sandbox: `yes` - version: `nix-env (Nix) 2.3.16` - ...
rofrol's user avatar
  • 277
8 votes

In nixos, how to remap caps lock to control?

As you already tried, and as grwlf suggests, you can enable this in X11 by adding services.xserver.xkbOptions = "ctrl:swapcaps"; to /etc/nixos/configuration.nix. To apply this setting in ...
gmarmstrong's user avatar
  • 1,293
8 votes
Accepted

How to install java in NixOS?

There are two Java compilers available via Nixpkgs: OpenJDK and OracleJDK, named openjdk and oraclejdk, respectively. Note that the OracleJDK doesn't seem to be available in the top-level expression,...
Emmanuel Rosa's user avatar
8 votes
Accepted

How to list package dependents on Nix?

You are looking for nix-store --query --referrers /nix/store/...(insert full path here)... Cf. https://nixos.org/manual/nix/stable/#operation-query-1
Heinrich Hartmann's user avatar
7 votes

In nixos, how to remap caps lock to control?

Let's say you have a configuration.nix like this. services.xserver.enable = true; services.xserver.layout = "pl"; services.xserver.xkbOptions = "ctrl:nocaps"; services....
425nesp's user avatar
  • 456
7 votes
Accepted

how to find which packages are installed system-wide in NixOS?

There's no specific tool for this. You may like the system.copySystemConfiguration option (see the docs for "caveats"). You'll get relatively close with nix-store -q --references /run/current-system/...
Vladimír Čunát's user avatar
7 votes
Accepted

How to rebuild the configuration of a NixOS installation from Live CD?

The simplest way to go is to install from the LiveCD. nixos-generate-config will regenerate the hardware config, but if it finds configuration.nix already exists it will leave it alone. And nixos-...
Emmanuel Rosa's user avatar
7 votes
Accepted

Change systemd stop job timeout in NixOS configuration

Add the following to your configuration.nix: systemd.extraConfig = '' DefaultTimeoutStopSec=10s '';
Mic92's user avatar
  • 271
7 votes
Accepted

Debugging why nix is building a package unnecessarily when it should be in nixpkgs binary cache?

We can search for the HUnit package in Hydra (for 19.03): https://hydra.nixos.org/eval/1552169?filter=HUnit&compare=1551557&full=#tabs-still-fail According to the above HUnit is built and ...
Chris Stryczynski's user avatar
7 votes

How to get /bin/bash on nixos

The standard POSIX shell is sh, not bash. So you can assume POSIX systems will have a bourne-compatible shell available and called sh, but there is no reason to assume they will have bash installed, ...
terdon's user avatar
  • 252k
7 votes

How to get the size of a Nix derivation?

You may want nix path-info (e.g., for emacs): $ nix-build -A emacs '<nixpkgs>' $ nix path-info -Sh ./result /nix/store/3l9lddwxz1mayaxvw8iy50ygzzfh1s1b-emacs-27.2 470.4M From the Nix release ...
Henri Menke's user avatar
6 votes

How to set the default browser in NixOS?

For Home Manager: The system-wide settings on nrdxp's answer may be ignored for one reason or another, so if it doesn't work and you're using Home Manager, try setting them per-user. To do that, you ...
CrazyStevenz's user avatar
6 votes
Accepted

Can I manage my NixOS configuration in version control like git?

The NixOS configuration consists of two files (although you can break it up into more files): configuration.nix and hardware-configuration.nix. Both files are stored in /etc/nixos and they are text ...
Emmanuel Rosa's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible