Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
140 lines (128 loc) · 4.29 KB
/
Copy pathflake.nix
File metadata and controls
140 lines (128 loc) · 4.29 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
138
139
140
{
description = "Auto-updating VS Code Nix flake with Microsoft's official binaries";
nixConfig = {
extra-substituters = [ "https://cache.garnix.io" ];
extra-trusted-public-keys = [
"cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g="
];
};
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
{
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};
inherit (pkgs) stdenv;
vscode = pkgs.callPackage ./package.nix { };
# Helper function to create VS Code with extensions, optional settings, and optional keybindings
vscodeWithExtensions =
extensions: settings:
let
settingsArgs =
if settings == null then
{
settings = null;
keybindings = null;
}
else if builtins.isAttrs settings && (settings ? settings || settings ? keybindings) then
{
settings = settings.settings or null;
keybindings = settings.keybindings or null;
}
else
{
settings = settings;
keybindings = null;
};
in
pkgs.callPackage ./package.nix {
inherit extensions;
userSettings = settingsArgs.settings;
userKeybindings = settingsArgs.keybindings;
};
in
{
packages = {
inherit vscode;
default = vscode;
};
apps = {
vscode = {
type = "app";
program = "${vscode}/bin/code";
meta.description = "Visual Studio Code - Microsoft's official build";
};
default = self.apps.${system}.vscode;
};
# Export lib with vscodeWithExtensions function
lib = {
inherit vscodeWithExtensions;
};
formatter = pkgs.nixpkgs-fmt;
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
nixpkgs-fmt
nix-prefetch
gh
jq
];
};
# Checks for `nix flake check`
checks =
let
# Helper to find the wrapper script path
# On Linux, wrapGAppsHook3 wraps to .code-wrapped; on macOS it's just code
findWrapper = pkg: if stdenv.isDarwin then "${pkg}/bin/code" else "${pkg}/bin/.code-wrapped";
in
{
# Basic build check - ensures the default package builds
build = vscode;
# Wrapper syntax check - validates bash syntax of the wrapper script
wrapper-syntax = pkgs.runCommand "vscode-wrapper-syntax-check" { } ''
${pkgs.bash}/bin/bash -n ${findWrapper vscode}
echo "Wrapper script syntax OK" > $out
'';
# Build with sample extensions list
with-extensions =
let
vscodeWithExt = vscodeWithExtensions [ "jnoortheen.nix-ide" ] null;
in
pkgs.runCommand "vscode-with-extensions-check" { } ''
# Verify the package built successfully
test -x ${vscodeWithExt}/bin/code
# Verify wrapper syntax
${pkgs.bash}/bin/bash -n ${findWrapper vscodeWithExt}
echo "Build with extensions OK" > $out
'';
# Build with sample settings
with-settings =
let
vscodeWithSettings = vscodeWithExtensions [ ] { "editor.fontSize" = 14; };
in
pkgs.runCommand "vscode-with-settings-check" { } ''
# Verify the package built successfully
test -x ${vscodeWithSettings}/bin/code
# Verify wrapper syntax
${pkgs.bash}/bin/bash -n ${findWrapper vscodeWithSettings}
echo "Build with settings OK" > $out
'';
};
}
)
// {
overlays.default = final: prev: {
vscode-nix = self.packages.${prev.system}.vscode;
};
};
}