In my nixos flake I have an app which needs runtime dependencies, how to I add those ?
- User
In my nixos flake I have an app which needs runtime dependencies, how to I add those ?
- Assistant
You can add runtime dependencies to your NixOS flake in the
inputssection of theflake.nixfile. For example:{ description = "My NixOS configuration"; inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-20.09-darwin"; myapp = { url = "github:user/myapp"; inputs = { runtimeDependencies = [ "dependency1" "dependency2" ]; }; }; }; outputs = { ... }: { # Your NixOS configuration goes here nixosConfigurations = { my-hostname = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = [ # your modules go here ]; configuration = { # your configuration goes here }; pkgs = import nixpkgs { system = "x86_64-linux"; }; }; }; }; }Here, the
myapppackage has aninputssection where you can add yourruntimeDependencies. You can add the dependencies as a list of strings, where each string represents the package name. - User
Those are runtime dependencies for the entire flake, can't I just have them per app ?
- Assistant
Yes, you can specify the runtime dependencies per app by adding a
defaultPackageattribute to yourmyappinput in theflake.nixfile.For example, you can modify the
myappinput to include thedefaultPackageattribute like this:inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-20.09-darwin"; myapp = { url = "github:user/myapp"; inputs = { dependency1 = nixpkgs.pkgs.callPackage ./dependency1.nix {}; dependency2 = nixpkgs.pkgs.callPackage ./dependency2.nix {}; }; defaultPackage = myappPackage; }; };In this example, we are defining
dependency1anddependency2as inputs formyappand then specifying themyappPackageas thedefaultPackagefor the app.Then, you can define
myappPackageto includedependency1anddependency2as runtime dependencies like this:myappPackage = pkgs.stdenv.mkDerivation { name = "myapp"; src = ...; runtimeDependencies = [ myappDependency1 myappDependency2 ]; }; - User
That looks like something you just made up
- Assistant
I apologize for any confusion my previous response may have caused. It is true that
defaultPackageis not a recognized attribute in Nix that can be used in the way I had described.Instead of
defaultPackage, you can specify the app's runtime dependencies by creating a derivation for the app usingpkgs.stdenv.mkDerivation. Here's how you can do it:- In your
flake.nixfile, include the dependencies for your app in theinputssection, like this:
{ inputs = { myapp = { # app input details inputs = { dep1 = <dep1>; dep2 = <dep2>; }; }; }; } - In your