From 542f49087e79cdd180ae483743b2dade3c7b314c Mon Sep 17 00:00:00 2001 From: LeRoyce Pearson Date: Mon, 18 Jul 2022 14:35:00 -0600 Subject: [PATCH] Add known-folders as a flake input This allows the flake to work without passing in `?submodules=1`, which makes it easy to include in other flakes. This commit also makes it possible to override the path to the `known-folders` package like so: ``` zig build -Dknown-folders=/path/to/known-folders.zig ``` This allows `flake.nix` to pass in the nix store path. --- build.zig | 4 +++- flake.nix | 28 +++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/build.zig b/build.zig index 99eeb90..7872c74 100644 --- a/build.zig +++ b/build.zig @@ -42,7 +42,9 @@ pub fn build(b: *std.build.Builder) !void { b.option(bool, "enable_tracy_callstack", "Enable callstack graphs.") orelse false, ); - exe.addPackage(.{ .name = "known-folders", .source = .{ .path = "src/known-folders/known-folders.zig" } }); + const KNOWN_FOLDERS_DEFAULT_PATH = "src/known-folders/known-folders.zig"; + const known_folders_path = b.option([]const u8, "known-folders", "Path to known-folders package (default: " ++ KNOWN_FOLDERS_DEFAULT_PATH ++ ")") orelse KNOWN_FOLDERS_DEFAULT_PATH; + exe.addPackage(.{ .name = "known-folders", .source = .{ .path = known_folders_path } }); if (enable_tracy) { const client_cpp = "src/tracy/TracyClient.cpp"; diff --git a/flake.nix b/flake.nix index e8eb6c9..39a5075 100644 --- a/flake.nix +++ b/flake.nix @@ -12,21 +12,43 @@ outputs = {self, nixpkgs, zig-overlay, gitignore }: let inherit (gitignore.lib) gitignoreSource; - zls-derivation-fn = (system: nixpkgs.legacyPackages.${system}.stdenvNoCC.mkDerivation { + + known-folders-fetch = (system: nixpkgs.legacyPackages.${system}.stdenvNoCC.mkDerivation { + name = "known-folders"; + src = nixpkgs.legacyPackages.${system}.fetchFromGitHub { + owner = "ziglibs"; + repo = "known-folders"; + rev = "9db1b99219c767d5e24994b1525273fe4031e464"; + sha256 = "sha256-eqaZxIax8C75L2UwDbVKSUZ7iThm/iWblfoaTfPyHLM="; + }; + dontConfigure = true; + dontInstall = true; + buildPhase = '' + mkdir -p $out + cp known-folders.zig $out + ''; + }); + + zls-derivation-fn = (system: nixpkgs.legacyPackages.${system}.stdenvNoCC.mkDerivation + (let known-folders = known-folders-fetch system; + in { name = "zls"; version = "master"; src = gitignoreSource ./.; nativeBuildInputs = [ zig-overlay.packages.${system}.master.latest ]; + buildInputs = [ + known-folders + ]; dontConfigure = true; dontInstall = true; buildPhase = '' mkdir -p $out - zig build install -Drelease-safe=true -Ddata_version=master --prefix $out + zig build install -Drelease-safe=true -Ddata_version=master -Dknown-folders=${known-folders}/known-folders.zig --prefix $out ''; XDG_CACHE_HOME = ".cache"; - }); + })); in { packages = rec { x86_64-linux.zls = zls-derivation-fn "x86_64-linux";