Skip to content

Commit 8db883d

Browse files
committed
Add nix flake for building extension
1 parent b49e02b commit 8db883d

7 files changed

+765
-5
lines changed

.envrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ dist
33
node_modules
44
.vscode-test/
55
*.vsix
6+
.direnv/
7+
result/

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ Allows user to specify the denied commands using glob syntax, eg:
8181

8282
Defaults to `[]` (doesn't deny anything).
8383

84+
## Building
85+
86+
### Nix
87+
88+
The extension can be built using the `flake.nix` file using the following command:
89+
90+
```bash
91+
nix build
92+
```
93+
94+
The resulting `.vsix` file will be placed in the `result/` folder.
95+
8496
## Troubleshooting
8597

8698
## Known issues

flake.lock

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
description = "A Nix-flake-based development environment for command-server";
3+
4+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
5+
6+
outputs = { self, nixpkgs }:
7+
let
8+
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
9+
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
10+
pkgs = import nixpkgs { inherit system; };
11+
});
12+
in
13+
{
14+
packages = forEachSupportedSystem
15+
({ pkgs, ... }:
16+
let
17+
attrs = with builtins; fromJSON (readFile ./package.json);
18+
name = attrs.name;
19+
version = attrs.version;
20+
in
21+
{
22+
default = pkgs.mkYarnPackage {
23+
pname = "${name}-${version}";
24+
src = ./.;
25+
26+
buildPhase = ''
27+
# yarn tries to create a .yarn file in $HOME. There's probably a
28+
# better way to fix this but setting HOME to cwd works for now.
29+
export HOME="."
30+
yarn --offline run compile
31+
# non-existent symlink errors during packaging
32+
rm ./deps/command-server/command-server
33+
# need node_modules for vsce, so don't use symlink
34+
rm ./deps/command-server/node_modules
35+
cp -R ./node_modules ./deps/command-server
36+
pushd ./deps/command-server
37+
echo y | yarn --offline vsce package --yarn -o ./$pname.vsix
38+
popd
39+
'';
40+
41+
installPhase = ''
42+
mkdir $out
43+
mv ./deps/command-server/$pname.vsix $out;
44+
'';
45+
46+
distPhase = "true";
47+
48+
};
49+
});
50+
51+
devShells = forEachSupportedSystem
52+
({ pkgs }: {
53+
default = pkgs.mkShell
54+
{
55+
packages = with pkgs;
56+
[ yarn typescript ];
57+
};
58+
});
59+
};
60+
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
"glob": "^7.1.6",
130130
"mocha": "^8.1.3",
131131
"typescript": "^4.1.2",
132+
"vsce": "^2.15.0",
132133
"vscode-test": "^1.4.1"
133134
},
134135
"dependencies": {

0 commit comments

Comments
 (0)