Flake A build a Python package using poetry2nix : myPythonApp
Flake B build a Haskell lib using haskell.nix : a specific pandoc version
Flake A need Flake B to run correctly using poetry : poetry run /results/bin/myPythonApp
The A flake is defined like that
{
description = "Application packaged using poetry2nix";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.nixpkgs.url = "github:NixOS/nixpkgs";
inputs.poetry.url = "github:nix-community/poetry2nix";
outputs = inputs@{ self, nixpkgs, flake-utils, poetry }:
let
overlay = final: prev: ({
# FIXME: Change to some more verbose name
myPythonApp = final.poetry2nix.mkPoetryApplication {
projectDir = ./.;
python = prev.python39;
propagatedBuildInputs = [
prev.graphviz
prev.bash
prev.wget
prev.findutils
];
};
} //
# This is kind of ugly, but required as it is not possible to return array in flake
# It merges poetry overlay with this overlay
(poetry.overlay final prev));
in
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; overlays = [ overlay ]; };
in
{
defaultPackage = pkgs.myPythonApp;
}
) // {
# Provide overlay outside of flake-utils so that it will not have
# system prefix.
inherit overlay;
};
}
Running nix build create a binary python package /results/bin/myPythonApp
{
description = "PandocProject";
inputs.haskellNix.url = "github:input-output-hk/haskell.nix";
inputs.nixpkgs.follows = "haskellNix/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.myPythonApp.url = "path:/home/mateusz/so/flakeA"; # FIXME: Change to your url
outputs = { self, nixpkgs, flake-utils, haskellNix, myPythonApp }:
flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
let
overlays = [
myPythonApp.overlay
haskellNix.overlay
(final: prev: {
# This overlay adds our project to pkgs
pandocProject = final.haskell-nix.cabalProject {
cabalProjectFreeze = null;
cabalProject = null;
cabalProjectLocal = null;
# In the `final` attribute there is your python script !
# Not sure how you want to use it
# It is avaible as `final.myPythonApp?`
compiler-nix-name = "ghc8104";
name = "pandocProject";
src = final.fetchFromGitHub {
name = "pandoc";
owner = "jgm";
repo = "pandoc";
rev = "d05460d00d7c9af3b4913f1760ea385a7d855d84";
sha256 = "1a3kwag6j13b42zhzxiwlzabsc6c9jppiwv9j8gbnf2k1yb84kdm";
};
pkg-def-extras = with final.haskell.lib; [ ];
};
})
];
pkgs = import nixpkgs { inherit system overlays; };
flake = pkgs.pandocProject.flake { };
in
flake // {
# Built by `nix build .`
defaultPackage = flake.packages."pandoc:exe:pandoc";
});
}
Building B flake produce a pandoc binary in /results/bin/pandoc
My Problem :
With overlays, i merge A and B into B, ok, but now, i don’t know how i do to build a /results/bin folder or a shell/develop context that contain BOTH the A package (mypythonapp) AND the B package (pandoc)
I have this when i run flake show, i’m not sure overlay are correctly consumed.
git+file:///home/xxx/pandoc2nix
├───defaultPackage
trace: No index state specified for pandocProject, using the latest index state that we know about │ └───x86_64-linux: package 'pandoc-exe-pandoc-2.14.2'
├───devShell
│ └───x86_64-linux: development environment 'nix-shell'
└───overlay: Nixpkgs overlay
I would define the overlays in a let block, then reference them from the let scope. You’re adding the overlays to your flake, then referencing them through self.overlay.
I understand the first part and the principle of recursive and overlay, which compile… BUT i don’t understand how to modify the final part that build package .
defaultPackages is just a QoL feature, I wouldn’t concern yourself too much about it. If you do have two equally important packages, then maybe having neither as the default is the correct choice.
@jonringer Yes, but if i don’t define defaultPackages nix build failed …
error: flake 'git+file:///home/XXX/TRASH/pandoc2nix' does not provide attribute 'packages.x86_64-linux.defaultPackage.x86_64-linux', 'legacyPackages.x86_64-linux.defaultPackage.x86_64-linux' or 'defaultPackage.x86_64-linux'
To define two equally package, like you say, i need to use this for example ?
➜ nix build .#wikiPandoc
warning: Git tree '/home/reyman/TRASH/pandoc2nix' is dirty
error: flake output attribute 'legacyPackages.x86_64-linux.wikiPandoc' is not a derivation
(base)
I’m not sure that HaskellNix.overlay in pandoc.nix is well defined …
Any help is welcome, is there something i don’t do well @jonringer ?
nix-repl> apps.x86_64-linux.myPandoc
trace: WARNING: 8.10.4 is out of date, consider using 8.10.7.
trace: No index state specified for pandocProject, using the latest index state that we know about (2021-11-22T00:00:00Z)!
trace: WARNING: 8.10.4 is out of date, consider using 8.10.7.
error: cannot coerce a set to a string
at /nix/store/xfqi0z497g4qamqjlziaxfvzpc9f06kr-source/default.nix:136:18:
135| type = "app";
136| program = "${drv}${exePath}";
| ^
137| };
nix-repl> apps.x86_64-linux.myWiki
{ program = "/nix/store/4nmziia3qjdrgbrs4fvf7y89cgcxa7in-python3.9-notebook-wiki-0.0.1/bin/notebook-wiki"; type = "app"; }
@reyman did you get any further with this ? RN I’m trying to get simplex-chat into my pkgs somehow (using flakes, simplex-chat relies on haskell.nix as well) and don’t know if worth a start ?