-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathflake.nix
More file actions
131 lines (113 loc) · 4.29 KB
/
flake.nix
File metadata and controls
131 lines (113 loc) · 4.29 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
{
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane.url = "github:ipetkov/crane";
};
outputs = inputs @ { self, ... }:
(inputs.flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ inputs.rust-overlay.overlays.default ];
};
rust-config = {
extensions = [ "rust-src" ];
targets = [ "wasm32-unknown-unknown" ];
};
rust = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override rust-config;
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rust;
python = pkgs.python312;
shellDeps = [
rust
] ++ (with pkgs; [
just
nixpkgs-fmt
# Python bindings development
python
maturin
(python.withPackages (ps: with ps; [ pytest pytest-asyncio ]))
]);
cupcake-cli =
let
pname = (craneLib.crateNameFromCargoToml { cargoToml = ./cupcake-cli/Cargo.toml; }).pname;
version = (craneLib.crateNameFromCargoToml { cargoToml = ./Cargo.toml; }).version;
craneArgs = rec {
inherit
pname
version
;
src = craneLib.cleanCargoSource (craneLib.path ./.);
cargoExtraArgs = "-p ${pname}";
doCheck = false;
};
cargoArtifacts = craneLib.buildDepsOnly craneArgs;
in
craneLib.buildPackage (craneArgs // {
inherit cargoArtifacts;
src = pkgs.lib.cleanSourceWith {
src = ./.;
filter =
let
regoFilter = path: _type: builtins.match ".*rego$" path != null;
ymlFilter = path: _type: builtins.match ".*yml$" path != null;
in
path: _type: (regoFilter path _type) || (ymlFilter path _type) || (craneLib.filterCargoSources path _type);
};
});
in
rec {
devShells = {
default = pkgs.mkShell ({
buildInputs = shellDeps;
});
};
packages = {
inherit cupcake-cli;
cupcake-py = pkgs.callPackage ({ lib, maturin, python312, cargo, rustc, rustPlatform }:
python312.pkgs.buildPythonPackage {
pname = "cupcake";
version = cupcake-cli.version;
pyproject = true;
src = pkgs.lib.cleanSourceWith {
src = ./.;
filter =
let
regoFilter = path: _type: builtins.match ".*rego$" path != null;
ymlFilter = path: _type: builtins.match ".*yml$" path != null;
pyFilter = path: _type: builtins.match ".*py$" path != null;
pyiFilter = path: _type: builtins.match ".*pyi$" path != null;
pytypedFilter = path: _type: builtins.match ".*/py\\.typed$" path != null;
mdFilter = path: _type: builtins.match ".*md$" path != null;
in
path: _type:
(regoFilter path _type)
|| (ymlFilter path _type)
|| (pyFilter path _type)
|| (pyiFilter path _type)
|| (pytypedFilter path _type)
|| (mdFilter path _type)
|| (craneLib.filterCargoSources path _type);
};
cargoDeps = rustPlatform.importCargoLock {
lockFile = ./Cargo.lock;
};
nativeBuildInputs = [
cargo rustc
rustPlatform.cargoSetupHook
rustPlatform.maturinBuildHook
];
# The source is the whole workspace; cd into the Python crate
# so maturin finds pyproject.toml + Cargo.toml.
# Cargo resolves the workspace root (../) and vendor dir automatically.
preBuild = "cd cupcake-py";
pythonImportsCheck = [ "cupcake" ];
}
) {};
};
}));
}