Skip to content

Commit

Permalink
fix: patch automation
Browse files Browse the repository at this point in the history
  • Loading branch information
willruggiano committed Apr 25, 2024
1 parent 4587911 commit 29cd9da
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cachix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
with:
name: vscode-js-debug
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
- run: cachix pin vscode-js-debug latest "$(nix build .#latest --accept-flake-config --print-out-paths)"
- run: cachix pin vscode-js-debug latest "$(nix build --accept-flake-config --print-out-paths)"
44 changes: 30 additions & 14 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
};

outputs = {
self,
dream2nix,
flake-utils,
nixpkgs,
Expand All @@ -32,23 +33,26 @@

formatter.${system} = pkgs.alejandra;

# TODO: We don't really need a "latest". We could just take the highest
# version after building all of the versioned derivations.
packages.${system} = let
sources = import ./nix/sources.nix {};
patches = import ./patches;
inherit (import ./patches) patches;

versionNewer = a: b: (builtins.compareVersions a b) >= 0;

mkName = lib.replaceStrings ["."] ["-"];
mkPackage = srcVersion: src:
mkPackage = version: src: let
semver = lib.removePrefix "v" version;
patchesToApply = builtins.filter (p: versionNewer semver p.since) patches;
in
dream2nix.lib.evalModules {
packageSets.nixpkgs = pkgs;
modules = [
{
config.deps = let
version =
if srcVersion == "latest"
then src.rev
else srcVersion;
in {
config.deps = {
inherit src version;
patches = patches.${version} or [];
patches = builtins.map (p: p.patch) patchesToApply;
};
}
./default.nix
Expand All @@ -61,11 +65,23 @@
}
];
};

packages =
lib.mapAttrs'
(version: src: lib.nameValuePair (mkName version) (mkPackage version src))
sources;
in
lib.mapAttrs' (
version: src:
lib.nameValuePair (mkName version) (mkPackage version src)
)
sources;
{
default = self.packages.${system}.latest;
latest =
lib.foldl'
(a: b:
if (versionNewer (a.version or "") (b.version or ""))
then a
else b)
{}
(lib.attrValues packages);
}
// packages;
};
}
12 changes: 0 additions & 12 deletions nix/sources.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
{
"latest": {
"branch": "main",
"description": "The VS Code JavaScript debugger",
"homepage": "",
"owner": "microsoft",
"repo": "vscode-js-debug",
"rev": "v1.89.0",
"sha256": "058rpi82yg05xi99r5nkhdsa5ivv4m324wkh0rql05arlfil40hr",
"type": "tarball",
"url": "https://github.com/microsoft/vscode-js-debug/archive/refs/tags/v1.89.0.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/refs/tags/<rev>.tar.gz"
},
"v1.84.0": {
"branch": "main",
"description": "The VS Code JavaScript debugger",
Expand Down
10 changes: 5 additions & 5 deletions patches/default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"v1.87.0" = [
./remove-postinstall-script.patch
];
"v1.88.0" = [
./remove-postinstall-script.patch
patches = [
{
patch = ./remove-postinstall-script.patch;
since = "1.87.0";
}
];
}
7 changes: 3 additions & 4 deletions scripts/update-sources/update-sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import subprocess

with open("nix/sources.json") as sources:
latest = semver.Version.parse(json.load(sources)["latest"]["rev"].removeprefix("v"))
latest = sorted(
[semver.Version.parse(v.removeprefix("v")) for v in json.load(sources)]
)[-1]

versions = []
for line in fileinput.input(encoding="utf-8"):
Expand All @@ -26,6 +28,3 @@
"https://github.com/<owner>/<repo>/archive/refs/tags/<rev>.tar.gz",
]
)

if len(versions) > 0:
subprocess.run(["niv", "update", "latest", "-r", f"v{versions[0]}"])

0 comments on commit 29cd9da

Please sign in to comment.