What is the common way to install utility programs like file and ripgrep in NixOS - nix

I want these programs to be installed in my user environment while not using nix-shell and nix-env (I was told to not use nix-env). I tried to use home-manager but I can't do program.file/ripgrep bc it's not an option. May I ask what is the common approach to install things like file and ripgrep in NixOS?

With home-manager, you can install programs by adding them by adding them in home.packages. For instance, if you want to install ripgrep, you could add in your home.nix:
home.packages = [
pkgs.ripgrep
];
Or, more conveniently
home.packages = with pkgs; [
ripgrep
];
You can add any program you want in that list.
Note that there is a difference between installing them with home-manager, and by adding it in environment.systemPackages, which is that the former will only install them for the user, while the latter will install system-wide. Besides that, both work similarly.

You should be able to set this in your nixos config:
environment.systemPackages = [
rigrep
file
];
I have no experience with home-manager so I don't know how it compares, but you should surely be able to install ripgrep with it.
I've been using nix-env for years without issue, only negatives is it's harder to keep track of things. But works fine for things you want to install 'temporarily' to have them available in your $PATH without having to invoke nix-shell.

Related

How can I create home-nix file from my current configuration

What I think that I've understood about home-manager.
Instead of using
nix-env iA packageToBeInstalled
you write a list of package in a file (/home/nixos/.config/nixpkgs/home.nix that I from now on call just home.nix)
you run
home-manager switch
and the package are installed.
But I have already installed some packages with nix-env. (home-manager for instance)
I would like to have my configuration save just in home.nix in order to just have to import it and execute home-manager switch to import the exact same configuration in a other OS.
Therefore I need a command replicating my configuration in home.nix.
I am not aware of a tool that fully automates this.
The nix-env list of installed packages is maintained in ~/.nix-profile/manifest.nix, but does not contain the attribute path, which is the "name" you need to use in such configuration files.
To find the attribute paths for the things you've installed, you may first create an index of sorts based on your current nixpkgs (NIX_PATH etc):
nix-env -qaP >packages.tmp
and then use it to look up each package.
Here's a one-liner that doesn't work for all packages.
nix-env -q | while read name; do grep "$name" <packages.tmp; done
So make sure to read through nix-env -q yourself and look up anything that's missing using for example https://search.nixos.org/packages.
To finalize, remove the imperatively installed packages with nix-env -e, check nix-env -q, and rm packages.tmp.

Why VI always starts in insert mode?

At some point, whenever I use vi from the command line (windows 10/WSL) it starts up in insert mode, meaning that everything I usually do to navigate ends up adding stuff to the file, wasting time having to clean it up.
I didn't have a vimrc file, and there doesn't seem to be anything in my bash rc files to modify vi behavior. Any ideas what I may have done or any ideas how to stop this behavior? I'm using Ubuntu-20.04
FWIW, adding a .vimrc file with tab related settings didn't change it's behavior. I looked at the /etc/vimrc file, and nothing inside it seemed relevant.
After plowing through google search and trying everything I understand about configuring 'vim' and doing comparison tests, I think:
This behavior is specific to Windows Terminal when opening a WSL terminal. Using WSL's "native" terminal (i.e., clicking the "Ubuntu 20.04 LTS" menu in the "Start" menu) doesn't have this problem.
My original motivation for switching to Windows Terminal is for its multi-tab feature. But this new behavior is crazy -- it works against years of my muscle memory of using "vi", and I'm almost certain that one day I'll accidentally update some configuration file while reading it in "vi". And, I cannot re-train a new muscle memory because all the rest of the UNIX world (e.g., when I SSH into a remote server) hasn't changed. This is like constantly switching between a Mac keyboard and a PC keyboard where the Ctrl key, etc., are in different places.
My solution: I switched to MobaXterm. It has multi-tab support, and is actually richer in features compared to Windows Terminal.
Please run the following:
alias | grep vim
sudo find / -name .vimrc 2>/dev/null
These commands should show you all the places to check, change the alias or fix the .vimrc files found.
Do you find it always going into edit mode, when you vim a file directly and when you use vim as the git commit editor for example?
EDIT:
You could also try which -a vim or whereis vim to see if you have multiple versions. Or failing that sudo find / -name vim 2>/dev/null
here is a better solution. I downloaded the binary.
https://github.com/lxhillwind/vim-bin/releases/tag/v9.0.0978
Put the vim command in /usr/bin/vi
Put the runtime in:
/usr/local/share/vim/runtim
sudo apt remove vim vim-common vim-runtime vim-tiny
sudo apt purge vim vim-common vim-doc vim-runtime vim-tiny
The second line actually gets rid of residual-defaults.
There is also a defaults.vim someplace on the system. I just nuked it.
I went through and made sure there were no aliases or vi or vim configuration files, but still no luck.
This is a horrible solution, but the only thing that is keeping my sanity right now.
vi -c ":imap jj "
You can alias it in your .bashrc. Looking into better solutions.

How to install Erlang or Elixir with Observer using the Nix package manager?

