Skip to content

Commit 054d912

Browse files
committed
nix shell w/ npins
Signed-off-by: phanirithvij <[email protected]>
1 parent a6b5c92 commit 054d912

File tree

3 files changed

+120
-0
lines changed

3 files changed

+120
-0
lines changed

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-24.11pre683804.a1d92660c6b3/nixexprs.tar.xz",
7+
"hash": "0lzd1g9x7ihscdajc2g9f0jyykymw6r1lq2ir5g0shjzjf0jc5la"
8+
}
9+
},
10+
"version": 3
11+
}

shell.nix

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
let
2+
sources = import ./npins;
3+
pkgs = import sources.nixpkgs {
4+
config.android_sdk.accept_license = true;
5+
};
6+
jdk = pkgs.jdk17_headless;
7+
androidSdk' =
8+
(pkgs.androidenv.composeAndroidPackages {
9+
platformVersions = [ "33" ];
10+
includeEmulator = false;
11+
includeSystemImages = false;
12+
includeNDK = false;
13+
}).androidsdk;
14+
in
15+
(pkgs.buildFHSUserEnv {
16+
name = "android-sdk";
17+
targetPkgs =
18+
pkgs:
19+
(with pkgs; [
20+
androidSdk'
21+
glibc
22+
nixfmt-rfc-style
23+
]);
24+
runScript = pkgs.writeScript "init.sh" ''
25+
export JAVA_HOME=${jdk}
26+
export PATH="${jdk}/bin:$PATH"
27+
exec bash
28+
'';
29+
}).env

0 commit comments

Comments
 (0)