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.
This commit is contained in:
LeRoyce Pearson 2022-07-18 14:35:00 -06:00
parent ac8600cd8c
commit 542f49087e
2 changed files with 28 additions and 4 deletions

View File

@ -42,7 +42,9 @@ pub fn build(b: *std.build.Builder) !void {
b.option(bool, "enable_tracy_callstack", "Enable callstack graphs.") orelse false, 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) { if (enable_tracy) {
const client_cpp = "src/tracy/TracyClient.cpp"; const client_cpp = "src/tracy/TracyClient.cpp";

View File

@ -12,21 +12,43 @@
outputs = {self, nixpkgs, zig-overlay, gitignore }: outputs = {self, nixpkgs, zig-overlay, gitignore }:
let let
inherit (gitignore.lib) gitignoreSource; 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"; name = "zls";
version = "master"; version = "master";
src = gitignoreSource ./.; src = gitignoreSource ./.;
nativeBuildInputs = [ nativeBuildInputs = [
zig-overlay.packages.${system}.master.latest zig-overlay.packages.${system}.master.latest
]; ];
buildInputs = [
known-folders
];
dontConfigure = true; dontConfigure = true;
dontInstall = true; dontInstall = true;
buildPhase = '' buildPhase = ''
mkdir -p $out 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"; XDG_CACHE_HOME = ".cache";
}); }));
in { in {
packages = rec { packages = rec {
x86_64-linux.zls = zls-derivation-fn "x86_64-linux"; x86_64-linux.zls = zls-derivation-fn "x86_64-linux";