-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
137 lines (124 loc) · 4.38 KB
/
flake.nix
File metadata and controls
137 lines (124 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
{
description = "A flake for Zig";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
# For upgrade use `nix flake update zig zigscient-src`
zig = {
url = "github:mitchellh/zig-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
zls-src = {
url = "github:zigtools/zls/0.15.0";
flake = false;
};
};
outputs =
inputs@{ nixpkgs
, flake-utils
, ...
}:
let
zlsBinName = "zls";
overlays = [
(
_final: prev: with prev; rec {
zig = inputs.zig.packages.${system}."0.15.1";
zls = stdenvNoCC.mkDerivation {
pname = "zls";
version = "${inputs.zls-src.shortRev}-${inputs.zls-src.lastModifiedDate}";
meta.mainProgram = "zls";
src = "${inputs.zls-src}";
nativeBuildInputs = [ zig ];
phases = [
"unpackPhase"
"buildPhase"
"checkPhase"
];
buildPhase = ''
mkdir -p .cache
zig build install --cache-dir $(pwd)/.zig-cache --global-cache-dir $(pwd)/.cache -Dcpu=baseline -Doptimize=ReleaseSafe --prefix $out
'';
checkPhase = ''
zig build test --cache-dir $(pwd)/.zig-cache --global-cache-dir $(pwd)/.cache -Dcpu=baseline
'';
};
}
)
];
in
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit overlays system; };
inherit (pkgs) zig;
inherit (pkgs) zls;
buildInputs =
with pkgs;
[
zig
zls
xmlstarlet
coreutils
bash
git
]
++ lib.optionals stdenv.isDarwin [
apple-sdk_14
];
baseShellHook = ''
export FLAKE_ROOT="$(nix flake metadata | grep 'Resolved URL' | awk '{print $3}' | sed 's/^path://' | sed 's/^git+file:\/\///')"
'';
in
{
# run: `nix develop`
devShells = {
default = pkgs.mkShell {
inherit buildInputs;
shellHook =
baseShellHook
+ ''
export HISTFILE="$FLAKE_ROOT/.nix_bash_history"
sed -i 's/^: [0-9]\{10\}:[0-9];//' $HISTFILE > /dev/null 2>&1
sed -i '/^#/d' $HISTFILE > /dev/null 2>&1
export PROJECT_ROOT="$FLAKE_ROOT"
''
+ pkgs.lib.optionalAttrs pkgs.stdenv.isDarwin ''
export NIX_CFLAGS_COMPILE="-iframework $SDKROOT/System/Library/Frameworks -isystem $SDKROOT/usr/include $NIX_CFLAGS_COMPILE"
export NIX_LDFLAGS="-L$SDKROOT/usr/lib $NIX_LDFLAGS"
'';
};
# Update IDEA paths. Use only if nix installed in whole system.
# run: `nix develop \#idea`
idea = pkgs.mkShell {
inherit buildInputs;
shellHook = pkgs.lib.concatLines [
baseShellHook
''
cd "$FLAKE_ROOT"
if [[ -d "$HOME/Library/Application Support/JetBrains" ]]; then
JETBRAINS_PATH="$HOME/Library/Application Support/JetBrains"
else
JETBRAINS_PATH="$HOME/.config/JetBrains"
fi
# Find CLion latest path
IDE_PATH=$(ls -d "$JETBRAINS_PATH"/* | grep -E 'CLion[0-9]+\.[0-9]+')
echo "IDE_PATH: $IDE_PATH"
if [[ -f ".idea/zigbrains.xml" ]]; then
xmlstarlet ed -L -u '//project/component[@name="ZLSSettings"]/option[@name="zlsPath"]/@value' -v '${zls}/bin/${zlsBinName}' ".idea/zigbrains.xml"
xmlstarlet ed -L -u '//project/component[@name="ZigProjectSettings"]/option[@name="toolchainPath"]/@value' -v '${zig}/bin' ".idea/zigbrains.xml"
xmlstarlet ed -L -u '//project/component[@name="ZigProjectSettings"]/option[@name="explicitPathToStd"]/@value' -v '${zig}/lib/std' ".idea/zigbrains.xml"
else
echo "Failed replace paths. File '.idea/zigbrains.xml' not found"
fi
exit 0
''
];
};
};
}
);
}