Skip to content

Commit bacf5a6

Browse files
committed
initial commit
0 parents  commit bacf5a6

17 files changed

+7149
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.log
2+
nc4nix
3+
result*

.gitlab-ci.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# vim: set ft=yaml sw=2:
2+
stages:
3+
- build
4+
- run
5+
- test
6+
- push
7+
8+
variables:
9+
COMMIT_LOG: "1"
10+
11+
build:
12+
stage: build
13+
script:
14+
- ./ci/build
15+
artifacts:
16+
paths:
17+
- ./nc4nix
18+
19+
run:
20+
stage: run
21+
only:
22+
- schedules
23+
artifacts:
24+
paths:
25+
- ./*.log
26+
- ./*.json
27+
script:
28+
- ./ci/run
29+
30+
test:
31+
stage: test
32+
interruptible: true
33+
script:
34+
- ./ci/test
35+
36+
push:
37+
stage: push
38+
only:
39+
- schedules
40+
script:
41+
- ./ci/push

21.json

+2,362
Large diffs are not rendered by default.

22.json

+2,262
Large diffs are not rendered by default.

23.json

+2,072
Large diffs are not rendered by default.

README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# nc4nix
2+
3+
So you want to roll out Nextcloud on NixOS but you also want to use Nix to manage your apps instead of the builtin apps system?
4+
You came to the right place.
5+
6+
This default.nix expression contains the code to handle all apps Nextcloud has to offer.
7+
It does that by parsing pre-generated JSON files with all plugins and themes.
8+
The files are pre-generated using the `main.go` script.
9+
10+
Apps are provided for all Nextcloud versions currently in nixpkgs.
11+
12+
## Generating the JSONs
13+
14+
The main.go script (by default) parses **all** plugins and themes for Matomo.
15+
16+
There also is an environment varaible, called `COMMIT_LOG`.
17+
If set to `1`, logs are generated.
18+
This is used by the `ci` script.
19+
20+
---
21+
22+
The `ci` script is run daily by our CI and updates all plugins and themes.
23+
It basically runs the `main.go` script and generates a commit message.

ci/build

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env nix-shell
2+
#!nix-shell -i bash -p go
3+
set -e
4+
go build .

ci/push

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env nix-shell
2+
#!nix-shell -i bash -p git openssh
3+
set -e
4+
set -u
5+
set -o pipefail
6+
7+
# What do we need to commit?
8+
porcelain="$(git status --porcelain)"
9+
declare -a toCommit
10+
for type in plugins themes; do
11+
if echo "${porcelain}" | grep -q "$type.json"; then
12+
toCommit+=("$type")
13+
fi
14+
done
15+
set +u
16+
if [ "${#toCommit[@]}" = 0 ]; then
17+
echo "Nothing changed"
18+
exit 0
19+
fi
20+
set -u
21+
22+
# Format commit message
23+
firstLine=
24+
details=
25+
for category in "${toCommit[@]}"; do
26+
# First line
27+
if [ "${firstLine}" = '' ]; then
28+
firstLine="${firstLine}${category^}: "
29+
else
30+
firstLine="${firstLine}; ${category^}: "
31+
fi
32+
added="$(grep -c ^ADD "${category}.log" || true)"
33+
if [ "${added}" != 0 ]; then
34+
firstLine="${firstLine}A:${added} "
35+
fi
36+
updated="$(grep -c ^UPD "${category}.log" || true)"
37+
if [ "${updated}" != 0 ]; then
38+
firstLine="${firstLine}U:${updated} "
39+
fi
40+
firstLine="$(echo "${firstLine}" | xargs)"
41+
# Details
42+
details="${details}"$'\n'$'\n'"${category^}:"
43+
details="${details}"$'\n'"$(sort -u < "${category}.log")"
44+
done
45+
46+
# set up ssh
47+
eval $(ssh-agent -s)
48+
echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
49+
# set up git
50+
git config user.name "GitLab CI"
51+
git config user.email "[email protected]"
52+
53+
# Commit and push
54+
git add *.json
55+
(
56+
echo -n "$firstLine"
57+
echo "$details"
58+
) | git commit -F -
59+
git push git@"$GITLAB_HOST":helsinki-systems/matomo4nix HEAD:master

ci/run

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
set -euxo pipefail
3+
4+
export NEXTCLOUD_VERSIONS=$(nix-instantiate --eval -E 'import ./nc-versions.nix {}' -A e)
5+
./nc4nix

ci/test

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
# Check if some relevant plugins still build, before committing
4+
nix build -L --no-link --option builders "" -f test.nix

default.nix

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{ fetchurl, libarchive, lib, stdenvNoCC, callPackage, overrides ? (self: super: {}) }:
2+
let apps = (self:
3+
let
4+
appJson = version: builtins.fromJSON (builtins.readFile (./. + "/${version}.json"));
5+
versions = (callPackage ./nc-versions.nix {}).n;
6+
apps = builtins.listToAttrs (map (v: let
7+
majorVer = lib.versions.major v;
8+
in {
9+
name = majorVer;
10+
value = builtins.mapAttrs mkApp (appJson majorVer);
11+
}) versions);
12+
13+
mkApp = pname: value: stdenvNoCC.mkDerivation {
14+
inherit pname;
15+
inherit (value) version;
16+
src = fetchurl {
17+
inherit (value) url sha256;
18+
name = "${pname}-${value.version}.zip";
19+
};
20+
buildInputs = [ libarchive ];
21+
dontUnpack = true;
22+
installPhase = ''
23+
mkdir -p $out/apps/${pname}
24+
bsdtar xf "$src" -C $out/apps/${pname}/
25+
'';
26+
};
27+
in
28+
apps
29+
);
30+
in lib.fix' (lib.extends overrides apps)

go.mod

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module git.helsinki.tools/helsinki-systems/nc4nix
2+
3+
go 1.16
4+
5+
require github.com/hashicorp/go-version v1.4.0 // indirect

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI=
2+
github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
3+
github.com/hashicorp/go-version v1.4.0 h1:aAQzgqIrRKRa7w75CKpbBxYsmUoPjzVm1W59ca1L0J4=
4+
github.com/hashicorp/go-version v1.4.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=

0 commit comments

Comments
 (0)