-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
233 lines (200 loc) · 7.37 KB
/
flake.nix
File metadata and controls
233 lines (200 loc) · 7.37 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
{
description = "Opiniated Flake for Developing R Software--for ISCAM";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; # Unstable to get the latest version of R + packages. Pretty safe.
flake-utils.url = "github:numtide/flake-utils";
nix-vscode-extensions = {
url = "github:nix-community/nix-vscode-extensions";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
};
outputs =
{
self,
nixpkgs,
flake-utils,
nix-vscode-extensions,
}:
flake-utils.lib.eachSystem [ "x86_64-linux" ] (
system:
let
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
overlays = [ nix-vscode-extensions.overlays.default ];
};
# List the packages you wish to have installed instead of installing packages interactively
# Useful links:
# https://search.nixos.org/packages?channel=unstable&from=0&size=50&sort=relevance&type=packages&query=rPackages.
# https://nixos.wiki/wiki/R#Install_an_R-package_from_GitHub
rPkgs = with pkgs.rPackages; [
# ! NOTE: ADD YOUR R PACKAGES HERE
devtools
roxygen2
testthat
usethis
pkgdown
languageserver
lintr
];
rWithPkgs = pkgs.rWrapper.override {
packages = rPkgs;
};
# Minimal open-vsx extensions
# Note that positron-bin will probably lag behind stable release, so extensions which target the latest version of code-oss may not work.
# e.g. on 20250817, vscode-pull-request-github-116.1 reports that it "is not compatible with Code 1.102.0. Extension requires: ^1.103.0."
# https://nix-community.github.io/nix4vscode/
extensions = with pkgs.open-vsx; [
# Default Positron extensions
github.vscode-pull-request-github
posit.air-vscode
quarto.quarto
# ! NOTE: ADD YOUR OPEN-VSX EXTENSIONS HERE
eamodio.gitlens
usernamehw.errorlens
edwinhuish.better-comments-next
tomoki1207.pdf
tombi-toml.tombi
oderwat.indent-rainbow
robole.marky-stats
# Catppuccin theme extensions
catppuccin.catppuccin-vsc
catppuccin.catppuccin-vsc-icons
];
# Declerative Positron settings.json
# Clear settings by running: $ rm ~/.config/Positron/User/settings.json
settingsJson = pkgs.writeText "settings.json" (
builtins.toJSON {
"workbench.keybindings.rstudioKeybindings" = true;
"workbench.colorTheme" = "Catppuccin Mocha";
"workbench.iconTheme" = "catppuccin-mocha";
"workbench.list.smoothScrolling" = true;
"catppuccin.accentColor" = "pink";
"catppuccin.colorOverrides" = {
"mocha" = {
"base" = "#000000";
"mantle" = "#010101";
"crust" = "#020202";
};
};
"catppuccin.customUIColors" = {
"mocha" = {
"statusBar.foreground" = "accent";
};
};
"git.autofetch" = true;
"git.confirmSync" = false;
"editor.formatOnSave" = true;
"editor.fontFamily" = "JetBrainsMono Nerd Font";
"editor.fontLigatures" = true;
"editor.semanticHighlighting.enabled" = true;
"editor.pasteAs.preferences" = [
"typst.link"
"markdown.link"
];
"terminal.integrated.fontFamily" = "IosevkaTerm Nerd Font";
"positron.plots.darkFilter" = "off";
"[r]" = {
"editor.formatOnSave" = true;
"editor.defaultFormatter" = "Posit.air-vscode";
};
"[quarto]" = {
"editor.formatOnSave" = true;
"editor.defaultFormatter" = "quarto.quarto";
};
}
);
# Symlink farm of extensions (read-only source)
extensionsRO = pkgs.buildEnv {
name = "positron-extensions";
paths = extensions;
pathsToLink = [ "/share/vscode/extensions" ];
};
# FHS environment for Positron
positronFHS = pkgs.buildFHSEnv {
name = "positron-fhs";
targetPkgs =
pkgs: with pkgs; [
# Core Positron and R
positron-bin
R
air-formatter
# Patched fonts
nerd-fonts.iosevka-term
nerd-fonts.jetbrains-mono
# Basic system libraries for dynamic linking
glibc
gcc-unwrapped.lib
stdenv.cc.cc.lib
zlib
git
gcc
gfortran
pkg-config
];
runScript = pkgs.writeScript "positron-run" ''
#!/bin/bash
set -euo pipefail
EXT_BASE="''${XDG_CACHE_HOME:-$HOME/.cache}"
EXT_DST="$EXT_BASE/positron/extensions"
SRC="${extensionsRO}/share/vscode/extensions"
CONFIG_BASE="''${XDG_CONFIG_HOME:-$HOME/.config}"
APP_ID="Positron"
SETTINGS_DIR="$CONFIG_BASE/$APP_ID/User"
SETTINGS_FILE="$SETTINGS_DIR/settings.json"
mkdir -p "$EXT_DST" "$SETTINGS_DIR"
# rm ~/.config/Positron/User/settings.json
# Copy settings.json if it doesn't exist
[ ! -f "$SETTINGS_FILE" ] && cp "${settingsJson}" "$SETTINGS_FILE"
# Sync extensions (copy if not exists)
for s in "$SRC"/*; do
[ -d "$s" ] || continue
bn="$(basename "$s")"
[ -d "$EXT_DST/$bn" ] || cp -r "$s" "$EXT_DST/$bn"
done
# Set up environment
export R_HOME='${pkgs.R}/lib/R'
export R_LIBS_USER='${rWithPkgs}/lib/R/library'
export PATH="${pkgs.R}/bin:${rWithPkgs}/bin:${pkgs.air-formatter}/bin:$PATH"
# Run Positron
exec positron --extensions-dir "$EXT_DST" "$@"
'';
};
positronWrapper = pkgs.writeShellScriptBin "positron-with-extensions" ''
exec ${positronFHS}/bin/positron-fhs "$@"
'';
rstudioWrapper = pkgs.writeShellScriptBin "rstudio-with-r" ''
export R_HOME='${pkgs.R}/lib/R'
export R_LIBS_USER='${rWithPkgs}/lib/R/library'
export PATH="${pkgs.R}/bin:${rWithPkgs}/bin:${pkgs.air-formatter}/bin:$PATH"
exec ${pkgs.rstudio}/bin/rstudio "$@"
'';
in
{
packages.positron = positronWrapper;
packages.rstudio = rstudioWrapper;
apps.positron = {
type = "app";
program = "${positronWrapper}/bin/positron-with-extensions";
meta = {
description = "Positron IDE with R environment and extensions";
platforms = [ "x86_64-linux" ];
};
};
apps.rstudio = {
type = "app";
program = "${rstudioWrapper}/bin/rstudio-with-r";
meta = {
description = "RStudio IDE with R environment";
platforms = [ "x86_64-linux" ];
};
};
devShells.default = pkgs.mkShell {
shellHook = ''
echo "Use: nix run .#positron or nix run .#rstudio"
'';
};
}
);
}