Every time I install Erlang, I end up without Observer. Used the commands below on a Ubuntu laptop with Xmonad and a Debian 9 running in the cloud, and seemingly they both resulted in the same package being installed:
nix-env -iA pkgs.beam.packages.erlangR22
nix-env -iA nixpkgs.beam.interpreters.erlang
nix-env -iA nixpkgs.beam.interpreters.erlangR22_odbc_javac
The Nixpkgs manuals 15.2. BEAM Languages (Erlang, Elixir & LFE) section (Version 19.09.1484.84586a4514d) does not mention Observer at all. It has a fairly recent update by DianaOlympos that does mention it, albeit I tried all these packages, but no joy:
Many Erlang/OTP distributions available in beam.interpreters have versions with ODBC and/or Java enabled or without wx (no observer support). For example, there's beam.interpreters.erlangR22_odbc_javac, which corresponds to beam.interpreters.erlangR22 and beam.interpreters.erlangR22_nox, which corresponds to beam.interpreters.erlangR22.
Shane Sveller pointed it out that the wxGTK package needs to be set up using propagatedBuildInputs, but not sure how to do that. (Simply just installing wxGTK then Erlang doesn't work of course; was naive enough to try it. Also found out that chapter 20 of Nix Pills is exactly about this topic.)
This is also kind of a follow-up to the question "How to install Erlang/Elixir on a non-NixOS system?", but I didn't realize it then that Observer is missing...
update: Apparently, it works somewhere out of the box. (Probably on NixOS.)
I have an overwrite for erlang, such that wx support is enabled:
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
let
inherit (lib) optionals;
erlang_wx = erlangR21.override {
wxSupport = true;
};
elixir = (beam.packagesWith erlang_wx).elixir.override {
version = "1.9.2";
rev = "ffe7a577cc80f37381dc289c820842d346002364";
sha256 = "19yn6nx6r627f5zbyc7ckgr96d6b45sgwx95n2gp2imqwqvpj8wc";
};
in
mkShell {
buildInputs = [ elixir git ]
# For file_system on Linux.
++ optionals stdenv.isLinux [ inotify-tools wxGTK ]
# For file_system on macOS.
++ optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [
# For file_system on macOS.
CoreFoundation
CoreServices
wxmac
]);
}
Save this (as shell.nix for example), and just run it:
$ nix-shell shell.nix
# or, if you are in the same directory:
$ nix-shell
Works on my machine!
Note: wxmac in buildInputs is specific to MacOS (and wxGTK to Linux). To find the right package for your OS, here are the available wx packages.
Kind of ashamed to admit that I am an idiot, but Observer was there all this time (along with net_adm)...
For some reason, it wouldn't autocomplete on the erl shell, but once observer:start(). was typed in and executed, it would recognize the module, and provide a list of available functions when hitting the Tab key.
I probably messed up translating between iex and erl ( observer.start(). and other combinations), and I assumed that the resulting error message (together with no autocompletion) means that the module was missing.

How can I reset my nix environment to the original user profile?

I believe I ran nix-env -if example.nix which changed my nix environment.
How can I undo this action?
I'm trying to run a application that is specified in my nixos config (/etc/nixos/*), however it no longer seems available (within the $PATH).
Seems it might be nix-env --switch-profile /nix/var/nix/profiles/default (according to https://nixos.org/nix/manual/#sec-profiles) ?
I run nix-env -e '*' to remove all packages from my profile installed via nix-env regularly and move anything I want to use into environment.systemPackages so all my packages are tracked in my nixos configuration declaratively. As for debugging why the application specified in your configuration.nix isn't in your path, an application specified in your configuration.nix should be symlinked to /run/current-system/sw/bin, so the first thing would be to check that the binary you're looking for is listed in there and second that is in your $PATH.

How to pass env variables to GNOME

I want to replace some utilities(like telnet) with transparent wrappers(with loggers).
At first I used aliases, that worked nicely at the command line but gnome doesn't understand shell aliases so that when people would launch the utilities as the shell for a gnome-terminal profile it would run the actual utility instead of the wrapper.
Then I tried adding new folder with symlinks and prepended it to PATH(security isn't a huge concern plus its a special folder just for these symlinks) in ~/.bashrc but they still run the original(I'm guessing gnome doesn't run .bashrc since it works from the command line). Any ideas where setting path needs to go?
Maybe update-alternatives fits your needs?
I found two ways to do this that seem to work like I want(sourcing scripts for gnome env).
First putting it in ${HOME}/.gnomerc (but I found some places that say you should manually exec gnome session afterwards and others that don't(It seems to work fine without it) and I'm afraid of breaking login.)
Putting it in ~/.profile seems to work so I just
echo 'PATH=~/.symlink_dir/:${PATH}' > ~/.profile
(note that this is ignored by bash if a ~/.bash_profile exists so you may want to manually source it from ~/.bash_profile just in case
echo 'source ~/.profile' >> ~/.bash_profile).
If you really want to use your replacement utilities throughout, you could put symlinks to your replacements in /usr/bin/ (or wherever as appropriate) and move the originals to /usr/bin/originals/ (or wherever).
If you do that, you'd better make sure that your wrappers are rock solid though. Depending on what you're replacing, errors might prevent booting, which is generally undesirable.
It might not be what you are asking, but have you tried changing the commands of the launchers from the menu editor.
If you are using Gnome 3 you will have to download the alacarte package.

Resources