mirror of
https://github.com/ryan4yin/nixos-and-flakes-book.git
synced 2024-12-04 22:11:19 +01:00
2.2 KiB
2.2 KiB
Run downloaded binaries on NixOS
NixOS does not follow the FHS standard, so the binaries you download from the Internet will not likely work on NixOS. But there are some ways to make it work.
Here is a detailed guide that provides 10 ways to run downloaded binaries on NixOS: Different methods to run a non-nixos executable on Nixos, I recommend you to read it.
Among these methods, I prefer creating an FHS environment to run the binary, which is very convenient and easy to use.
To create such an environment, add the following code to one of your Nix modules:
{ config, pkgs, lib, ... }:
{
# ......omit many configurations
environment.systemPackages = with pkgs; [
# ......omit many packages
# create a fhs environment by command `fhs`, so we can run non-nixos packages in nixos!
(pkgs.buildFHSUserEnv (base // {
name = "fhs";
targetPkgs = pkgs: (
# pkgs.buildFHSUserEnv provides only a minimal fhs environment,
# it lacks many basic packages needed by most softwares.
# so we need to add them manually.
#
# pkgs.appimageTools provides basic packages needed by most softwares.
(pkgs.appimageTools.defaultFhsEnvArgs.targetPkgs pkgs) ++ with pkgs; [
pkg-config
ncurses
# feel free to add more packages here, if you need
]
);
profile = "export FHS=1";
runScript = "bash";
extraOutputsToInstall = ["dev"];
}))
];
# ......omit many configurations
}
After applying the updated configuration, you can run fhs
to enter the FHS environment, and then run the binary you downloaded, e.g.
# Activating FHS drops me in a shell which looks like a "normal" Linux
$ fhs
# check what we have in /usr/bin
(fhs) $ ls /usr/bin
# try to run a non-nixos binary downloaded from the Internet
(fhs) $ ./bin/code
References
- Tips&Tricks for NixOS Desktop - NixOS Discourse: Just as the title says, it is a collection of tips and tricks for NixOS desktop.