From 431dec2c56a77ea03109419700b4a7278896bb3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Niemier?= <~@hauleth.dev> Date: Tue, 9 Sep 2025 11:07:52 +0200 Subject: [PATCH] Add JJ helpers to work with megamerges --- flake.lock | 58 +++++++++++++++++++++++------------------------ flake.nix | 4 +++- modules/fish.nix | 2 +- modules/fonts.nix | 2 +- modules/jj.nix | 50 ++++++++++++++++++++++++++++++++++++---- modules/tools.nix | 1 + 6 files changed, 81 insertions(+), 36 deletions(-) diff --git a/flake.lock b/flake.lock index d2a8f98..1b3d4c4 100644 --- a/flake.lock +++ b/flake.lock @@ -28,11 +28,11 @@ ] }, "locked": { - "lastModified": 1755825449, - "narHash": "sha256-XkiN4NM9Xdy59h69Pc+Vg4PxkSm9EWl6u7k6D5FZ5cM=", + "lastModified": 1758102940, + "narHash": "sha256-wwqf3+A8EiqwWpcAaPN20QXJLlpGPpwtLTrzgnngI2o=", "owner": "lnl7", "repo": "nix-darwin", - "rev": "8df64f819698c1fee0c2969696f54a843b2231e8", + "rev": "ebd0bfc11fc2b5cff37401e9b3703881ad5fabbd", "type": "github" }, "original": { @@ -43,16 +43,16 @@ }, "darwin-stable": { "locked": { - "lastModified": 1751290243, - "narHash": "sha256-kNf+obkpJZWar7HZymXZbW+Rlk3HTEIMlpc6FCNz0Ds=", + "lastModified": 1758235313, + "narHash": "sha256-OGnmMaDFlg/6TcF/MUns9WGGGKXgbZi+kIT2xrWP0zM=", "owner": "nixos", "repo": "nixpkgs", - "rev": "5ab036a8d97cb9476fbe81b09076e6e91d15e1b6", + "rev": "660ccb4ded7a6a715a79fdee58f064e8beecb65a", "type": "github" }, "original": { "owner": "nixos", - "ref": "nixpkgs-24.11-darwin", + "ref": "nixpkgs-25.05-darwin", "repo": "nixpkgs", "type": "github" } @@ -94,11 +94,11 @@ "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1754487366, - "narHash": "sha256-pHYj8gUBapuUzKV/kN/tR3Zvqc7o6gdFB9XKXIp1SQ8=", + "lastModified": 1756770412, + "narHash": "sha256-+uWLQZccFHwqpGqr2Yt5VsW/PbeJVTn9Dk6SHWhNRPw=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "af66ad14b28a127c5c0f3bbb298218fc63528a18", + "rev": "4524271976b625a4a605beefd893f270620fd751", "type": "github" }, "original": { @@ -228,11 +228,11 @@ ] }, "locked": { - "lastModified": 1756579987, - "narHash": "sha256-duCce8zGsaMsrqqOmLOsuaV1PVIw/vXWnKuLKZClsGg=", + "lastModified": 1758250706, + "narHash": "sha256-Jv/V+PNi5RyqCUK2V6YJ0iCqdLPutU69LZas85EBUaU=", "owner": "nix-community", "repo": "home-manager", - "rev": "99a69bdf8a3c6bf038c4121e9c4b6e99706a187a", + "rev": "363007f12930caf8b0ea59c0bf5be109c52ad0ef", "type": "github" }, "original": { @@ -264,11 +264,11 @@ "lix": { "flake": false, "locked": { - "lastModified": 1753306924, - "narHash": "sha256-jLCEW0FvjFhC+c4RHzH+xbkSOxrnpFHnhjOw6sudhx0=", - "rev": "1a4393d0aac31aba21f5737ede1b171e11336d77", + "lastModified": 1757791921, + "narHash": "sha256-83qbJckLOLrAsKO88UI9N4QRatNEc3gUFtLMiAPwK0g=", + "rev": "b7c2f17e9133e8b85d41c58b52f9d4e3254f41da", "type": "tarball", - "url": "https://git.lix.systems/api/v1/repos/lix-project/lix/archive/1a4393d0aac31aba21f5737ede1b171e11336d77.tar.gz?rev=1a4393d0aac31aba21f5737ede1b171e11336d77" + "url": "https://git.lix.systems/api/v1/repos/lix-project/lix/archive/b7c2f17e9133e8b85d41c58b52f9d4e3254f41da.tar.gz?rev=b7c2f17e9133e8b85d41c58b52f9d4e3254f41da" }, "original": { "type": "tarball", @@ -301,11 +301,11 @@ "neorg": { "flake": false, "locked": { - "lastModified": 1751646203, - "narHash": "sha256-uQSrXTngyRSWRyPN7v7uVQOHw+8rLm8+KXxls4nT2K4=", + "lastModified": 1757505607, + "narHash": "sha256-FwxvApfOcnHH1kWYDccaKRGObLhT4zx/FzjrvasefVI=", "owner": "nvim-neorg", "repo": "neorg", - "rev": "790b0444c0c654131a722817dc893332e06c72b9", + "rev": "91db472c7f65a1a8f7fdc461e0fb040f565a95c4", "type": "github" }, "original": { @@ -326,11 +326,11 @@ "norg-meta": "norg-meta" }, "locked": { - "lastModified": 1756585044, - "narHash": "sha256-Pd71Z4muaqfFdbbW7gajF7mJurgPGK5V+dp1gDhB7io=", + "lastModified": 1758277139, + "narHash": "sha256-x6IhcmQI6JpM3G4kRhSA3ZSdB09l5prYPE2hK+Eb3Uw=", "owner": "nvim-neorg", "repo": "nixpkgs-neorg-overlay", - "rev": "9050eda53388acfa780b8e6e316c2ec5758cd492", + "rev": "0bb8d5b94424dacd788a71f3f1da68eafdf175de", "type": "github" }, "original": { @@ -371,11 +371,11 @@ }, "nixpkgs-lib": { "locked": { - "lastModified": 1753579242, - "narHash": "sha256-zvaMGVn14/Zz8hnp4VWT9xVnhc8vuL3TStRqwk22biA=", + "lastModified": 1754788789, + "narHash": "sha256-x2rJ+Ovzq0sCMpgfgGaaqgBSwY+LST+WbZ6TytnT9Rk=", "owner": "nix-community", "repo": "nixpkgs.lib", - "rev": "0f36c44e01a6129be94e3ade315a5883f0228a6e", + "rev": "a73b9c743612e4244d865a2fdee11865283c04e6", "type": "github" }, "original": { @@ -430,11 +430,11 @@ }, "nixpkgs_4": { "locked": { - "lastModified": 1756536218, - "narHash": "sha256-ynQxPVN2FIPheUgTFhv01gYLbaiSOS7NgWJPm9LF9D0=", + "lastModified": 1758213207, + "narHash": "sha256-rqoqF0LEi+6ZT59tr+hTQlxVwrzQsET01U4uUdmqRtM=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "a918bb3594dd243c2f8534b3be01b3cb4ed35fd1", + "rev": "f4b140d5b253f5e2a1ff4e5506edbf8267724bde", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index c9d9eae..58dc37d 100644 --- a/flake.nix +++ b/flake.nix @@ -3,7 +3,7 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - darwin-stable.url = "github:nixos/nixpkgs/nixpkgs-24.11-darwin"; + darwin-stable.url = "github:nixos/nixpkgs/nixpkgs-25.05-darwin"; flake-parts.url = "github:hercules-ci/flake-parts"; home-manager = { @@ -89,6 +89,8 @@ }: { formatter = pkgs.alejandra; + legacyPackages = inputs'.darwin-stable.legacyPackages.callPackage ./pkgs {}; + packages = (pkgs.callPackage ./pkgs {}) // { diff --git a/modules/fish.nix b/modules/fish.nix index bdf1788..60afcff 100644 --- a/modules/fish.nix +++ b/modules/fish.nix @@ -56,7 +56,7 @@ }; loginShellInit = '' - fish_add_path --move --path $HOME/.nix-profile/bin /run/wrappers/bin /etc/profiles/per-user/$USER/bin /nix/var/nix/profiles/default/bin /run/current-system/sw/bin + fish_add_path --move --path /run/wrappers/bin /etc/profiles/per-user/$USER/bin /nix/var/nix/profiles/default/bin /run/current-system/sw/bin fish_add_path $HOME/.local/bin ''; diff --git a/modules/fonts.nix b/modules/fonts.nix index 0e02337..e23338e 100644 --- a/modules/fonts.nix +++ b/modules/fonts.nix @@ -3,7 +3,7 @@ inputs, ... }: let - pkgs-self = inputs.self.packages.${pkgs.stdenv.hostPlatform.system}; + pkgs-self = inputs.self.legacyPackages.${pkgs.stdenv.hostPlatform.system}; in { fonts = { packages = [ diff --git a/modules/jj.nix b/modules/jj.nix index 0aaa2bf..5a5bff8 100644 --- a/modules/jj.nix +++ b/modules/jj.nix @@ -13,10 +13,6 @@ }; aliases = { - record = ["commit"]; - ci = ["commit"]; - rci = ["squash"]; - lg = ["log"]; tug = ["bookmark" "move" "--from" "closest_bookmark(@-)" "--to" "@-"]; pull = ["git" "fetch"]; push = ["git" "push"]; @@ -25,13 +21,59 @@ "--source" "roots(trunk()..mutable())" "--destination" "trunk()" ]; + + # Put changes from `@` into another change + # Inverse of `extract` + inject = ["squash" "--from" "@" "--into"]; + + # Fetch changes from change into `@` + # Inverse of `inject` + extract = ["squash" "--into" "@" "--form"]; + + # 'jj sandwich xyz' to move xyz into the megamerge in parallel to everything + # else. See notes on 'megamerge()' above for how it's resolved. + sandwich = [ "rebase" "-B" "megamerge()" "-A" "trunk()" "-r"]; }; revset-aliases = { "closest_bookmark(to)" = "heads(::to & bookmarks())"; + + # stack(x, n) is the set of mutable commits reachable from 'x', with 'n' + # parents. 'n' is often useful to customize the display and return set for + # certain operations. 'x' can be used to target the set of 'roots' to traverse, + # e.g. @ is the current stack. + "stack()" = "stack(@)"; + "stack(x)" = "stack(x, 2)"; + "stack(x, n)" = "ancestors(reachable(x, mutable()), n)"; + + # Find the megamerge. Mostly useful in combination with other aliases, primarily + # 'sandwich'. Normally when there's only one megamerge, sandwich works perfectly + # fine and is basically "magic". However, there are more complex cases; consider + # something like this which represents a forked repository of an upstream: + # + # + # ----> P1 ... Pn -----------\ + # / \ + # /---> X --\ (main) \ + # B M1 --> T1 ... Tn --> M2 --> @ + # \---> Y --/ + # + # X and Y are typical features on top of base B, combined inside megamerge M1. + # However, we may want changes T1...Tn to go on top of M1, because (in my case) + # they're custom and will never go upstream, but are correctly published as part + # of the fork; Tn is where the main bookmark points. Finally, we have changes P1 + # ... Pn which are private and should never be pushed upstream at all. + # + # In this case, sandwich will fail because 'reachable(stack(), merges())' will + # resolve to {M1, M2}, which is an invalid argument for 'rebase -B' due to not + # having an all: prefix modifier. So to handle that case, we allow the user + # to either specify the merge via literal tag "megamerge". In this case if we + # 'bookmark set megamerge -r M1' then sandwich will always work correctly. + "megamerge()" = "coalesce(present(megamerge), reachable(stack(), merges()))"; }; git = { + colocate = true; write-change-id-header = true; push-new-bookmarks = true; }; diff --git a/modules/tools.nix b/modules/tools.nix index d928169..6f843ca 100644 --- a/modules/tools.nix +++ b/modules/tools.nix @@ -12,6 +12,7 @@ in { home.packages = [ # bfs # pkgs-self.ubin-client + pkgs.ast-grep pkgs.btop pkgs.charm-freeze # pkgs.comby -- 2.51.2