Skip to content

Commit f0e9532

Browse files
committed
Update to niv
1 parent 1834e8d commit f0e9532

File tree

14 files changed

+98
-186
lines changed

14 files changed

+98
-186
lines changed

bin/Snack.hs

+1-4
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,7 @@ nixBuild snackCfg extraNixArgs nixExpr =
358358
[i|
359359
{ pkgs = import
360360
(
361-
builtins.fetchTarball
362-
{ url = "https://github.com/${spec.owner}/${spec.repo}/archive/${spec.rev}.tar.gz";
363-
sha256 = spec.sha256;
364-
}
361+
builtins.fetchTarball { inherit (spec) url sha256; }
365362
) {} ;
366363
}
367364
|]

bin/package.nix

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ let
22
pkgs = import ../nix {};
33
specJson = pkgs.writeTextFile
44
{ name = "spec-json";
5-
text =
6-
let
7-
versions = builtins.fromJSON (builtins.readFile ../nix/versions.json);
8-
in builtins.toJSON versions.nixpkgs;
5+
text = builtins.toJSON { inherit (pkgs.sources.nixpkgs) sha256 url; } ;
96
destination = "/spec.json";
107
};
118
lib64 = pkgs.runCommand "lib64" {}

default.nix

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
let pkgs = import ./nix {}; in
1+
with { pkgs = import ./nix {}; };
22
{
3-
inherit (pkgs)
3+
inherit (pkgs.packages)
44
snack-lib
55
snack-exe
66
;

nix/default.nix

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
with { fetch = import ./fetch.nix; };
2-
{ nixpkgs ? fetch.nixpkgs }:
3-
import nixpkgs {
4-
config = { };
5-
overlays = [
6-
(import ./overlay.nix)
7-
];
8-
}
1+
{ sources ? import ./sources.nix }:
2+
with
3+
{ overlay = _: pkgs:
4+
{ inherit (import sources.niv {}) niv;
5+
packages = pkgs.callPackages ./packages.nix {};
6+
sources = sources;
7+
};
8+
};
9+
import sources.nixpkgs
10+
{ overlays = [ overlay ] ; config = {}; }

nix/fetch.nix

-26
This file was deleted.

nix/overlay.nix

-4
This file was deleted.

nix/packages.nix

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{ callPackage }:
2+
rec
3+
{
4+
snack-lib = callPackage ../snack-lib/default.nix { };
5+
snack-exe = snack-lib.executable ../bin/package.nix;
6+
}

nix/sources.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"nixpkgs": {
3+
"url": "https://github.com/NixOS/nixpkgs-channels/archive/3276e04a39ed6ecf8fc3d2d73fda80781449f92e.tar.gz",
4+
"owner": "NixOS",
5+
"branch": "nixos-18.09",
6+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz",
7+
"repo": "nixpkgs-channels",
8+
"sha256": "1kimplgz5n7l22z5fc6aqdbfx22pbld13jzyg87p5cv3gj86lij3",
9+
"description": "Nixpkgs/NixOS branches that track the Nixpkgs/NixOS channels",
10+
"rev": "3276e04a39ed6ecf8fc3d2d73fda80781449f92e"
11+
},
12+
"niv": {
13+
"homepage": "https://github.com/nmattia/niv",
14+
"url": "https://github.com/nmattia/niv/archive/cdfa7b9a27a92b0892f1286de529dc25b653f5f0.tar.gz",
15+
"owner": "nmattia",
16+
"branch": "master",
17+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz",
18+
"repo": "niv",
19+
"sha256": "1qsm2f6znkxqw2nvxhfyrx43c0h1ppnvxnbbd9738vbh8dw105cx",
20+
"description": "Easy dependency management for Nix projects",
21+
"rev": "cdfa7b9a27a92b0892f1286de529dc25b653f5f0"
22+
}
23+
}

nix/sources.nix

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# A record, from name to path, of the third-party packages
2+
with
3+
{
4+
sources = builtins.fromJSON (builtins.readFile ./sources.json);
5+
6+
# fetchTarball version that is compatible between all the sources of Nix
7+
fetchTarball =
8+
{ url, sha256 }:
9+
if builtins.lessThan builtins.nixVersion "1.12" then
10+
builtins.fetchTarball { inherit url; }
11+
else
12+
builtins.fetchTarball { inherit url sha256; };
13+
mapAttrs = builtins.mapAttrs or
14+
(f: set: with builtins;
15+
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)));
16+
};
17+
18+
# NOTE: spec must _not_ have an "outPath" attribute
19+
mapAttrs (_: spec:
20+
if builtins.hasAttr "outPath" spec
21+
then abort
22+
"The values in sources.json should not have an 'outPath' attribute"
23+
else
24+
if builtins.hasAttr "url" spec && builtins.hasAttr "sha256" spec
25+
then
26+
spec //
27+
{ outPath = fetchTarball { inherit (spec) url sha256; } ; }
28+
else spec
29+
) sources

nix/versions.json

-9
This file was deleted.

script/test

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#!nix-shell -p jq
66
#!nix-shell -p nix
77
#!nix-shell -p shfmt
8-
#!nix-shell -p snack-exe
8+
#!nix-shell -p packages.snack-exe
99
#!nix-shell -p glibcLocales
1010
#!nix-shell --pure
1111
# vim: ft=sh sw=2 et

