summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaus T. Aehlig <aehlig@linta.de>2024-06-25 17:35:19 +0200
committerKlaus T. Aehlig <aehlig@linta.de>2024-06-25 17:52:47 +0200
commit628cb0ab06332086a7ea022bcebfb69d95c38068 (patch)
tree41a06a68e7a1e89f084e899e0a01b7d846958c7f
parentafcdb1184799526f20954e475af990254d772cd4 (diff)
downloadhello-nix-628cb0ab06332086a7ea022bcebfb69d95c38068.tar.gz
Import rules instead of hard-coding
-rw-r--r--README.md11
-rwxr-xr-xetc/generate-repos.sh11
-rw-r--r--etc/repos.json18
-rw-r--r--etc/repos.template.json21
-rw-r--r--nix-import-tools/default.nix2
-rw-r--r--nix-import-tools/import-tools.nix41
-rw-r--r--shell.nix2
-rwxr-xr-xupdate-just-dependencies.sh1
8 files changed, 91 insertions, 16 deletions
diff --git a/README.md b/README.md
index cfb1773..0e6d1f9 100644
--- a/README.md
+++ b/README.md
@@ -112,13 +112,10 @@ There are two files pinning dependencies
be updated using [update-nix-dependencies.sh](./update-nix-dependencies.sh)
which simply calls `niv update` in our `nix-shell`.
- The dependencies on other other justbuild projects are
- pinned in [etc/repos.json](etc/repos.json). As, at the
- moment, there is only one external justbuild dependency,
- the [rules-cc](https://github.com/just-buildsystem/rules-cc),
- this is updated by hand. For larger
- projects [just-import-git](https://github.com/just-buildsystem/justbuild/blob/master/share/man/just-import-git.1.md)
- would be used to generate this file out of a description of the
- local repositories and the dependencies to import.
+ pinned in [etc/repos.json](etc/repos.json). They can be updated using
+ [update-just-dependencies.sh](./update-just-dependencies.sh) which
+ calls [etc/generate-repos.sh](./etc/generate-repos.sh) in our `nix-shell`,
+ which also brings in tools required for this step.
### Logical repositories
diff --git a/etc/generate-repos.sh b/etc/generate-repos.sh
new file mode 100755
index 0000000..f7b4cf8
--- /dev/null
+++ b/etc/generate-repos.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+
+readonly ROOT=$(readlink -f $(dirname $0)/..)
+
+: ${RULES_CC_REPO:=https://github.com/just-buildsystem/rules-cc}
+: ${RULES_CC_BRANCH:=master}
+
+just-import-git -C ${ROOT}/etc/repos.template.json \
+ --as rules -b ${RULES_CC_BRANCH} ${RULES_CC_REPO} rules \
+ | hdump > ${ROOT}/etc/repos.json
diff --git a/etc/repos.json b/etc/repos.json
index d1537db..5ab3477 100644
--- a/etc/repos.json
+++ b/etc/repos.json
@@ -8,15 +8,6 @@
, "bindings": {"rules": "rules/nix-test", "src": ""}
}
, "defaults": {"repository": {"type": "file", "path": "etc/defaults"}}
- , "rules":
- { "repository":
- { "type": "git"
- , "branch": "master"
- , "commit": "0d436f26134d3fcaa695e4e6e87249d7fa381e44"
- , "repository": "https://github.com/just-buildsystem/rules-cc.git"
- , "subdir": "rules"
- }
- }
, "rules/nix":
{"repository": "rules", "target_root": "defaults", "rule_root": "rules"}
, "rules/nix-test":
@@ -26,5 +17,14 @@
, "target_file_name": "test.TARGETS"
, "bindings": {"base": "rules/nix"}
}
+ , "rules":
+ { "repository":
+ { "type": "git"
+ , "repository": "https://github.com/just-buildsystem/rules-cc"
+ , "branch": "master"
+ , "commit": "0e9d13a761c878a647fde5a543946a02bf2c693d"
+ , "subdir": "rules"
+ }
+ }
}
}
diff --git a/etc/repos.template.json b/etc/repos.template.json
new file mode 100644
index 0000000..bb4d04c
--- /dev/null
+++ b/etc/repos.template.json
@@ -0,0 +1,21 @@
+{ "repositories":
+ { "":
+ { "repository": {"type": "file", "path": "src"}
+ , "bindings": {"rules": "rules/nix"}
+ }
+ , "test":
+ { "repository": {"type": "file", "path": "test"}
+ , "bindings": {"rules": "rules/nix-test", "src": ""}
+ }
+ , "defaults": {"repository": {"type": "file", "path": "etc/defaults"}}
+ , "rules/nix":
+ {"repository": "rules", "target_root": "defaults", "rule_root": "rules"}
+ , "rules/nix-test":
+ { "repository": "rules"
+ , "target_root": "defaults"
+ , "rule_root": "rules"
+ , "target_file_name": "test.TARGETS"
+ , "bindings": {"base": "rules/nix"}
+ }
+ }
+}
diff --git a/nix-import-tools/default.nix b/nix-import-tools/default.nix
new file mode 100644
index 0000000..e8f8026
--- /dev/null
+++ b/nix-import-tools/default.nix
@@ -0,0 +1,2 @@
+{ nixpkgs ? import <nixpkgs> {} }:
+nixpkgs.callPackage ./import-tools.nix {}
diff --git a/nix-import-tools/import-tools.nix b/nix-import-tools/import-tools.nix
new file mode 100644
index 0000000..cfb7a91
--- /dev/null
+++ b/nix-import-tools/import-tools.nix
@@ -0,0 +1,41 @@
+{ stdenv
+, fetchFromGitHub
+, python3
+}:
+
+stdenv.mkDerivation rec {
+ name = "just-import-tools";
+ version = "2024-06-25";
+
+ buildInputs = [ (python3.withPackages (ps: [])) ];
+
+ srcjust = fetchFromGitHub {
+ owner = "just-buildsystem";
+ repo = "justbuild";
+ rev = "v1.3.1";
+ sha256 = "sha256-kv7HpDEYZml5uk06s8Cxt5rEpxaJBz9s+or6Od1q4Io=";
+ };
+
+ srcrustrules = fetchFromGitHub {
+ owner = "just-buildsystem";
+ repo = "rules-rust";
+ rev = "bf3e05a614f1de5a9a8a0f8e40f1dd9e1f6609da";
+ sha256 = "sha256-8y10ZmZpeTGtbkIeneaVISyMbVKfIi3gHqyvztnKn0M=";
+ };
+
+
+ unpackPhase = ''
+ cp $srcjust/bin/just-import-git.py .
+ cp $srcrustrules/bin/hdump.py .
+ '';
+
+ dontBuild = true;
+
+ installPhase = ''
+ mkdir -p $out/bin
+ cp just-import-git.py $out/bin/just-import-git
+ cp hdump.py $out/bin/hdump
+ chmod 555 $out/bin/just-import-git $out/bin/hdump
+ '';
+
+}
diff --git a/shell.nix b/shell.nix
index b89488b..2a1b356 100644
--- a/shell.nix
+++ b/shell.nix
@@ -7,6 +7,7 @@ let
pkgs = import nixpkgs {};
nix-dependencies = import ./nix-dependencies { nixpkgs = pkgs; } ;
+ update-deps = import ./nix-import-tools { nixpkgs = pkgs; } ;
in pkgs.mkShell rec {
@@ -14,6 +15,7 @@ in pkgs.mkShell rec {
buildInputs = with pkgs; [
niv
+ update-deps
];
shellHook = ''
diff --git a/update-just-dependencies.sh b/update-just-dependencies.sh
new file mode 100755
index 0000000..e9469d3
--- /dev/null
+++ b/update-just-dependencies.sh
@@ -0,0 +1 @@
+nix-shell --run "./etc/generate-repos.sh"