-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
107 lines (98 loc) · 3.17 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 = "Flake for ns";
inputs = {
# override this one with the `nixpkgs` that you want to query
nixpkgs.url = "github:nixos/nixpkgs/23.05";
# override this one only for the packages that build the packages
nixpkgs_fixed.url = "github:nixos/nixpkgs/23.05";
};
outputs = { self, nixpkgs, nixpkgs_fixed }:
let
system = "x86_64-linux";
pkgs = import nixpkgs_fixed {
inherit system;
};
pkgs_ns = import nixpkgs {
inherit system;
config.allowBroken = true;
};
in {
packages.${system} = rec {
nixsearch_db = pkgs.stdenv.mkDerivation {
name = "nixsearch_db";
version = nixpkgs.rev;
src = ./src;
buildInputs = [
nixsearch_create_db
#pkgs_json
];
buildPhase = ''
mkdir -p $out
cd $out
${nixsearch_create_db}/bin/nixsearch_create_db "${pkgs_json}"
'';
installPhase = ''
echo pass
'';
};
ns = pkgs.stdenv.mkDerivation rec {
name = "ns";
version = nixpkgs.rev;
src = ./src;
nativeBuildInputs = with pkgs; [
gcc
pkg-config
];
buildInputs = with pkgs; [
sqlite
nixsearch_db
];
buildPhase = ''
mkdir -p $out/bin
g++ -DDB_PATH="${nixsearch_db}/nix-search.db" $(pkg-config --libs --cflags sqlite3) -o $out/bin/ns main.cpp -O3
'';
installPhase = ''
echo pass
'';
};
pkgs_json =
builtins.toFile "pkgs.json" (import ./main.nix { pkgs = pkgs_ns; });
nixsearch_create_db =
pkgs.writers.writePython3Bin "nixsearch_create_db" {
libraries = [ pkgs.python3Packages.sqlite-utils ];
} ''
import json
import sqlite3
import sys
def get_tuple(x):
name = str(x["name"]) if "name" in x else ""
version = str(x["version"]) if "version" in x else ""
desc = x["description"] if "description" in x else ""
long_desc = x["longDescription"] if "longDescription" in x else ""
return (name, version, desc, long_desc)
con = sqlite3.connect("nix-search.db")
cur = con.cursor()
cur.execute("CREATE TABLE packages(name,\
version,\
description,\
longDescription)")
pkgs_json = sys.argv[1]
print(pkgs_json)
with open(pkgs_json, "r") as pkgs:
data = json.loads(pkgs.read())
to_insert = [get_tuple(x) for x in data.values()]
cur.executemany("INSERT INTO packages VALUES(?, ?, ?, ?)", to_insert)
con.commit()
'';
};
devShells.${system} = {
default = pkgs.mkShell {
packages = with pkgs; [
(python3.withPackages (ps: with ps; [ sqlite-utils rich ]))
sqlite
pkg-config
];
};
};
};
}