I packaged a python Application named fws with poetry2nix and flakes. The nix build and nix run commands are successful. You can try it with nix run "github:rivera-bl/flakes?dir=fws".
However I am unable to install it as part of my NixOS system, which is managed with flakes too. The installation doesn’t yield any error, but I can’t find the package after nixos-rebuild switch.
Here are the relevant parts of my nixos flake.
# flake.nix
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
fws = {
url = "github:rivera-bl/flakes?dir=fws"; # THIS IS MY PYTHON APP
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs@{ self, fws, nixpkgs, home-manager, ... }: let
hostnames = builtins.attrNames (builtins.readDir ./hosts);
system = "x86_64-linux";
in {
nixosConfigurations = builtins.listToAttrs (builtins.map (host: {
name = host;
value = inputs.nixpkgs.lib.nixosSystem {
inherit system;
modules = [
{ _module.args = inputs; }
./hosts/${host}/configuration.nix
sops-nix.nixosModules.sops
];
};
}) hostnames);
};
}
This is the command I’m using to search for the package: nix-store --query --references /run/current-system/sw | xargs nix-store --query --requisites | grep fws, which yields nothing.
outputs = inputs@{ self, fws, nixpkgs, home-manager, ... }: let
I’m no expert in the nix language, but with my rudimentary skills I believe that the python flake is already available in configuration.nix, because if I try to install the package with fws.packages.${system} I can see in the error the derivation that poetry2nix builds.
$ sudo nixos-rebuild switch --flake ~/system/# 3s
warning: Git tree '/home/wim/system' is dirty
warning: input 'nix-colors' has an override for a non-existent input 'nixpkgs'
building the system configuration...
warning: Git tree '/home/wim/system' is dirty
warning: input 'nix-colors' has an override for a non-existent input 'nixpkgs'
error: A definition for option `environment.systemPackages."[definition 3-entry 3]"' is not of type `package'. Definition values:
- In `/nix/store/b2431n9jfl2hh5la0c1wvi8da5i1fb1a-source/roles/pkgs.nix':
{
default = <derivation python3.10-fws-0.1.0>;
myapp = <derivation python3.10-fws-0.1.0>;
}
(use '--show-trace' to show detailed location information)
Ok, you’re right I’ve looked it up and using _module.args to pass inputs is actually encouraged.
I think the mistake in your case is possibly that you are using fws as a package in your configuration.nix but it is an evaluated flake.
You could try:
Is there a way to automatically build the package with pkgs.fws? and not pkgs.fws.packages.${pkgs.system}.default? Maybe modifying the flake of the appication? For example, with nix build or nix run I only need to pass the location of the flake.
I’m using the flake template from github:nix-community/poetry2nix to build my python Application.
The nix build and nix run commands know about the packages attribute, that is why
they do not need to be told where to find the packages. At this time I don’t think there is
a way to just pass a flake to nixosSystem so that it automatically knows about the packages.
But if you only need the package outputs of your flake you could just pass that to the module system:
You can shift the default attribute into the flake if you prefer that.
If you are including many packages with flakes this gets unwieldy quickly, so in that case I recommend bundling these packages into a new flake and using that one as an input.
Using nixpkgs.overlays is also quite nice, because you don’t have specify where your package
comes from in the configuration.nix.