script/update

+3-99
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,6 @@
11
#!/usr/bin/env nix-shell
2-
#!nix-shell -i bash -p bash nix curl jq --pure
2+
#!nix-shell -I nixpkgs=./nix
3+
#!nix-shell -i bash -p bash nix niv --pure
34
# vim: filetype=sh
4-
set -euo pipefail
55

6-
banner() {
7-
echo
8-
echo "--- $*"
9-
echo
10-
}
11-
12-
13-
update() {
14-
local versions="$1"
15-
local package="$2"
16-
echo "Versions file: $versions"
17-
echo "Package to update: $package"
18-
local owner=$(cat $versions | jq -r ".[\"$package\"].owner")
19-
local repo=$(cat $versions | jq -r ".[\"$package\"].repo")
20-
local branch=$(cat $versions | jq -r ".[\"$package\"].branch")
21-
local rev=$(cat $versions | jq -r ".[\"$package\"].rev")
22-
local sha256=$(cat $versions | jq -r ".[\"$package\"].sha256")
23-
24-
echo "Owner: $owner"
25-
echo "Repository: $repo"
26-
echo "Branch: $branch"
27-
28-
29-
case "$PREFETCH_ONLY" in
30-
TRUE)
31-
local new_rev=$rev
32-
echo "Using existing revision"
33-
;;
34-
FALSE)
35-
local new_rev=$(curl -sfL \
36-
https://api.github.com/repos/$owner/$repo/git/refs/heads/$branch \
37-
| jq -r .object.sha)
38-
echo "Fetching latest revision on branch $branch"
39-
;;
40-
esac
41-
echo "The following revision will be used:"
42-
echo " $new_rev"
43-
44-
local url=https://github.com/$owner/$repo/archive/$new_rev.tar.gz
45-
local new_sha256=$(nix-prefetch-url --unpack "$url")
46-
47-
echo "The following url will be used:"
48-
echo " $url"
49-
50-
echo "The following sha256 will be used:"
51-
echo " $new_sha256"
52-
53-
res=$(cat $versions \
54-
| jq -rM ".[\"$package\"].rev = \"$new_rev\"" \
55-
| jq -rM ".[\"$package\"].sha256 = \"$new_sha256\""
56-
)
57-
58-
echo "New versions file:"
59-
echo "$res"
60-
61-
echo "$res" > $versions
62-
}
63-
64-
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. >/dev/null && pwd )"
65-
VERSIONS_DEF="$ROOT/nix/versions.json"
66-
PACKAGES_DEF="$(cat $VERSIONS_DEF | jq -r 'keys | .[]')"
67-
68-
VERSIONS="$VERSIONS_DEF"
69-
echo "Using versions file ${VERSIONS}"
70-
71-
PREFETCH_ONLY="FALSE"
72-
PACKAGES=""
73-
74-
75-
while [[ $# -gt 0 ]]
76-
do
77-
key="$1"
78-
79-
case $key in
80-
--prefetch)
81-
PREFETCH_ONLY="TRUE"
82-
shift
83-
;;
84-
*)
85-
PACKAGES="$key $PACKAGES"
86-
shift # past value
87-
;;
88-
esac
89-
done
90-
91-
if [ -z "$PACKAGES" ];
92-
then
93-
PACKAGES="$PACKAGES_DEF"
94-
fi
95-
96-
echo "Using packages:"
97-
for p in $PACKAGES; do echo " - $p"; done
98-
99-
for p in $PACKAGES; do
100-
banner "$p"
101-
update "$VERSIONS" "$p"
102-
done
6+
niv update

shell.nix

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
{ pkgs ? import ./nix {} }:
2-
with pkgs;
3-
mkShell {
4-
buildInputs = [ snack-exe nix ];
1+
with { pkgs = import ./nix {}; };
2+
pkgs.mkShell {
3+
buildInputs = [ pkgs.packages.snack-exe pkgs.nix ];
54
}

tests/extended-config/nix/default.nix

+19-25
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
1-
let
2-
spec =
3-
let versions = builtins.fromJSON (builtins.readFile ../../../nix/versions.json);
4-
in versions.nixpkgs;
5-
nixpkgs =
6-
(builtins.fetchTarball
7-
{ url = "https://github.com/${spec.owner}/${spec.repo}/archive/${spec.rev}.tar.gz";
8-
sha256 = spec.sha256;
9-
});
10-
in
11-
import nixpkgs
12-
{ overlays =
13-
[
14-
(self: super:
15-
{ haskellPackages = super.haskellPackages.extend
16-
(super.haskell.lib.packageSourceOverrides
17-
{ something-that-doesnt-exist =
18-
self.lib.cleanSource ./extra-hs;
19-
}
20-
);
21-
}
22-
)
23-
];
24-
}
25-
1+
with
2+
rec {
3+
sources = import ../../../nix/sources.nix;
4+
nixpkgs = sources.nixpkgs;
5+
};
6+
import nixpkgs
7+
{ overlays =
8+
[
9+
(self: super:
10+
{ haskellPackages = super.haskellPackages.extend
11+
(super.haskell.lib.packageSourceOverrides
12+
{ something-that-doesnt-exist =
13+
self.lib.cleanSource ./extra-hs;
14+
}
15+
);
16+
}
17+
)
18+
];
19+
}

0 commit comments

Comments
 (0)