mirror of
https://github.com/ryan4yin/nixos-and-flakes-book
synced 2024-12-13 06:02:35 +00:00
59 lines
2.1 KiB
Markdown
59 lines
2.1 KiB
Markdown
|
## 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 which provides 10 ways to run downloaded binaries on NixOS: [Different methods to run a non-nixos executable on Nixos](https://unix.stackexchange.com/questions/522822/different-methods-to-run-a-non-nixos-executable-on-nixos), I recommend you to read it.
|
||
|
|
||
|
Among these methods, I prefer creating a 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:
|
||
|
|
||
|
```nix
|
||
|
{ 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.
|
||
|
|
||
|
```shell
|
||
|
# 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][Tips&Tricks for NixOS Desktop - NixOS Discourse]: Just as the title says, it is a collection of tips and tricks for NixOS desktop.
|