I am trying to make a Nix flake which will use poetry2nix for building a poetry project the code is
{
description = "searx : flake";
inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-20.03;
outputs = { self, nixpkgs }: {
defaultPackage.x86_64-linux =
with import nixpkgs { system = "x86_64-linux";
buildInputs = [
nixpkgs.python39
nixpkgs.git
nixpkgs.openssl
nixpkgs.python39Packages.pip
nixpkgs.uwsgi
nixpkgs.python39Packages.virtualenv
nixpkgs.poetry
];
};
pkgs.poetry2nix.mkPoetryApplication {
projectDir = ./.;
src = pkgs.fetchgit {
url = "https://github.com/searx/searx.git";
rev = "ae122ea943f77600fd97556503c483dcd92e1e63";
sha256 = "sIJ+QXwUdsRIpg6ffUS3ItQvrFy0kmtI8whaiR7qEz4=";
};
};
};
However the Nix flake starts pulling python3.7 and breaks with following error
ERROR: Could not find a version that satisfies the requirement importlib-metadata; python_version < "3.8" (from click==8.0.1) (from versions: none)
> ERROR: No matching distribution found for importlib-metadata; python_version < "3.8" (from click==8.0.1)
Equivalent default.nix pulls python 3.9 and builds successfully. I believe if flake could be pinned to python3.9 it will be able to build this. Is this possible?
You can pass another python to mkPoetryApplication.
pkgs.poetry2nix.mkPoetryApplication {
projectDir = ./.;
python = pkgs.python39;
# ... your code ...
}
Related
I defined a custom nix cpython derivation with unmerged patches. If I specify it as a target nix-shell gives me the version I expect.
{ pkgs ? import <nixpkgs> {} }:
(pkgs.python3.overrideAttrs (old: {
src = pkgs.fetchFromGitHub {
owner = "bergkvist";
repo = "cpython";
rev = "01bcf2bef5f4ffffb454da35cb66b186a7a12598";
sha256 = "1713sx5izd745bgr6fdx6d1g7ivaqy6jrf9v5jgml31bd1nmfccy";
};
verions = "3.11.5";
})) })).override {
sourceVersion = {major = "3"; minor = "11" ; patch = "5"; suffix = ""; };
};
$ nix-shell
$ python
Python 3.11.0a0 (default, Aug 4 2021, 00:12:31) [Clang 7.1.0 (tags/RELEASE_710/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
But I don't see a way how to use new cpython for existing packages.
Straight forward overlay doesn't affect anything.
{ pkgs ? import <nixpkgs> {} }:
let myPatchedPython = ... ;
myPkgs = pkgs.extend(self: super: {
python3 = myPatchedPython;
python39 = myPatchedPython;
});
in myPkgs.python39Packages.send2trash
$ nix-shell
$ python3
Python 3.9.5 (default, Jul 18 2021, 14:31:15)
I noticed I can use override but it is only for runtime and it is not working for all packages.
let useMyPy = drv: drv.override {
python = myPatchedPython;
python3 = myPatchedPython;
python38 = myPatchedPython;
python39 = myPatchedPython;
};
pyobjc-core = useMyPy (pkgs.python39Packages.buildPythonPackage rec {
pname = "pyobjc-core";
version = "7.3";
adfasdf = true;
name = "${pname}-${version}";
src = pkgs.python39Packages.fetchPypi {
pname = "pyobjc-core";
inherit version;
sha256 = "0x3msrzvcszlmladdpl64s48l52fwk4xlnnri8daq2mliggsx0ah";
};
propagatedBuildInputs = [
myPatchedPython
pkgs.darwin.libobjc
pkgs.darwin.cctools
pkgs.darwin.apple_sdk.frameworks.Foundation
pkgs.darwin.apple_sdk.frameworks.AppKit
pkgs.darwin.apple_sdk.frameworks.CoreServices
pkgs.darwin.apple_sdk.frameworks.Cocoa
pkgs.python39Packages.setuptools
];
buildInputs = [ pkgs.libffi ];
});
in pyobjc-core
$ nix-shell
$ python3
Python 3.11.0a0 (default, Aug 4 2021, 00:12:31) [Clang 7.1.0 (tags/RELEASE_710/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import import AppKit
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/nix/store/jcc0xf3zwxnzzh497nip7v57k68r4zb9-python3.9-pyobjc-7.3/lib/python3.9/site-packages/AppKit/__init__.py", line 10, in <module>
import Foundation
^^^^^^^^^^^^^^^^^
...
AFAIK, the official way to do this is to define myPatchedPython in an overlay for nixpkgs (in ~/.config/nixpkgs/overlays.nix), and invoke nix-shell like so:
nix-shell -p myPatchedPython
If this does not work, you can also try nix-shell -E '(import <nixpkgs> {}).myPatchedPython' and the like, which give you more of a debugging angle.
The more pedantic way (without overlays) that I have used in the past with success is to directly copy or include your patched Python version in the shell.nix file, e.g.:
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = [
pkgs.python.overrideAttrs { ... }
];
}
I have a single file (dep-terraform.nix) with contents of:
{ sources ? import ./nix/sources.nix
} :
let
niv = import sources.nixpkgs {
overlays = [
(_ : _ : { niv = import sources.niv {}; })
] ;
config = {};
};
pkgs = niv.pkgs;
in
pkgs.terraform.withPlugins(p: [p.google])
The above (a single package/derivation) can successfully be installed with nix-env -if dep-terraform.nix. How can specify additional packages to be installed using the above approach (without having to create a file for each dependency)?
It is possible to install list of packages using nix-env:
$ echo 'with import <nixpkgs>{}; [ htop moreutils ]' > /tmp/tmp.nix
$ nix-env -if /tmp/tmp.nix
installing 'htop-2.2.0'
installing 'moreutils-0.63'
building '/nix/store/dvhlfnmjska9j55jr4m6cch7xwdgf59a-user-environment.drv'...
created 1419 symlinks in user environment
I am using the default nixos 17.09 channel and want to install an unfree package from the unstable channel.
I am using (import <nixos-unstable> {}).vscode to install vscode in this case, but I am getting the error that I must set ...allowUnfree = true;
It seems that the setting only applies to the default channel.
How can I set allowFree = true; also on the unstable channel?
I found a solution (https://github.com/NixOS/nixpkgs/issues/25880#issuecomment-322855573).
It creates an alias for the unstable channel with the same config.
nixpkgs.config =
{
# Allow proprietary packages
allowUnfree = true;
# Create an alias for the unstable channel
packageOverrides = pkgs:
{
unstable = import <nixos-unstable>
{
# pass the nixpkgs config to the unstable alias
# to ensure `allowUnfree = true;` is propagated:
config = config.nixpkgs.config;
};
};
};
Then you can use it like unstable.vscode instead of (import <nixos-unstable> {}).vscode.
As an alternative example:
{ config, pkgs, ... }:
let
unstable = import <unstable> {
config = config.nixpkgs.config;
};
in
{
environment.systemPackages = with pkgs; [
# google-chrome
unstable.google-chrome
];
nixpkgs.config.allowUnfree = true;
}
to experiment with upstream changes i want to alter the src= attribute in pkgs.python27Packages.bepasty-server.
reading through https://nixos.org/nixpkgs/manual/#chap-functions there is no example how to do this for pythonPackages!
so i have tried the stuff below, which i found in some xml-code for the documentation. but it doesn't work ... which is the part where i need your help!
packageOverrides
idea
nixpkgs.config.packageOverrides = super: {
python27Packages.bepasty-server = (pkgs.python27Packages.bepasty-server.overrideAttrs (oldAttrs: {
src = pkgs.fetchgit {
url = "https://github.com/bepasty/bepasty-server";
sha256 = "1ziqshmsf0rjvdhhca55sm0x8jz76fsf2q4rwh4m6lpcf8wr0nps";
rev = "e2516e8cf4f2afb5185337073607eb9e84a61d2d";
};
}));
results in this:
building Nix...
building the system configuration...
error: attribute ‘gunicorn’ missing, at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/nixos/modules/services/misc/bepasty.nix:5:14
(use ‘--show-trace’ to show detailed location information)
reducing the code
nixpkgs.config.packageOverrides = super: {
python27Packages.bepasty-server = pkgs.python27Packages.bepasty-server;
};
results in:
[root#nixdoc:~/nixpkgs]# nixos-rebuild build
building Nix...
building the system configuration...
error: attribute ‘gunicorn’ missing, at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/nixos/modules/services/misc/bepasty.nix:5:14
(use ‘--show-trace’ to show detailed location information)
so it seems this won't work at all, but why?
systemPackages
in contrast, here it seems to be working:
environment.systemPackages = with pkgs; [
(python27Packages.bepasty-server.overrideAttrs (oldAttrs: {
src = pkgs.fetchgit {
url = "https://github.com/bepasty/bepasty-server";
sha256 = "1ziqshmsf0rjvdhhca55sm0x8jz76fsf2q4rwh4m6lpcf8wr0nps";
rev = "e2516e8cf4f2afb5185337073607eb9e84a61d2d";
};
}))
file
# gcc-wrapper
gdb
gnumake
gnutls
psmisc
# tlspool
wireshark-cli
gnutls
however, i don't need bepasty-server binaries in the interactive environment but instead i need to override pkgs so the bepasty service will use it!
thanks to lassulus!
here is what works now:
nixpkgs.config.packageOverrides = super: {
pythonPackages = super.pythonPackages // { bepasty-server = super.python27Packages.bepasty-server.overrideAttrs (oldAttrs: {
src = pkgs.fetchgit {
url = "https://github.com/bepasty/bepasty-server";
sha256 = "9ziqshmsf0rjvdhhca55sm0x8jz76fsf2q4rwh4m6lpcf8wr0nps";
#sha256 = "5ziqshmsf0rjvdhhca55sm0x8jz76fsf2q4rwh4m6lpcf8wr0nps";
#sha256 = "7ziqshmsf0rjvdhhca55sm0x8jz76fsf2q4rwh4m6lpcf8wr0nps";
rev = "e2516e8cf4f2afb5185337073607eb9e84a61d2d";
};
});
};
};
This is my first time creating a luarock and writing .rockpec file. I have a small lua script and some static text files that this script requires to use. How should I pack my luarock so that these static files are available for my script?
For example, here is my myscript.rockspeck file:
package = "myscript"
version = "1.0-1"
source = {
url = "https://github.com/me/myscript/raw/master/myscript-1.0.tar.gz",
tag = "v1.0"
}
description = {
summary = "My script.",
detailed = [[
Some lua script.
]],
homepage = "https://github.com/me/myscript",
license = "MIT"
}
dependencies = {
"lua >= 5.1, < 5.4"
}
build = {
type = "builtin",
modules = {
myfun = "src/myscript.lua"
},
copy_directories = {"my_data"}
}
I am able to do :
luarocks pack myscript-1.0-1.rockspec
sudo luarocks install myscript-1.0-1.src.rock
However, upon importing myfun module I can see that the my_data directory with the required files inside is not accessible by the module as it complains accordingly.
When I do laurocks pack my working directory contains myscript-1.0.tar.gz with the following sctructure:
myscript-1.0/
src/myscript.lua
tiny_data/
data1.txt
data2.txt
How should I correctly include my_data static files?