diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-05-24 14:43:09 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-05-24 14:45:37 +0200 |
commit | dbcba2ea2b7301aaa7e6487c2589b09ef09ba066 (patch) | |
tree | b4cd4b064468840e96757a55adbe9fd57a9d7904 /scripts | |
parent | db4f87d640a090c4b469595737503f4189923c45 (diff) | |
download | Nix-dbcba2ea2b7301aaa7e6487c2589b09ef09ba066.tar.gz Nix-dbcba2ea2b7301aaa7e6487c2589b09ef09ba066.tar.zst Nix-dbcba2ea2b7301aaa7e6487c2589b09ef09ba066.zip |
Reorganize files
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/fetch_version | 173 | ||||
-rwxr-xr-x | scripts/make-env | 7 | ||||
-rw-r--r-- | scripts/nix_env | 17 | ||||
-rwxr-xr-x | scripts/nix_infos | 2 |
4 files changed, 195 insertions, 4 deletions
diff --git a/scripts/fetch_version b/scripts/fetch_version new file mode 100755 index 0000000..a0325f6 --- /dev/null +++ b/scripts/fetch_version | |||
@@ -0,0 +1,173 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | usage() { | ||
4 | echo "$0 file.json" | ||
5 | echo "$0 [-n|--name name] [-b|--branch branch_or_rev] [-f|--file out_file] [-h|--help] (-u|--url) url" | ||
6 | exit | ||
7 | } | ||
8 | |||
9 | branch="master" | ||
10 | while [[ $# -gt 0 ]]; do | ||
11 | a="$1" | ||
12 | shift | ||
13 | case "$a" in | ||
14 | *.json) | ||
15 | file=$a | ||
16 | content=$(cat $a) | ||
17 | name="$(echo "$content" | jq -r ".meta.name")" | ||
18 | url="$(echo "$content" | jq -r ".meta.url")" | ||
19 | branch="$(echo "$content" | jq -r ".meta.branch")" | ||
20 | ;; | ||
21 | -n|--name) | ||
22 | name=$1 | ||
23 | shift | ||
24 | ;; | ||
25 | -u|--url) | ||
26 | url=$1 | ||
27 | shift | ||
28 | ;; | ||
29 | -b|--branch) | ||
30 | branch=$1 | ||
31 | shift | ||
32 | ;; | ||
33 | -f|--file) | ||
34 | file=$1 | ||
35 | shift | ||
36 | ;; | ||
37 | -h|--help) | ||
38 | usage | ||
39 | ;; | ||
40 | esac | ||
41 | done | ||
42 | if [ -z "$url" ]; then | ||
43 | usage | ||
44 | fi | ||
45 | if [ -z "$name" ]; then | ||
46 | name=$(echo "$url" | cut -d"/" -f5) | ||
47 | fi | ||
48 | if [ -z "$file" ]; then | ||
49 | file=$name.json | ||
50 | fi | ||
51 | |||
52 | # function fetch_ledger () { | ||
53 | # pushd $HOME/projets/ledger >/dev/null 2>/dev/null | ||
54 | # git fetch origin | ||
55 | # tag="$(git describe origin/next | sed -e "s/^v//")" | ||
56 | # rev="$(git show-ref -s refs/remotes/origin/next)" | ||
57 | # sha="$(nix-prefetch-url --unpack file://<(git archive --format=tar.gz HEAD) 2>/dev/null)" | ||
58 | # popd >/dev/null 2>/dev/null | ||
59 | # } | ||
60 | |||
61 | # awk_describe='BEGIN { | ||
62 | # FS = "[ /^]+" | ||
63 | # while ("git ls-remote " ARGV[1] "| sort -Vk2" | getline) { | ||
64 | # if (!sha) | ||
65 | # sha = substr($0, 1, 7) | ||
66 | # tag = $3 | ||
67 | # } | ||
68 | # while ("curl -s " ARGV[1] "/releases/tag/" tag | getline) | ||
69 | # if ($3 ~ "commits") | ||
70 | # com = $2 | ||
71 | # printf com ? "%s-%s-g%s\n" : "%s\n", tag, com, sha | ||
72 | # }' | ||
73 | |||
74 | function get_ref () { | ||
75 | case "$1" in | ||
76 | refs/*) | ||
77 | echo "$1" | ||
78 | ;; | ||
79 | *) | ||
80 | echo "refs/heads/$1" | ||
81 | ;; | ||
82 | esac | ||
83 | } | ||
84 | |||
85 | function get_name () { | ||
86 | branch="$1" | ||
87 | rev="$2" | ||
88 | minirev=${rev:0:7} | ||
89 | |||
90 | case "$branch" in | ||
91 | refs/tags/*) | ||
92 | b="${branch#refs/tags/}" | ||
93 | echo "${b//\//-}" | ||
94 | ;; | ||
95 | refs/heads/*) | ||
96 | b=${branch#refs/heads/} | ||
97 | echo "$minirev-${b//\//-}" | ||
98 | ;; | ||
99 | refs/*) | ||
100 | b=${branch#refs/} | ||
101 | echo "$minirev-${b//\//-}" | ||
102 | ;; | ||
103 | *) | ||
104 | echo "$minirev-${branch//\//-}" | ||
105 | ;; | ||
106 | esac | ||
107 | } | ||
108 | |||
109 | function fetch_github () { | ||
110 | rev="$(git ls-remote --refs $url $(get_ref $branch) | head -n1 | cut -f1)" | ||
111 | sha="$(nix-prefetch-url --unpack $url/archive/$rev.tar.gz)" | ||
112 | # Différent du git-describe et github-spécifique | ||
113 | #tag=$(echo "$awk_describe" | awk -f - $url | sed -e "s/^v//") | ||
114 | tag=$(get_name $branch $rev) | ||
115 | } | ||
116 | |||
117 | function fetch_other () { | ||
118 | rev="$(git ls-remote --refs $url $(get_ref $branch) | head -n1 | cut -f1)" | ||
119 | sha="$(nix-prefetch-git --url $url --rev $(get_ref $branch) | jq -r '.sha256')" | ||
120 | tag=$(get_name $branch $rev) | ||
121 | } | ||
122 | |||
123 | case "$url" in | ||
124 | https://*github.com/*) | ||
125 | fetch_github 2>/dev/null | ||
126 | owner=$(echo "$url" | cut -d"/" -f4) | ||
127 | repo=$(echo "$url" | cut -d"/" -f5) | ||
128 | |||
129 | F='{ | ||
130 | "tag": $tag, | ||
131 | "meta": { | ||
132 | "name": $name, | ||
133 | "url": $url, | ||
134 | "branch": $branch | ||
135 | }, | ||
136 | "github": { | ||
137 | "owner": $owner, | ||
138 | "repo": $repo, | ||
139 | "rev": $rev, | ||
140 | "sha256": $sha, | ||
141 | "fetchSubmodules": true | ||
142 | } | ||
143 | }' | ||
144 | ;; | ||
145 | *) | ||
146 | fetch_other 2>/dev/null | ||
147 | F='{ | ||
148 | "tag": $tag, | ||
149 | "meta": { | ||
150 | "name": $name, | ||
151 | "url": $url, | ||
152 | "branch": $branch | ||
153 | }, | ||
154 | "git": { | ||
155 | "url": $url, | ||
156 | "rev": $rev, | ||
157 | "sha256": $sha, | ||
158 | "fetchSubmodules": true | ||
159 | } | ||
160 | }' | ||
161 | ;; | ||
162 | esac | ||
163 | |||
164 | jq -n \ | ||
165 | --arg name "$name" \ | ||
166 | --arg owner "$owner" \ | ||
167 | --arg repo "$repo" \ | ||
168 | --arg tag "$tag" \ | ||
169 | --arg rev "$rev" \ | ||
170 | --arg url "$url" \ | ||
171 | --arg branch "$branch" \ | ||
172 | --arg sha "$sha" \ | ||
173 | "$F" > $file | ||
diff --git a/scripts/make-env b/scripts/make-env index ebb1eed..983a359 100755 --- a/scripts/make-env +++ b/scripts/make-env | |||
@@ -2,10 +2,11 @@ | |||
2 | 2 | ||
3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" |
4 | 4 | ||
5 | source $(dirname $DIR)/nix_path_env | 5 | source $DIR/nix_env |
6 | nix-env -r -i -A myEnvironments.immae-eu -f "<nixpkgs>" "$@" | 6 | nix-env -r -i -A myEnvironments.immae-eu -f "<nixpkgs>" "$@" |
7 | result=$? | ||
7 | 8 | ||
8 | cat >> $(dirname $DIR)/versions_log <<EOF | 9 | cat >> $(dirname $DIR)/versions_log <<EOF |
9 | # Ran $(date) with args "$@" | 10 | Ran $(date) with args "$@" and returned "$result" |
10 | $($DIR/nix_infos | sed -e "s/^/# /") | 11 | $($DIR/nix_infos | sed -e "s/^/ /") |
11 | EOF | 12 | EOF |
diff --git a/scripts/nix_env b/scripts/nix_env new file mode 100644 index 0000000..6326243 --- /dev/null +++ b/scripts/nix_env | |||
@@ -0,0 +1,17 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | if [ -z "$NIXOPS_DEPLOYMENT" ]; then | ||
4 | # This will automatically upgrade to latest version at each build | ||
5 | nixpkgs="https://nixos.org/channels/nixos-19.03/nixexprs.tar.xz" | ||
6 | else | ||
7 | nixpkgs="https://releases.nixos.org/nixos/19.03/nixos-19.03.172530.096e2f137b6/nixexprs.tar.xz" | ||
8 | fi | ||
9 | nixpkgsPrevious="$nixpkgs" | ||
10 | nixpkgsNext="$nixpkgs" | ||
11 | export NIX_PATH="nixpkgs=$nixpkgs:nixpkgsNext=$nixpkgsNext:nixpkgsPrevious=$nixpkgsPrevious" | ||
12 | |||
13 | nixops_custom () { | ||
14 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
15 | d=$(nix-build --no-out-link -E "with import <nixpkgs> { overlays = builtins.attrValues (import $(dirname $DIR)/overlays); }; nixops") | ||
16 | ${d}/bin/nixops "$@" | ||
17 | } | ||
diff --git a/scripts/nix_infos b/scripts/nix_infos index f824305..56e5b19 100755 --- a/scripts/nix_infos +++ b/scripts/nix_infos | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" |
4 | 4 | ||
5 | source $(dirname $DIR)/nix_path_env | 5 | source $DIR/nix_env |
6 | version=$(nix eval --raw nixpkgs.lib.version) | 6 | version=$(nix eval --raw nixpkgs.lib.version) |
7 | mainversion=$(echo $version | cut -d"." -f -2) | 7 | mainversion=$(echo $version | cut -d"." -f -2) |
8 | 8 | ||