├── .gitignore ├── .github ├── dependabot.yml └── workflows │ ├── release.yml │ └── ci.yml ├── CHANGELOG.md ├── src ├── Dependency.zig ├── codegen.zig ├── main.zig ├── fetch.zig └── parse.zig ├── nix └── package.nix ├── fixtures └── basic.zon ├── flake.nix ├── README.md ├── flake.lock └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | /result 2 | /.zig-cache 3 | /zig-out 4 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | updates: 4 | - package-ecosystem: github-actions 5 | directory: / 6 | schedule: 7 | interval: daily 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## v0.1.2 - 2023-09-03 4 | 5 | ### Changes 6 | 7 | - move to nix-community 8 | 9 | ## v0.1.1 - 2023-08-08 10 | 11 | ### Fixes 12 | 13 | - fetch: do not assume experimental features are enabled 14 | 15 | ## v0.1.0 - 2023-08-08 16 | 17 | First release 18 | -------------------------------------------------------------------------------- /src/Dependency.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const Dependency = @This(); 3 | 4 | url: []const u8, 5 | rev: ?[]const u8, 6 | nix_hash: ?[]const u8, 7 | done: bool, 8 | 9 | pub fn deinit(self: Dependency, alloc: std.mem.Allocator) void { 10 | alloc.free(self.url); 11 | if (self.rev) |rev| alloc.free(rev); 12 | if (self.nix_hash) |nix_hash| alloc.free(nix_hash); 13 | } 14 | -------------------------------------------------------------------------------- /nix/package.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib, 3 | stdenv, 4 | zig, 5 | nix, 6 | }: 7 | stdenv.mkDerivation { 8 | pname = "zon2nix"; 9 | version = "0.1.2"; 10 | 11 | src = ../.; 12 | 13 | nativeBuildInputs = [ 14 | zig.hook 15 | ]; 16 | 17 | zigBuildFlags = [ 18 | "-Dnix=${lib.getExe nix}" 19 | "-Dlinkage=${if stdenv.hostPlatform.isStatic then "static" else "dynamic"}" 20 | ]; 21 | 22 | zigCheckFlags = [ 23 | "-Dnix=${lib.getExe nix}" 24 | "-Dlinkage=${if stdenv.hostPlatform.isStatic then "static" else "dynamic"}" 25 | ]; 26 | } 27 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: release 2 | 3 | on: 4 | push: 5 | tags: 6 | - v[0-9]+.[0-9]+.[0-9]+ 7 | workflow_dispatch: 8 | inputs: 9 | tag: 10 | description: The existing tag to publish to FlakeHub 11 | type: string 12 | required: true 13 | 14 | jobs: 15 | release: 16 | runs-on: ubuntu-latest 17 | if: github.event_name != 'workflow_dispatch' 18 | steps: 19 | - uses: softprops/action-gh-release@v2 20 | with: 21 | body: "[CHANGELOG.md](https://github.com/nix-community/zon2nix/blob/main/CHANGELOG.md)" 22 | 23 | flakehub: 24 | runs-on: ubuntu-latest 25 | permissions: 26 | id-token: write 27 | contents: read 28 | steps: 29 | - uses: actions/checkout@v4 30 | with: 31 | ref: ${{ inputs.tag != null && format('refs/tags/{0}', inputs.tag) || '' }} 32 | - uses: DeterminateSystems/nix-installer-action@v16 33 | - uses: DeterminateSystems/flakehub-push@v5 34 | with: 35 | visibility: public 36 | tag: ${{ inputs.tag }} 37 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | 9 | jobs: 10 | test: 11 | name: test 12 | runs-on: ${{ matrix.os }} 13 | strategy: 14 | matrix: 15 | os: [macos-latest, ubuntu-latest, macos-13, ubuntu-24.04-arm] 16 | 17 | steps: 18 | - name: Checkout 19 | uses: actions/checkout@v4 20 | 21 | - name: Set up zig 22 | uses: goto-bus-stop/setup-zig@v2 23 | with: 24 | version: 0.13.0 25 | 26 | - uses: DeterminateSystems/nix-installer-action@main 27 | 28 | - name: Run tests 29 | run: zig build test 30 | 31 | - name: Run executable on zls 32 | run: | 33 | git clone https://github.com/zigtools/zls 34 | nix run .#default_0_13 -- zls 35 | nix run . -- zls 36 | 37 | format: 38 | name: format 39 | runs-on: ubuntu-latest 40 | steps: 41 | - name: Checkout 42 | uses: actions/checkout@v4 43 | 44 | - name: Set up zig 45 | uses: goto-bus-stop/setup-zig@v2 46 | with: 47 | version: 0.13.0 48 | 49 | - name: Check formatting 50 | run: zig fmt --check . 51 | -------------------------------------------------------------------------------- /fixtures/basic.zon: -------------------------------------------------------------------------------- 1 | .{ 2 | .name = "zls", 3 | .version = "0.11.0", 4 | 5 | .dependencies = .{ 6 | .known_folders = .{ 7 | .url = "https://github.com/ziglibs/known-folders/archive/fa75e1bc672952efa0cf06160bbd942b47f6d59b.tar.gz", 8 | .hash = "122048992ca58a78318b6eba4f65c692564be5af3b30fbef50cd4abeda981b2e7fa5", 9 | }, 10 | .diffz = .{ 11 | .url = "https://github.com/ziglibs/diffz/archive/90353d401c59e2ca5ed0abe5444c29ad3d7489aa.tar.gz", 12 | .hash = "122089a8247a693cad53beb161bde6c30f71376cd4298798d45b32740c3581405864", 13 | }, 14 | .binned_allocator = .{ 15 | .url = "https://gist.github.com/antlilja/8372900fcc09e38d7b0b6bbaddad3904/archive/6c3321e0969ff2463f8335da5601986cf2108690.tar.gz", 16 | .hash = "1220363c7e27b2d3f39de6ff6e90f9537a0634199860fea237a55ddb1e1717f5d6a5", 17 | }, 18 | // git+https test 19 | .ziggy = .{ 20 | .url = "git+https://github.com/kristoff-it/ziggy#c66f47bc632c66668d61fa06eda112b41d6e5130", 21 | .hash = "1220115ff095a3c970cc90fce115294ba67d6fbc4927472dc856abc51e2a1a9364d7", 22 | }, 23 | // this has deps (github.com/zigimg/zigimg and codeberg.org/atman/zg) with no deps 24 | .vaxis = .{ 25 | .url = "git+https://github.com/rockorager/libvaxis#1fd920a7aea1bb040c7c028f4bbf0af2ea58e1d1", 26 | .hash = "1220feaa655e14cbb4baf59fe746f09a17fc6949be46ad64dd5044982f4fc1bb57c7", 27 | }, 28 | // from a problem during https://github.com/nix-community/zon2nix/pull/24 29 | .@"zig-tracy" = .{ 30 | .url = "git+https://github.com/vancluever/zig-tracy?ref=fix-callstack#6e123ee26032e49a1a0039524ddf7970692931d9", 31 | .hash = "122094fc39764bd527269d3721f52fc3b8cbb72bc4cdbd3345cbc2cd941936f3d185", 32 | .lazy = true, 33 | }, 34 | }, 35 | } 36 | -------------------------------------------------------------------------------- /src/codegen.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const assert = std.debug.assert; 3 | const Allocator = std.mem.Allocator; 4 | const StringHashMap = std.StringHashMap; 5 | const mem = std.mem; 6 | 7 | const Dependency = @import("Dependency.zig"); 8 | 9 | const Entry = StringHashMap(Dependency).Entry; 10 | 11 | pub fn write(alloc: Allocator, out: anytype, deps: StringHashMap(Dependency)) !void { 12 | try out.writeAll( 13 | \\# generated by zon2nix (https://github.com/nix-community/zon2nix) 14 | \\ 15 | \\{ linkFarm, fetchzip, fetchgit }: 16 | \\ 17 | \\linkFarm "zig-packages" [ 18 | \\ 19 | ); 20 | 21 | const len = deps.count(); 22 | 23 | var entries = try alloc.alloc(Entry, len); 24 | defer alloc.free(entries); 25 | 26 | var iter = deps.iterator(); 27 | for (0..len) |i| { 28 | entries[i] = iter.next().?; 29 | } 30 | mem.sortUnstable(Entry, entries, {}, lessThan); 31 | 32 | for (entries) |entry| { 33 | const key = entry.key_ptr.*; 34 | const dep = entry.value_ptr.*; 35 | const nix_hash = dep.nix_hash orelse return error.MissingNixHash; 36 | if (dep.rev) |rev| { 37 | try out.print( 38 | \\ {{ 39 | \\ name = "{s}"; 40 | \\ path = fetchgit {{ 41 | \\ url = "{s}"; 42 | \\ rev = "{s}"; 43 | \\ hash = "{s}"; 44 | \\ }}; 45 | \\ }} 46 | \\ 47 | , .{ key, dep.url, rev, nix_hash }); 48 | } else { 49 | try out.print( 50 | \\ {{ 51 | \\ name = "{s}"; 52 | \\ path = fetchzip {{ 53 | \\ url = "{s}"; 54 | \\ hash = "{s}"; 55 | \\ }}; 56 | \\ }} 57 | \\ 58 | , .{ key, dep.url, nix_hash }); 59 | } 60 | } 61 | 62 | try out.writeAll("]\n"); 63 | } 64 | 65 | fn lessThan(_: void, lhs: Entry, rhs: Entry) bool { 66 | return mem.order(u8, lhs.key_ptr.*, rhs.key_ptr.*) == .lt; 67 | } 68 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "zon2nix helps you package Zig project with Nix, by converting the dependencies in a build.zig.zon to a Nix expression."; 3 | 4 | inputs = { 5 | flake-parts = { 6 | url = "github:hercules-ci/flake-parts"; 7 | inputs.nixpkgs-lib.follows = "nixpkgs"; 8 | }; 9 | nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; 10 | zig-overlay = { 11 | url = "github:mitchellh/zig-overlay"; 12 | inputs.nixpkgs.follows = "nixpkgs"; 13 | }; 14 | }; 15 | 16 | outputs = 17 | inputs@{ flake-parts, ... }: 18 | flake-parts.lib.mkFlake { inherit inputs; } { 19 | systems = [ 20 | "aarch64-darwin" 21 | "aarch64-linux" 22 | "x86_64-darwin" 23 | "x86_64-linux" 24 | ]; 25 | 26 | flake.herculesCI.ciSystems = [ 27 | "aarch64-linux" 28 | "x86_64-linux" 29 | ]; 30 | 31 | perSystem = 32 | { 33 | system, 34 | lib, 35 | pkgs, 36 | ... 37 | }: 38 | let 39 | inherit (pkgs) 40 | callPackage 41 | zigpkgs 42 | zig_0_13 43 | zig_0_14 44 | ; 45 | in 46 | { 47 | _module.args.pkgs = import inputs.nixpkgs { 48 | inherit system; 49 | overlays = [ 50 | inputs.zig-overlay.overlays.default 51 | ]; 52 | config = { }; 53 | }; 54 | 55 | packages = { 56 | default = callPackage ./nix/package.nix { 57 | zig = zigpkgs.master.overrideAttrs ( 58 | f: p: { 59 | inherit (zig_0_14) meta; 60 | 61 | passthru.hook = callPackage "${inputs.nixpkgs}/pkgs/development/compilers/zig/hook.nix" { 62 | zig = f.finalPackage; 63 | }; 64 | } 65 | ); 66 | }; 67 | default_0_14 = callPackage ./nix/package.nix { 68 | zig = zig_0_14; 69 | }; 70 | default_0_13 = callPackage ./nix/package.nix { 71 | zig = zig_0_13; 72 | }; 73 | }; 74 | }; 75 | }; 76 | } 77 | -------------------------------------------------------------------------------- /src/main.zig: -------------------------------------------------------------------------------- 1 | const builtin = @import("builtin"); 2 | const std = @import("std"); 3 | const StringHashMap = std.StringHashMap; 4 | const fs = std.fs; 5 | const heap = std.heap; 6 | const io = std.io; 7 | const process = std.process; 8 | 9 | const Dependency = @import("Dependency.zig"); 10 | const fetch = @import("fetch.zig").fetch; 11 | const parse = @import("parse.zig").parse; 12 | const write = @import("codegen.zig").write; 13 | 14 | const zig_legacy_version = (std.SemanticVersion{ 15 | .major = builtin.zig_version.major, 16 | .minor = builtin.zig_version.minor, 17 | .patch = builtin.zig_version.patch, 18 | }).order(.{ 19 | .major = 0, 20 | .minor = 14, 21 | .patch = 0, 22 | }) == .lt; 23 | 24 | const DebugAllocator = @field(std.heap, if (zig_legacy_version) "GeneralPurposeAllocator" else "DebugAllocator"); 25 | 26 | var debug_allocator: DebugAllocator(.{}) = if (zig_legacy_version) .{} else .init; 27 | 28 | pub fn main() !void { 29 | var args = process.args(); 30 | _ = args.skip(); 31 | const dir = fs.cwd(); 32 | 33 | const file = try if (args.next()) |path| 34 | if ((try dir.statFile(path)).kind == .directory) 35 | (try dir.openDir(path, .{})).openFile("build.zig.zon", .{}) 36 | else 37 | dir.openFile(path, .{}) 38 | else 39 | dir.openFile("build.zig.zon", .{}); 40 | defer file.close(); 41 | 42 | const gpa, const is_debug = gpa: { 43 | break :gpa switch (builtin.mode) { 44 | .Debug, .ReleaseSafe => .{ debug_allocator.allocator(), true }, 45 | .ReleaseFast, .ReleaseSmall => .{ std.heap.smp_allocator, false }, 46 | }; 47 | }; 48 | defer if (is_debug) { 49 | _ = debug_allocator.deinit(); 50 | }; 51 | 52 | var deps = StringHashMap(Dependency).init(gpa); 53 | defer { 54 | var iter = deps.iterator(); 55 | while (iter.next()) |entry| { 56 | gpa.free(entry.key_ptr.*); 57 | entry.value_ptr.deinit(gpa); 58 | } 59 | deps.deinit(); 60 | } 61 | 62 | try parse(gpa, &deps, file); 63 | try fetch(gpa, &deps); 64 | 65 | var out = io.bufferedWriter(io.getStdOut().writer()); 66 | try write(gpa, out.writer(), deps); 67 | try out.flush(); 68 | } 69 | 70 | comptime { 71 | std.testing.refAllDecls(@This()); 72 | } 73 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # zon2nix 2 | 3 | Convert the dependencies in `build.zig.zon` to a Nix expression 4 | 5 | ## Usage 6 | 7 | ```bash 8 | zon2nix > deps.nix 9 | zon2nix zls > deps.nix 10 | zon2nix zls/build.zig.zon > deps.nix 11 | ``` 12 | 13 | To use the generated file, add this to your Nix expression: 14 | 15 | ```nix 16 | postPatch = '' 17 | ln -s ${callPackage ./deps.nix { }} $ZIG_GLOBAL_CACHE_DIR/p 18 | ''; 19 | ``` 20 | 21 | ## Example 22 | 23 | This `build.zig.zon` from [zls](https://github.com/zigtools/zls) 24 | 25 | ```zig 26 | .{ 27 | .name = "zls", 28 | .version = "0.11.0", 29 | 30 | .dependencies = .{ 31 | .known_folders = .{ 32 | .url = "https://github.com/ziglibs/known-folders/archive/fa75e1bc672952efa0cf06160bbd942b47f6d59b.tar.gz", 33 | .hash = "122048992ca58a78318b6eba4f65c692564be5af3b30fbef50cd4abeda981b2e7fa5", 34 | }, 35 | .diffz = .{ 36 | .url = "https://github.com/ziglibs/diffz/archive/90353d401c59e2ca5ed0abe5444c29ad3d7489aa.tar.gz", 37 | .hash = "122089a8247a693cad53beb161bde6c30f71376cd4298798d45b32740c3581405864", 38 | }, 39 | .binned_allocator = .{ 40 | .url = "https://gist.github.com/antlilja/8372900fcc09e38d7b0b6bbaddad3904/archive/6c3321e0969ff2463f8335da5601986cf2108690.tar.gz", 41 | .hash = "1220363c7e27b2d3f39de6ff6e90f9537a0634199860fea237a55ddb1e1717f5d6a5", 42 | }, 43 | }, 44 | } 45 | ``` 46 | 47 | produces the following nix expression 48 | 49 | ```nix 50 | # generated by zon2nix (https://github.com/nix-community/zon2nix) 51 | 52 | { linkFarm, fetchzip }: 53 | 54 | linkFarm "zig-packages" [ 55 | { 56 | name = "1220363c7e27b2d3f39de6ff6e90f9537a0634199860fea237a55ddb1e1717f5d6a5"; 57 | path = fetchzip { 58 | url = "https://gist.github.com/antlilja/8372900fcc09e38d7b0b6bbaddad3904/archive/6c3321e0969ff2463f8335da5601986cf2108690.tar.gz"; 59 | hash = "sha256-m/kr4kmkG2rLkAj5YwvM0HmXTd+chAiQHzYK6ozpWlw="; 60 | }; 61 | } 62 | { 63 | name = "122048992ca58a78318b6eba4f65c692564be5af3b30fbef50cd4abeda981b2e7fa5"; 64 | path = fetchzip { 65 | url = "https://github.com/ziglibs/known-folders/archive/fa75e1bc672952efa0cf06160bbd942b47f6d59b.tar.gz"; 66 | hash = "sha256-U/h4bVarq8CFKbFyNXKl3vBRPubYooLxA1xUz3qMGPE="; 67 | }; 68 | } 69 | { 70 | name = "122089a8247a693cad53beb161bde6c30f71376cd4298798d45b32740c3581405864"; 71 | path = fetchzip { 72 | url = "https://github.com/ziglibs/diffz/archive/90353d401c59e2ca5ed0abe5444c29ad3d7489aa.tar.gz"; 73 | hash = "sha256-3CdYo6WevT0alRwKmbABahjhFKz7V9rdkDUZ43VtDeU="; 74 | }; 75 | } 76 | ] 77 | ``` 78 | -------------------------------------------------------------------------------- /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-parts": { 20 | "inputs": { 21 | "nixpkgs-lib": [ 22 | "nixpkgs" 23 | ] 24 | }, 25 | "locked": { 26 | "lastModified": 1741352980, 27 | "narHash": "sha256-+u2UunDA4Cl5Fci3m7S643HzKmIDAe+fiXrLqYsR2fs=", 28 | "owner": "hercules-ci", 29 | "repo": "flake-parts", 30 | "rev": "f4330d22f1c5d2ba72d3d22df5597d123fdb60a9", 31 | "type": "github" 32 | }, 33 | "original": { 34 | "owner": "hercules-ci", 35 | "repo": "flake-parts", 36 | "type": "github" 37 | } 38 | }, 39 | "flake-utils": { 40 | "inputs": { 41 | "systems": "systems" 42 | }, 43 | "locked": { 44 | "lastModified": 1705309234, 45 | "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", 46 | "owner": "numtide", 47 | "repo": "flake-utils", 48 | "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", 49 | "type": "github" 50 | }, 51 | "original": { 52 | "owner": "numtide", 53 | "repo": "flake-utils", 54 | "type": "github" 55 | } 56 | }, 57 | "nixpkgs": { 58 | "locked": { 59 | "lastModified": 1742288794, 60 | "narHash": "sha256-Txwa5uO+qpQXrNG4eumPSD+hHzzYi/CdaM80M9XRLCo=", 61 | "owner": "nixos", 62 | "repo": "nixpkgs", 63 | "rev": "b6eaf97c6960d97350c584de1b6dcff03c9daf42", 64 | "type": "github" 65 | }, 66 | "original": { 67 | "owner": "nixos", 68 | "ref": "nixos-unstable", 69 | "repo": "nixpkgs", 70 | "type": "github" 71 | } 72 | }, 73 | "root": { 74 | "inputs": { 75 | "flake-parts": "flake-parts", 76 | "nixpkgs": "nixpkgs", 77 | "zig-overlay": "zig-overlay" 78 | } 79 | }, 80 | "systems": { 81 | "locked": { 82 | "lastModified": 1681028828, 83 | "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 84 | "owner": "nix-systems", 85 | "repo": "default", 86 | "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 87 | "type": "github" 88 | }, 89 | "original": { 90 | "owner": "nix-systems", 91 | "repo": "default", 92 | "type": "github" 93 | } 94 | }, 95 | "zig-overlay": { 96 | "inputs": { 97 | "flake-compat": "flake-compat", 98 | "flake-utils": "flake-utils", 99 | "nixpkgs": [ 100 | "nixpkgs" 101 | ] 102 | }, 103 | "locked": { 104 | "lastModified": 1742430672, 105 | "narHash": "sha256-orBItpmsW/07AsxDmfKnMerGN6jlkaEx2b0ct6digXk=", 106 | "owner": "mitchellh", 107 | "repo": "zig-overlay", 108 | "rev": "5c0be45cf5af521165c38766846f56e75475b763", 109 | "type": "github" 110 | }, 111 | "original": { 112 | "owner": "mitchellh", 113 | "repo": "zig-overlay", 114 | "type": "github" 115 | } 116 | } 117 | }, 118 | "root": "root", 119 | "version": 7 120 | } 121 | -------------------------------------------------------------------------------- /src/fetch.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const assert = std.debug.assert; 3 | const Allocator = std.mem.Allocator; 4 | const ArrayList = std.ArrayList; 5 | const ChildProcess = std.process.Child; 6 | const StringHashMap = std.StringHashMap; 7 | const mem = std.mem; 8 | const fmt = std.fmt; 9 | const fs = std.fs; 10 | const json = std.json; 11 | const log = std.log; 12 | 13 | const nix = @import("options").nix; 14 | 15 | const Dependency = @import("Dependency.zig"); 16 | const parse = @import("parse.zig").parse; 17 | 18 | const Prefetch = struct { 19 | hash: []const u8, 20 | storePath: []const u8, 21 | }; 22 | 23 | const Worker = struct { 24 | child: *ChildProcess, 25 | dep: *Dependency, 26 | }; 27 | 28 | pub fn fetch(alloc: Allocator, deps: *StringHashMap(Dependency)) !void { 29 | var workers = try ArrayList(Worker).initCapacity(alloc, deps.count()); 30 | defer workers.deinit(); 31 | var done = false; 32 | 33 | while (!done) { 34 | var iter = deps.valueIterator(); 35 | while (iter.next()) |dep| { 36 | if (dep.done) { 37 | continue; 38 | } 39 | 40 | var child = try alloc.create(ChildProcess); 41 | const ref = ref: { 42 | const base = base: { 43 | if (dep.rev) |rev| { 44 | break :base try fmt.allocPrint(alloc, "git+{s}?rev={s}", .{ dep.url, rev }); 45 | } else { 46 | break :base try fmt.allocPrint(alloc, "tarball+{s}", .{dep.url}); 47 | } 48 | }; 49 | 50 | const revi = mem.lastIndexOf(u8, base, "rev=") orelse break :ref base; 51 | const refi = mem.lastIndexOf(u8, base, "ref=") orelse break :ref base; 52 | 53 | defer alloc.free(base); 54 | 55 | const i = @min(revi, refi); 56 | break :ref try alloc.dupe(u8, base[0..(i - 1)]); 57 | }; 58 | defer alloc.free(ref); 59 | 60 | log.debug("running \"nix flake prefetch --json --extra-experimental-features 'flakes nix-command' {s}\"", .{ref}); 61 | const argv = &[_][]const u8{ nix, "flake", "prefetch", "--json", "--extra-experimental-features", "flakes nix-command", ref }; 62 | child.* = ChildProcess.init(argv, alloc); 63 | child.stdin_behavior = .Ignore; 64 | child.stdout_behavior = .Pipe; 65 | try child.spawn(); 66 | try workers.append(.{ .child = child, .dep = dep }); 67 | } 68 | 69 | const len_before = deps.count(); 70 | done = true; 71 | 72 | for (workers.items) |worker| { 73 | const child = worker.child; 74 | const dep = worker.dep; 75 | 76 | defer alloc.destroy(child); 77 | 78 | const buf = try child.stdout.?.readToEndAlloc(alloc, std.math.maxInt(usize)); 79 | defer alloc.free(buf); 80 | 81 | log.debug("nix prefetch for \"{s}\" returned: {s}", .{ dep.url, buf }); 82 | 83 | const res = try json.parseFromSlice(Prefetch, alloc, buf, .{ 84 | .ignore_unknown_fields = true, 85 | .allocate = .alloc_always, 86 | }); 87 | defer res.deinit(); 88 | 89 | switch (try child.wait()) { 90 | .Exited => |code| if (code != 0) { 91 | log.err("{s} exited with code {}", .{ child.argv, code }); 92 | return error.NixError; 93 | }, 94 | .Signal => |signal| { 95 | log.err("{s} terminated with signal {}", .{ child.argv, signal }); 96 | return error.NixError; 97 | }, 98 | .Stopped, .Unknown => { 99 | log.err("{s} finished unsuccessfully", .{child.argv}); 100 | return error.NixError; 101 | }, 102 | } 103 | 104 | assert(res.value.hash.len != 0); 105 | log.debug("hash for \"{s}\" is {s}", .{ dep.url, res.value.hash }); 106 | 107 | dep.nix_hash = try alloc.dupe(u8, res.value.hash); 108 | dep.done = true; 109 | 110 | const path = try fmt.allocPrint(alloc, "{s}" ++ fs.path.sep_str ++ "build.zig.zon", .{res.value.storePath}); 111 | defer alloc.free(path); 112 | 113 | const file = fs.openFileAbsolute(path, .{}) catch |err| switch (err) { 114 | error.FileNotFound => continue, 115 | else => return err, 116 | }; 117 | defer file.close(); 118 | 119 | try parse(alloc, deps, file); 120 | if (deps.count() > len_before) { 121 | done = false; 122 | } 123 | } 124 | 125 | workers.clearRetainingCapacity(); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/parse.zig: -------------------------------------------------------------------------------- 1 | const builtin = @import("builtin"); 2 | const std = @import("std"); 3 | const assert = std.debug.assert; 4 | const Allocator = std.mem.Allocator; 5 | const Ast = std.zig.Ast; 6 | const File = std.fs.File; 7 | const Index = std.zig.Ast.Node.Index; 8 | const StringHashMap = std.StringHashMap; 9 | const mem = std.mem; 10 | const string_literal = std.zig.string_literal; 11 | 12 | const Dependency = @import("Dependency.zig"); 13 | 14 | const zig_legacy_version = (std.SemanticVersion{ 15 | .major = builtin.zig_version.major, 16 | .minor = builtin.zig_version.minor, 17 | .patch = builtin.zig_version.patch, 18 | }).order(.{ 19 | .major = 0, 20 | .minor = 15, 21 | .patch = 0, 22 | }) == .lt; 23 | 24 | pub fn parse(alloc: Allocator, deps: *StringHashMap(Dependency), file: File) !void { 25 | const content = try alloc.allocSentinel(u8, try file.getEndPos(), 0); 26 | defer alloc.free(content); 27 | 28 | _ = try file.reader().readAll(content); 29 | 30 | var ast = try Ast.parse(alloc, content, .zon); 31 | defer ast.deinit(alloc); 32 | 33 | var root_buf: [2]Index = undefined; 34 | const root_init = ast.fullStructInit(&root_buf, @field(ast.nodes.items(.data)[0], if (zig_legacy_version) "lhs" else "node")) orelse { 35 | return error.ParseError; 36 | }; 37 | 38 | for (root_init.ast.fields) |field_idx| { 39 | const field_name = try parseFieldName(alloc, ast, field_idx); 40 | defer alloc.free(field_name); 41 | 42 | if (!mem.eql(u8, field_name, "dependencies")) { 43 | continue; 44 | } 45 | 46 | var deps_buf: [2]Index = undefined; 47 | const deps_init = ast.fullStructInit(&deps_buf, field_idx) orelse { 48 | return error.ParseError; 49 | }; 50 | 51 | for (deps_init.ast.fields) |dep_idx| { 52 | var dep: Dependency = .{ 53 | .url = undefined, 54 | .rev = null, 55 | .nix_hash = null, 56 | .done = false, 57 | }; 58 | 59 | var hash: ?[]const u8 = null; 60 | var url: ?[]const u8 = null; 61 | 62 | var dep_buf: [2]Index = undefined; 63 | const dep_init = ast.fullStructInit(&dep_buf, dep_idx) orelse { 64 | std.log.warn("failed to get dependencies", .{}); 65 | continue; 66 | }; 67 | 68 | for (dep_init.ast.fields) |dep_field_idx| { 69 | const name = try parseFieldName(alloc, ast, dep_field_idx); 70 | defer alloc.free(name); 71 | 72 | if (mem.eql(u8, name, "url")) { 73 | const parsed_url = try parseString(alloc, ast, dep_field_idx); 74 | if (std.mem.startsWith(u8, parsed_url, "https://")) { 75 | url = parsed_url; 76 | } else if (std.mem.startsWith(u8, parsed_url, "git+https://")) { 77 | defer alloc.free(parsed_url); 78 | 79 | const url_end = std.mem.indexOf(u8, parsed_url[0..], "#").?; 80 | const raw_url = parsed_url[4..url_end]; 81 | const hash_start = url_end + 1; // +1 to skip the '#' 82 | const git_hash = parsed_url[hash_start..]; 83 | url = try alloc.dupe(u8, raw_url); 84 | dep.rev = try alloc.dupe(u8, git_hash); 85 | } 86 | } else if (mem.eql(u8, name, "hash")) { 87 | hash = try parseString(alloc, ast, dep_field_idx); 88 | } 89 | } 90 | 91 | if (url != null and hash != null) { 92 | dep.url = url.?; 93 | _ = try deps.getOrPutValue(hash.?, dep); 94 | } else { 95 | return error.parseError; 96 | } 97 | } 98 | } 99 | } 100 | 101 | fn parseFieldName(alloc: Allocator, ast: Ast, idx: Index) ![]const u8 { 102 | const name = ast.tokenSlice(ast.firstToken(idx) - 2); 103 | return if (name[0] == '@') string_literal.parseAlloc(alloc, name[1..]) else alloc.dupe(u8, name); 104 | } 105 | 106 | fn parseString(alloc: Allocator, ast: Ast, idx: Index) ![]const u8 { 107 | return string_literal.parseAlloc(alloc, ast.tokenSlice(ast.nodes.items(.main_token)[if (zig_legacy_version) idx else @intFromEnum(idx)])); 108 | } 109 | 110 | test parse { 111 | const fs = std.fs; 112 | const heap = std.heap; 113 | const testing = std.testing; 114 | 115 | var arena = heap.ArenaAllocator.init(testing.allocator); 116 | defer arena.deinit(); 117 | const alloc = arena.allocator(); 118 | 119 | var deps = StringHashMap(Dependency).init(alloc); 120 | const basic = try fs.cwd().openFile("fixtures/basic.zon", .{}); 121 | defer basic.close(); 122 | try parse(alloc, &deps, basic); 123 | 124 | try testing.expectEqual(deps.count(), 6); 125 | try testing.expectEqualStrings(deps.get("122048992ca58a78318b6eba4f65c692564be5af3b30fbef50cd4abeda981b2e7fa5").?.url, "https://github.com/ziglibs/known-folders/archive/fa75e1bc672952efa0cf06160bbd942b47f6d59b.tar.gz"); 126 | try testing.expectEqualStrings(deps.get("122089a8247a693cad53beb161bde6c30f71376cd4298798d45b32740c3581405864").?.url, "https://github.com/ziglibs/diffz/archive/90353d401c59e2ca5ed0abe5444c29ad3d7489aa.tar.gz"); 127 | try testing.expectEqualStrings(deps.get("1220363c7e27b2d3f39de6ff6e90f9537a0634199860fea237a55ddb1e1717f5d6a5").?.url, "https://gist.github.com/antlilja/8372900fcc09e38d7b0b6bbaddad3904/archive/6c3321e0969ff2463f8335da5601986cf2108690.tar.gz"); 128 | const ziggy = deps.get("1220115ff095a3c970cc90fce115294ba67d6fbc4927472dc856abc51e2a1a9364d7").?; 129 | try testing.expectEqualStrings(ziggy.url, "https://github.com/kristoff-it/ziggy"); 130 | try testing.expectEqualStrings(ziggy.rev.?, "c66f47bc632c66668d61fa06eda112b41d6e5130"); 131 | const vaxis = deps.get("1220feaa655e14cbb4baf59fe746f09a17fc6949be46ad64dd5044982f4fc1bb57c7").?; 132 | try testing.expectEqualStrings(vaxis.url, "https://github.com/rockorager/libvaxis"); 133 | try testing.expectEqualStrings(vaxis.rev.?, "1fd920a7aea1bb040c7c028f4bbf0af2ea58e1d1"); 134 | const zig_tracy = deps.get("122094fc39764bd527269d3721f52fc3b8cbb72bc4cdbd3345cbc2cd941936f3d185").?; 135 | try testing.expectEqualStrings(zig_tracy.url, "https://github.com/vancluever/zig-tracy?ref=fix-callstack"); 136 | try testing.expectEqualStrings(zig_tracy.rev.?, "6e123ee26032e49a1a0039524ddf7970692931d9"); 137 | } 138 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | --------------------------------------------------------------------------------