-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
107 lines (101 loc) · 3.05 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
{
description = "Application packaged using poetry2nix";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05-small";
poetry2nix = {
url = "github:nix-community/poetry2nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
};
outputs =
{
self,
nixpkgs,
flake-utils,
poetry2nix,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pypkgs-build-requirements = {
conllu = [ "setuptools" ];
janome = [ "setuptools" ];
pptree = [ "setuptools" ];
confection = [ "setuptools" ];
ftfy = [ "hatchling" ];
segtok = [ "setuptools" ];
wikipedia-api = [ "setuptools" ];
presidio-vault = [ "poetry" ];
safetensors = [ "maturin" ];
};
p2n-overrides = pkgs.poetry2nix.defaultPoetryOverrides.extend (
final: prev:
builtins.mapAttrs (
package: build-requirements:
(builtins.getAttr package prev).overridePythonAttrs (old: {
buildInputs =
(old.buildInputs or [ ])
++ (builtins.map (
pkg: if builtins.isString pkg then builtins.getAttr pkg prev else pkg
) build-requirements);
})
) pypkgs-build-requirements
);
myapp =
{ poetry2nix, lib }:
poetry2nix.mkPoetryApplication {
projectDir = self;
overrides = p2n-overrides;
preferWheels = true;
};
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
overlays = [
poetry2nix.overlays.default
(final: _: { myapp = final.callPackage myapp { }; })
];
};
# build docker using nix to have smaller images. Inspiration from
# https://lucabrunox.github.io/2016/04/cheap-docker-images-with-nix_15.html
buildImage = pkgs.dockerTools.buildLayeredImage {
name = "pii";
tag = "latest";
created = "now";
config.Entrypoint = [ "${pkgs.myapp}/bin/cli" ];
};
in
{
packages.default = pkgs.myapp;
packages.dockerImage = buildImage;
apps.default = {
type = "app";
program = "${pkgs.myapp}/bin/cli";
};
devShells = {
# Shell for app dependencies.
#
# nix develop
#
# Use this shell for developing your app.
default = pkgs.mkShell {
inputsFrom = [ pkgs.myapp ];
packages = [
pkgs.docker
pkgs.jq
pkgs.vault
];
};
# Shell for poetry.
#
# nix develop .#poetry
#
# Use this shell for changes to pyproject.toml and poetry.lock.
poetry = pkgs.mkShell { packages = [ pkgs.poetry ]; };
};
legacyPackages = pkgs;
}
);
}