├── .envrc ├── .github ├── dependabot.yml └── workflows │ ├── test.yml │ └── update.yml ├── .gitignore ├── LICENSE ├── README.md ├── default.nix ├── flake.lock ├── flake.nix ├── shell.nix ├── sources.json ├── templates ├── compiler-dev │ ├── .envrc │ ├── flake.lock │ ├── flake.nix │ └── shell.nix └── init │ ├── .envrc │ ├── flake.nix │ └── shell.nix └── update /.envrc: -------------------------------------------------------------------------------- 1 | # If we are a computer with nix-shell available, then use that to setup 2 | # the build environment with exactly what we need. 3 | if has nix; then 4 | use nix 5 | fi 6 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | on: [push, pull_request] 2 | name: Test 3 | jobs: 4 | test: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v4.2.2 8 | - uses: cachix/install-nix-action@v31 9 | with: 10 | nix_path: nixpkgs=channel:nixos-unstable 11 | - run: nix flake check 12 | 13 | # Verify the update script WORKS but we don't actually commit anything 14 | # in the test job. 15 | - run: ./update 16 | -------------------------------------------------------------------------------- /.github/workflows/update.yml: -------------------------------------------------------------------------------- 1 | name: update-sources 2 | on: 3 | schedule: 4 | - cron: '0 */12 * * *' 5 | workflow_dispatch: 6 | jobs: 7 | update-sources: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v4.2.2 11 | - uses: cachix/install-nix-action@v31 12 | with: 13 | nix_path: nixpkgs=channel:nixos-unstable 14 | - run: ./update 15 | - run: "git config user.email mitchellh@users.noreply.github.com" 16 | - run: "git config user.name zig-overlay" 17 | - run: "git add -A" 18 | - run: "git commit -m 'update sources.json' | true" 19 | - run: "git push -u origin main" 20 | 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | index.json 2 | index.json.minisig 3 | sources.old.json 4 | sources.new.json 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Mitchell Hashimoto 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Nix Flake for Zig 2 | 3 | This repository is a Nix flake packaging the [Zig](https://ziglang.org) 4 | compiler. The flake mirrors the binaries built officially by Zig and 5 | does not build them from source. 6 | 7 | This repository is meant to be consumed primarily as a flake but the 8 | `default.nix` can also be imported directly by non-flakes, too. 9 | 10 | The flake outputs are documented in `flake.nix` but an overview: 11 | 12 | * Default package and "app" is the latest released version 13 | * `packages.` for a tagged release 14 | * `packages.master` for the latest nightly release 15 | * `packages.master-` for a nightly release 16 | * `overlays.default` is an overlay that adds `zigpkgs` to be the packages 17 | exposed by this flake 18 | * `templates.compiler-dev` to setup a development environment for Zig 19 | compiler development. 20 | 21 | ## Usage 22 | 23 | ### Flake 24 | 25 | In your `flake.nix` file: 26 | 27 | ```nix 28 | { 29 | inputs.zig.url = "github:mitchellh/zig-overlay"; 30 | 31 | outputs = { self, zig, ... }: { 32 | ... 33 | }; 34 | } 35 | ``` 36 | 37 | In a shell: 38 | 39 | ```sh 40 | # run the latest released version 41 | $ nix run 'github:mitchellh/zig-overlay' 42 | # open a shell with nightly version dated 2021-02-13 (oldest version available) 43 | $ nix shell 'github:mitchellh/zig-overlay#master-2021-02-13' 44 | # open a shell with latest nightly version 45 | $ nix shell 'github:mitchellh/zig-overlay#master' 46 | ``` 47 | 48 | ### Compiler Development 49 | 50 | This flake outputs a template that makes it easy to work on the Zig 51 | compiler itself. If you're looking to contribute to the Zig compiler, 52 | here are the easy steps to setup a working development environment: 53 | 54 | ```sh 55 | # clone zig and go into that directory 56 | $ git clone https://github.com/ziglang/zig.git 57 | $ cd zig 58 | # setup the template 59 | $ nix flake init -t 'github:mitchellh/zig-overlay#compiler-dev' 60 | # Two options: 61 | # (1) start a shell, this forces bash 62 | $ nix develop 63 | # (2) If you have direnv installed, you can start the shell environment 64 | # in your active shell (fish, zsh, etc.): 65 | $ direnv allow 66 | ``` 67 | 68 | ## FAQ 69 | 70 | ### Why is a Nightly Missing? 71 | 72 | There are two possible reasons: 73 | 74 | 1. The Zig download JSON that is used to generate this overlay only shows 75 | the latest _master_ release. It doesn't keep track of historical releases. 76 | If this overlay wasn't running or didn't exist at the time of a release, 77 | we could miss a day. This is why historical dates beyond a certain point 78 | don't exist; they predate this overlay (or original overlays this derives 79 | from). 80 | 81 | 2. The official Zig CI only generates a master release if the CI runs 82 | full green. During certain periods of development, a full day may go by 83 | where the master branch of the Zig compiler is broken. In this scenario, 84 | a master build (aka "nightly") is not built or released at all. 85 | 86 | ## Thanks 87 | 88 | The `sources.json` file was originally from another Zig overlay repository 89 | hosted by the username `arqv`. This user and repository was deleted at some 90 | point, so I started a new flake based on the same `sources.json` format 91 | they used so I could inherit the history. Thank you for compiling nightly 92 | release information since 2021! 93 | -------------------------------------------------------------------------------- /default.nix: -------------------------------------------------------------------------------- 1 | { 2 | pkgs ? import {}, 3 | system ? builtins.currentSystem, 4 | }: let 5 | inherit (pkgs) lib; 6 | sources = builtins.fromJSON (lib.strings.fileContents ./sources.json); 7 | 8 | # mkBinaryInstall makes a derivation that installs Zig from a binary. 9 | mkBinaryInstall = { 10 | url, 11 | version, 12 | sha256, 13 | }: 14 | pkgs.stdenv.mkDerivation { 15 | inherit version; 16 | 17 | pname = "zig"; 18 | src = pkgs.fetchurl {inherit url sha256;}; 19 | dontConfigure = true; 20 | dontBuild = true; 21 | dontFixup = true; 22 | installPhase = '' 23 | mkdir -p $out/{doc,bin,lib} 24 | [ -d docs ] && cp -r docs/* $out/doc 25 | [ -d doc ] && cp -r doc/* $out/doc 26 | cp -r lib/* $out/lib 27 | cp zig $out/bin/zig 28 | ''; 29 | }; 30 | 31 | # The packages that are tagged releases 32 | taggedPackages = 33 | lib.attrsets.mapAttrs 34 | (k: v: mkBinaryInstall {inherit (v.${system}) version url sha256;}) 35 | (lib.attrsets.filterAttrs 36 | (k: v: (builtins.hasAttr system v) && (v.${system}.url != null) && (v.${system}.sha256 != null)) 37 | (builtins.removeAttrs sources ["master"])); 38 | 39 | # The master packages 40 | masterPackages = 41 | lib.attrsets.mapAttrs' ( 42 | k: v: 43 | lib.attrsets.nameValuePair 44 | ( 45 | if k == "latest" 46 | then "master" 47 | else ("master-" + k) 48 | ) 49 | (mkBinaryInstall {inherit (v.${system}) version url sha256;}) 50 | ) 51 | (lib.attrsets.filterAttrs 52 | (k: v: (builtins.hasAttr system v) && (v.${system}.url != null)) 53 | sources.master); 54 | 55 | # This determines the latest /released/ version. 56 | latest = lib.lists.last ( 57 | builtins.sort 58 | (x: y: (builtins.compareVersions x y) < 0) 59 | (builtins.attrNames taggedPackages) 60 | ); 61 | in 62 | # We want the packages but also add a "default" that just points to the 63 | # latest released version. 64 | taggedPackages // masterPackages // {"default" = taggedPackages.${latest};} 65 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "flake-compat": { 4 | "flake": false, 5 | "locked": { 6 | "lastModified": 1696426674, 7 | "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", 8 | "owner": "edolstra", 9 | "repo": "flake-compat", 10 | "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", 11 | "type": "github" 12 | }, 13 | "original": { 14 | "owner": "edolstra", 15 | "repo": "flake-compat", 16 | "type": "github" 17 | } 18 | }, 19 | "flake-utils": { 20 | "inputs": { 21 | "systems": "systems" 22 | }, 23 | "locked": { 24 | "lastModified": 1705309234, 25 | "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", 26 | "owner": "numtide", 27 | "repo": "flake-utils", 28 | "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", 29 | "type": "github" 30 | }, 31 | "original": { 32 | "owner": "numtide", 33 | "repo": "flake-utils", 34 | "type": "github" 35 | } 36 | }, 37 | "nixpkgs": { 38 | "locked": { 39 | "lastModified": 1708161998, 40 | "narHash": "sha256-6KnemmUorCvlcAvGziFosAVkrlWZGIc6UNT9GUYr0jQ=", 41 | "owner": "NixOS", 42 | "repo": "nixpkgs", 43 | "rev": "84d981bae8b5e783b3b548de505b22880559515f", 44 | "type": "github" 45 | }, 46 | "original": { 47 | "owner": "NixOS", 48 | "ref": "nixos-23.11", 49 | "repo": "nixpkgs", 50 | "type": "github" 51 | } 52 | }, 53 | "root": { 54 | "inputs": { 55 | "flake-compat": "flake-compat", 56 | "flake-utils": "flake-utils", 57 | "nixpkgs": "nixpkgs" 58 | } 59 | }, 60 | "systems": { 61 | "locked": { 62 | "lastModified": 1681028828, 63 | "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 64 | "owner": "nix-systems", 65 | "repo": "default", 66 | "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 67 | "type": "github" 68 | }, 69 | "original": { 70 | "owner": "nix-systems", 71 | "repo": "default", 72 | "type": "github" 73 | } 74 | } 75 | }, 76 | "root": "root", 77 | "version": 7 78 | } 79 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "Zig compiler binaries."; 3 | 4 | inputs = { 5 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; 6 | flake-utils.url = "github:numtide/flake-utils"; 7 | 8 | # Used for shell.nix 9 | flake-compat = { 10 | url = "github:edolstra/flake-compat"; 11 | flake = false; 12 | }; 13 | }; 14 | 15 | outputs = { 16 | self, 17 | nixpkgs, 18 | flake-utils, 19 | ... 20 | }: let 21 | systems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"]; 22 | outputs = flake-utils.lib.eachSystem systems (system: let 23 | pkgs = nixpkgs.legacyPackages.${system}; 24 | in rec { 25 | # The packages exported by the Flake: 26 | # - default - latest /released/ version 27 | # - - tagged version 28 | # - master - latest nightly (updated daily) 29 | # - master- - nightly by date 30 | packages = import ./default.nix {inherit system pkgs;}; 31 | 32 | # "Apps" so that `nix run` works. If you run `nix run .` then 33 | # this will use the latest default. 34 | apps = rec { 35 | default = apps.zig; 36 | zig = flake-utils.lib.mkApp {drv = packages.default;}; 37 | }; 38 | 39 | # nix fmt 40 | formatter = pkgs.alejandra; 41 | 42 | devShells.default = pkgs.mkShell { 43 | nativeBuildInputs = with pkgs; [ 44 | curl 45 | jq 46 | minisign 47 | ]; 48 | }; 49 | 50 | # For compatibility with older versions of the `nix` binary 51 | devShell = self.devShells.${system}.default; 52 | }); 53 | in 54 | outputs 55 | // { 56 | # Overlay that can be imported so you can access the packages 57 | # using zigpkgs.master or whatever you'd like. 58 | overlays.default = final: prev: { 59 | zigpkgs = outputs.packages.${prev.system}; 60 | }; 61 | 62 | # Templates for use with nix flake init 63 | templates.compiler-dev = { 64 | path = ./templates/compiler-dev; 65 | description = "A development environment for Zig compiler development."; 66 | }; 67 | 68 | templates.init = { 69 | path = ./templates/init; 70 | description = "A basic, empty development environment."; 71 | }; 72 | }; 73 | } 74 | -------------------------------------------------------------------------------- /shell.nix: -------------------------------------------------------------------------------- 1 | (import 2 | ( 3 | let 4 | flake-compat = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.flake-compat; 5 | in 6 | fetchTarball { 7 | url = "https://github.com/edolstra/flake-compat/archive/${flake-compat.locked.rev}.tar.gz"; 8 | sha256 = flake-compat.locked.narHash; 9 | } 10 | ) 11 | {src = ./.;}) 12 | .shellNix 13 | -------------------------------------------------------------------------------- /templates/compiler-dev/.envrc: -------------------------------------------------------------------------------- 1 | # use nix shell if nix is available 2 | if has nix; then 3 | use nix 4 | fi 5 | -------------------------------------------------------------------------------- /templates/compiler-dev/flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "flake-compat": { 4 | "flake": false, 5 | "locked": { 6 | "lastModified": 1696426674, 7 | "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", 8 | "owner": "edolstra", 9 | "repo": "flake-compat", 10 | "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", 11 | "type": "github" 12 | }, 13 | "original": { 14 | "owner": "edolstra", 15 | "repo": "flake-compat", 16 | "type": "github" 17 | } 18 | }, 19 | "flake-utils": { 20 | "inputs": { 21 | "systems": "systems" 22 | }, 23 | "locked": { 24 | "lastModified": 1710146030, 25 | "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", 26 | "owner": "numtide", 27 | "repo": "flake-utils", 28 | "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", 29 | "type": "github" 30 | }, 31 | "original": { 32 | "owner": "numtide", 33 | "repo": "flake-utils", 34 | "type": "github" 35 | } 36 | }, 37 | "nixpkgs": { 38 | "locked": { 39 | "lastModified": 1715161350, 40 | "narHash": "sha256-5ZU8DVwHO0gjw2sKoKkToYOXMJFRBpRsa17Ebm8fgj0=", 41 | "owner": "NixOS", 42 | "repo": "nixpkgs", 43 | "rev": "c4200cb341ee794775185ecd4105fbbfb5ca73a0", 44 | "type": "github" 45 | }, 46 | "original": { 47 | "owner": "NixOS", 48 | "ref": "nixpkgs-unstable", 49 | "repo": "nixpkgs", 50 | "type": "github" 51 | } 52 | }, 53 | "root": { 54 | "inputs": { 55 | "flake-compat": "flake-compat", 56 | "flake-utils": "flake-utils", 57 | "nixpkgs": "nixpkgs" 58 | } 59 | }, 60 | "systems": { 61 | "locked": { 62 | "lastModified": 1681028828, 63 | "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 64 | "owner": "nix-systems", 65 | "repo": "default", 66 | "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 67 | "type": "github" 68 | }, 69 | "original": { 70 | "owner": "nix-systems", 71 | "repo": "default", 72 | "type": "github" 73 | } 74 | } 75 | }, 76 | "root": "root", 77 | "version": 7 78 | } 79 | -------------------------------------------------------------------------------- /templates/compiler-dev/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "Zig compiler development."; 3 | 4 | inputs = { 5 | nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; 6 | flake-utils.url = "github:numtide/flake-utils"; 7 | 8 | # Used for shell.nix 9 | flake-compat = { 10 | url = "github:edolstra/flake-compat"; 11 | flake = false; 12 | }; 13 | }; 14 | 15 | outputs = { 16 | self, 17 | nixpkgs, 18 | flake-utils, 19 | ... 20 | } @ inputs: 21 | flake-utils.lib.eachDefaultSystem ( 22 | system: let 23 | pkgs = import nixpkgs {inherit system;}; 24 | in { 25 | devShells.default = pkgs.mkShell { 26 | nativeBuildInputs = with pkgs; 27 | [ 28 | cmake 29 | gdb 30 | libxml2 31 | ninja 32 | qemu 33 | wasmtime 34 | zlib 35 | ] 36 | ++ (with llvmPackages_18; [ 37 | clang 38 | clang-unwrapped 39 | lld 40 | llvm 41 | ]); 42 | 43 | hardeningDisable = ["all"]; 44 | }; 45 | 46 | # For compatibility with older versions of the `nix` binary 47 | devShell = self.devShells.${system}.default; 48 | } 49 | ); 50 | } 51 | -------------------------------------------------------------------------------- /templates/compiler-dev/shell.nix: -------------------------------------------------------------------------------- 1 | (import 2 | ( 3 | let 4 | flake-compat = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.flake-compat; 5 | in 6 | fetchTarball { 7 | url = "https://github.com/edolstra/flake-compat/archive/${flake-compat.locked.rev}.tar.gz"; 8 | sha256 = flake-compat.locked.narHash; 9 | } 10 | ) 11 | {src = ./.;}) 12 | .shellNix 13 | -------------------------------------------------------------------------------- /templates/init/.envrc: -------------------------------------------------------------------------------- 1 | # If we are a computer with nix-shell available, then use that to setup 2 | # the build environment with exactly what we need. 3 | if has nix; then 4 | use nix 5 | fi 6 | -------------------------------------------------------------------------------- /templates/init/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "An empty project that uses Zig."; 3 | 4 | inputs = { 5 | nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05"; 6 | flake-utils.url = "github:numtide/flake-utils"; 7 | zig.url = "github:mitchellh/zig-overlay"; 8 | 9 | # Used for shell.nix 10 | flake-compat = { 11 | url = "github:edolstra/flake-compat"; 12 | flake = false; 13 | }; 14 | }; 15 | 16 | outputs = { 17 | self, 18 | nixpkgs, 19 | flake-utils, 20 | ... 21 | } @ inputs: let 22 | overlays = [ 23 | # Other overlays 24 | (final: prev: { 25 | zigpkgs = inputs.zig.packages.${prev.system}; 26 | }) 27 | ]; 28 | 29 | # Our supported systems are the same supported systems as the Zig binaries 30 | systems = builtins.attrNames inputs.zig.packages; 31 | in 32 | flake-utils.lib.eachSystem systems ( 33 | system: let 34 | pkgs = import nixpkgs {inherit overlays system;}; 35 | in rec { 36 | devShells.default = pkgs.mkShell { 37 | nativeBuildInputs = with pkgs; [ 38 | zigpkgs.master 39 | ]; 40 | }; 41 | 42 | # For compatibility with older versions of the `nix` binary 43 | devShell = self.devShells.${system}.default; 44 | } 45 | ); 46 | } 47 | -------------------------------------------------------------------------------- /templates/init/shell.nix: -------------------------------------------------------------------------------- 1 | (import 2 | ( 3 | let 4 | flake-compat = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.flake-compat; 5 | in 6 | fetchTarball { 7 | url = "https://github.com/edolstra/flake-compat/archive/${flake-compat.locked.rev}.tar.gz"; 8 | sha256 = flake-compat.locked.narHash; 9 | } 10 | ) 11 | {src = ./.;}) 12 | .shellNix 13 | -------------------------------------------------------------------------------- /update: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env nix-shell 2 | #! nix-shell -p curl jq minisign -i sh 3 | set -e 4 | 5 | # The well known public key for Zig 6 | PUBLIC_KEY="RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U" 7 | 8 | # Grab the JSON and parse the version 9 | rm -rf index.json index.json.minisig 10 | curl -s 'https://ziglang.org/download/index.json' > index.json 11 | VERSION=$(cat index.json | jq -r '.master.version') 12 | echo "Parsing master version: ${VERSION}" 13 | 14 | # Verify the signature of the JSON before we parse it 15 | curl -s "https://ziglang.org/builds/zig-${VERSION}-index.json.minisig" > index.json.minisig 16 | minisign -V -P ${PUBLIC_KEY} -x index.json.minisig -m index.json 17 | 18 | # Build our new sources.json 19 | cat index.json | jq ' 20 | ["aarch64-linux", "x86_64-linux", "aarch64-macos", "x86_64-macos", "aarch64-windows", "x86_64-windows"] as $targets | 21 | def todarwin(x): x | gsub("macos"; "darwin"); 22 | def toentry(vsn; x): 23 | [(vsn as $version | 24 | .value | 25 | to_entries[] | 26 | select(.key as $key | any($targets[]; . == $key)) | { 27 | (todarwin(.key)): { 28 | "url": .value.tarball, 29 | "sha256": .value.shasum, 30 | "version": $version, 31 | } 32 | } 33 | )] | add | first(values, {}); 34 | 35 | reduce to_entries[] as $entry ({}; . * ( 36 | $entry | { 37 | (.key): ( 38 | if (.key != "master") then 39 | toentry(.key; .value) 40 | else { 41 | "latest": toentry(.value.version; .value), 42 | (.value.date): toentry(.value.version; .value), 43 | } end 44 | ) 45 | } 46 | )) 47 | ' > sources.new.json 48 | 49 | # For debugging 50 | # cat sources.new.json 51 | # exit 52 | 53 | # Copy the old file since jq can't modify in-place. This is also a backup. 54 | cp sources.json sources.old.json 55 | 56 | # Recursive merge 57 | jq -s '.[0] * .[1]' sources.old.json sources.new.json > sources.json 58 | --------------------------------------------------------------------------------