nix-community / dream2nix

Simplified nix packaging for various programming language ecosystems [maintainer=@DavHau]
https://dream2nix.dev
MIT License
989 stars 122 forks source link

Help: Package library and use it in another flake #398

Open VolodiaPG opened 1 year ago

VolodiaPG commented 1 year ago

Hello,

I am currently having trouble using the result of the flake generated by dream2nix (I think).

I am trying to package a Python library that will be used in other projects as an import in scripts. However, I do not understand how to capture that package (the output, I guess?) and use it in another flake (or in the devshell of the dream2nix flake).

P.S. The flake.nix file is the following, if it helps.

```nix { inputs = { dream2nix.url = "github:nix-community/dream2nix"; src.url = "github:BeyondTheClouds/enoslib?rev=a9e30b09bd7d4191b5645f5c85191d94029938cd"; src.flake = false; }; outputs = { self , dream2nix , src , } @ inp: (dream2nix.lib.makeFlakeOutputs { systems = [ "x86_64-linux" ]; config.projectRoot = ./.; source = src; settings = [ { # optionally define python version subsystemInfo.pythonAttr = "python310"; } ]; }) // { defaultPackage = self.packages.x86_64-linux.main; }; } ``` Also, I generated the `dream-lock` in order for the packaging process to complete.
antotocar34 commented 1 year ago

If you remove the // { defaultPackage = self.packages.x86_64-linux.main; }; bit and run nix flake show, you will get the output

├───devShells
│   └───x86_64-linux
│       ├───default: development environment 'nix-shell'
│       └───main: development environment 'nix-shell'
├───packages
│   └───x86_64-linux
│       ├───default: package 'python3.10-default'
│       ├───main: package 'python3.10-main'
│       └───resolveImpure: package 'resolve'
└───projectsJson: unknown

and you see that the flake exposes packages.x86_64-linux.main.

PS. I'm not very experienced yet so I could be missing something :)

hsjobeki commented 1 year ago

As antotocar34 already wrote you can explore the attributes of the flake with „nix flake show“ If you want to build you run „nix build .#main“ (or other attributes) If you want to change the build behavior or format of the output you can apply overrides. (See the docs) Which could be needed if you want to consume it in another flake. You can Run „nix develop“ to enter the devShell of the flake