I was trying to move Python/Poetry project to flake.nix without any success.
Iteratively, I come up with the following flake.nix, but now stuck with overrides to have setuptools
available for some packages with this guide.
flake.nix
{
description = "";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
poetry2nix.url = "github:nix-community/poetry2nix";
};
outputs = { self, nixpkgs, poetry2nix }:
let
name = "usefultool";
src = ./.;
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
pkgs = forAllSystems (system: nixpkgs.legacyPackages.${system});
overrides = poetry2nix.defaultPoetryOverrides.extend
(self: super: {
usefullogging = super.usefullogging.overridePythonAttrs
(
old: {
buildInputs = (old.buildInputs or [ ]) ++ [ super.setuptools ];
}
);
});
inherit (pkgs) stdenv;
in
{
packages = forAllSystems (system:
let
inherit (poetry2nix.lib.mkPoetry2Nix { pkgs = pkgs.${system}; }) mkPoetryApplication;
in
{
default = mkPoetryApplication { projectDir = self; inherit overrides; };
});
devShells = forAllSystems (system:
let
inherit (poetry2nix.lib.mkPoetry2Nix { pkgs = pkgs.${system}; }) mkPoetryEnv;
in
{
default = pkgs.${system}.mkShellNoCC {
packages = with pkgs.${system}; [
(mkPoetryEnv { projectDir = self; inherit overrides; })
poetry
];
};
});
};
}
The error I am getting with this flake.nix is cryptic to me and I have no idea how to fix it (or what it even means, outside of something inside mkShellNoCC
; I tried specifying nativeBuildInputs
in overrides
without any success):
error
error:
… while calling the 'derivationStrict' builtin
at <nix/derivation-internal.nix>:9:12:
8|
9| strict = derivationStrict drvAttrs;
| ^
10|
… while evaluating derivation 'nix-shell'
whose name attribute is located at /nix/store/zwzh9ag7jab7gkzxjhbgmns0hbzqfkfn-source/pkgs/stdenv/generic/make-derivation.nix:348:7
… while evaluating attribute 'nativeBuildInputs' of derivation 'nix-shell'
at /nix/store/zwzh9ag7jab7gkzxjhbgmns0hbzqfkfn-source/pkgs/stdenv/generic/make-derivation.nix:392:7:
391| depsBuildBuild = elemAt (elemAt dependencies 0) 0;
392| nativeBuildInputs = elemAt (elemAt dependencies 0) 1;
| ^
393| depsBuildTarget = elemAt (elemAt dependencies 0) 2;
(stack trace truncated; use '--show-trace' to show the full trace)
error: attribute 'defaultPoetryOverrides' missing
at /nix/store/6c7bzbbds6idnchgql1ndzz6aw5flbl2-source/flake.nix:16:19:
15| pkgs = forAllSystems (system: nixpkgs.legacyPackages.${system});
16| overrides = poetry2nix.defaultPoetryOverrides.extend
| ^
17| (self: super: {