-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
default.nix
89 lines (78 loc) · 2.33 KB
/
default.nix
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
{
config,
fenix,
nixpkgs,
...
}: let
pkg = nixpkgs.vscode;
extensionsDir = "/data/editor/extensions";
userDataDir = "/data/editor/data";
bin =
nixpkgs.lib.pipe
[
["${pkg}/bin/code"] # unfree
["--extensions-dir" extensionsDir]
["--user-data-dir" userDataDir]
]
[
(nixpkgs.lib.flatten)
(nixpkgs.lib.concatStringsSep " ")
];
extensions = import ./extensions.nix {inherit fenix nixpkgs;};
settings = import ./settings.nix {inherit config fenix nixpkgs;};
settingsJson =
nixpkgs.runCommand "settings.json" {
passAsFile = ["settings"];
settings = builtins.toJSON settings;
}
"cp $settingsPath $out";
in {
environment.variables.EDITOR = "${bin} --wait";
environment.systemPackages = [
pkg
(nixpkgs.writeShellScriptBin "editor" ''
exec ${bin} "$@"
'')
];
home-manager.users.${config.wellKnown.username} = {
home.file.".config/rustfmt/rustfmt.toml".source = ./rustfmt.toml;
};
programs.git.config = {
diff.tool = "editor";
difftool.editor.cmd = "${bin} --diff $LOCAL $REMOTE --wait";
merge.tool = "editor";
mergetool.editor.cmd = "${bin} --wait $MERGED";
};
systemd.services."machine-editor-setup" = {
script = toString (nixpkgs.substitute {
src = nixpkgs.writeShellScript "machine-editor-setup.sh" ''
set -eux
rm -rf "@userDataDir@"
rm -rf "@extensionsDir@"
mkdir -p "@userDataDir@/User"
mkdir -p "@extensionsDir@"
cp --dereference --no-preserve=mode,ownership \
"@settings@" "@userDataDir@/User/settings.json"
cp --dereference --no-preserve=mode,ownership -rT \
"@extensions@/share/vscode/extensions/" "@extensionsDir@"
'';
substitutions = nixpkgs.lib.concatLists [
["--replace-fail" "@extensions@" extensions]
["--replace-fail" "@extensionsDir@" extensionsDir]
["--replace-fail" "@settings@" settingsJson]
["--replace-fail" "@userDataDir@" userDataDir]
];
isExecutable = true;
});
serviceConfig = {
Group = config.users.users.${config.wellKnown.username}.group;
RemainAfterExit = true;
Type = "oneshot";
User = config.wellKnown.username;
};
unitConfig = {
After = ["multi-user.target"];
};
requiredBy = ["graphical.target"];
};
}