Skip to content

Commit d200ba0

Browse files
committed
Add nix development files
When using nix, it allows running `nix-shell` to add the required dependencies to the current environment
1 parent 66ec320 commit d200ba0

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed

default.nix

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
sources ? import ./npins,
3+
pkgs ? import sources.nixpkgs { },
4+
}:
5+
6+
{
7+
devShell = pkgs.mkShell {
8+
name = "flint.dev";
9+
packages = with pkgs; [
10+
# Dependencies
11+
gmp
12+
mpfr
13+
ntl
14+
openblas
15+
16+
# Build tools
17+
autoconf
18+
automake
19+
gnumake
20+
libtool
21+
];
22+
};
23+
}

npins/default.nix

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Generated by npins. Do not modify; will be overwritten regularly
2+
let
3+
data = builtins.fromJSON (builtins.readFile ./sources.json);
4+
version = data.version;
5+
6+
mkSource =
7+
spec:
8+
assert spec ? type;
9+
let
10+
path =
11+
if spec.type == "Git" then
12+
mkGitSource spec
13+
else if spec.type == "GitRelease" then
14+
mkGitSource spec
15+
else if spec.type == "PyPi" then
16+
mkPyPiSource spec
17+
else if spec.type == "Channel" then
18+
mkChannelSource spec
19+
else
20+
builtins.throw "Unknown source type ${spec.type}";
21+
in
22+
spec // { outPath = path; };
23+
24+
mkGitSource =
25+
{
26+
repository,
27+
revision,
28+
url ? null,
29+
hash,
30+
branch ? null,
31+
...
32+
}:
33+
assert repository ? type;
34+
# At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository
35+
# In the latter case, there we will always be an url to the tarball
36+
if url != null then
37+
(builtins.fetchTarball {
38+
inherit url;
39+
sha256 = hash; # FIXME: check nix version & use SRI hashes
40+
})
41+
else
42+
assert repository.type == "Git";
43+
let
44+
urlToName =
45+
url: rev:
46+
let
47+
matched = builtins.match "^.*/([^/]*)(\\.git)?$" repository.url;
48+
49+
short = builtins.substring 0 7 rev;
50+
51+
appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else "";
52+
in
53+
"${if matched == null then "source" else builtins.head matched}${appendShort}";
54+
name = urlToName repository.url revision;
55+
in
56+
builtins.fetchGit {
57+
url = repository.url;
58+
rev = revision;
59+
inherit name;
60+
# hash = hash;
61+
};
62+
63+
mkPyPiSource =
64+
{ url, hash, ... }:
65+
builtins.fetchurl {
66+
inherit url;
67+
sha256 = hash;
68+
};
69+
70+
mkChannelSource =
71+
{ url, hash, ... }:
72+
builtins.fetchTarball {
73+
inherit url;
74+
sha256 = hash;
75+
};
76+
in
77+
if version == 3 then
78+
builtins.mapAttrs (_: mkSource) data.pins
79+
else
80+
throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"

npins/sources.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"pins": {
3+
"nixpkgs": {
4+
"type": "Channel",
5+
"name": "nixpkgs-unstable",
6+
"url": "https://releases.nixos.org/nixpkgs/nixpkgs-25.05pre744509.88a55dffa4d4/nixexprs.tar.xz",
7+
"hash": "031apspqfm8z4yczj8126chfc7mijnmnxzqg0inaz1dwi4pzwlbz"
8+
}
9+
},
10+
"version": 3
11+
}

shell.nix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(import ./. { }).devShell

0 commit comments

Comments
 (0)