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 ...
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… &...
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 ...
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 ...
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) ...
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 ...
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 ...
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
...
18
votes
How can I set a custom DNS server within Nixos?
networking.nameservers = [ "1.1.1.1" "9.9.9.9" ];
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:
...
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 = [ "...
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 ...
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 ...
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 ...
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 '~/...
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 = {
&...
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 --...
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`
- ...
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 ...
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,...
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
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....
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/...
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-...
7
votes
Accepted
Change systemd stop job timeout in NixOS configuration
Add the following to your configuration.nix:
systemd.extraConfig = ''
DefaultTimeoutStopSec=10s
'';
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 ...
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, ...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
nixos × 360nix × 119
linux × 19
systemd × 13
package-management × 13
gnome × 11
configuration × 10
networking × 8
boot × 7
audio × 7
nixpkgs × 7
kde × 6
x11 × 5
usb × 5
grub2 × 5
shell × 4
arch-linux × 4
wifi × 4
software-installation × 4
xorg × 4
docker × 4
lvm × 4
grub × 4
virtual-machine × 4
udev × 4