Skip to content

Commit be0d05d

Browse files
committed
Make it possible to customize user list
1 parent a04361c commit be0d05d

File tree

4 files changed

+39
-24
lines changed

4 files changed

+39
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use:
5454
{
5555
services.vscode-server = {
5656
enable = true;
57-
enableForAllUsers = true;
57+
enableForUsers.enable = true;
5858
};
5959
}
6060
```

modules/vscode-server/default.nix

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@ import ./module.nix (
1212
wantedBy = [ "default.target" ];
1313
};
1414
}
15-
(lib.mkIf cfg.enableForAllUsers {
15+
(lib.mkIf cfg.enableForUsers.enable {
1616
systemd.tmpfiles.settings =
1717
let
18-
forEachUser = ({ path, file }: lib.attrsets.mapAttrs'
19-
(username: userOptions:
20-
{
21-
# Create the directory so that it has the appropriate permissions if it doesn't already exist
22-
# Otherwise the directive below creating the symlink would have that owned by root
23-
name = "${userOptions.home}/${path}";
24-
value = file username;
25-
})
26-
(lib.attrsets.filterAttrs (username: userOptions: userOptions.isNormalUser) config.users.users));
18+
forEachUser = ({ path, file }: builtins.listToAttrs
19+
(builtins.map
20+
(username:
21+
{
22+
# Create the directory so that it has the appropriate permissions if it doesn't already exist
23+
# Otherwise the directive below creating the symlink would have that owned by root
24+
name = let s = "${config.users.users.${username}.home}/${path}"; in builtins.trace s s;
25+
value = file username;
26+
})
27+
cfg.enableForUsers.users));
2728
homeDirectory = (path: forEachUser {
2829
inherit path;
2930
file = (username: {

modules/vscode-server/home.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import ./module.nix (
1919
};
2020

2121
assertions = [{
22-
assertion = !cfg.enableForAllUsers;
23-
message = "enableForAllUsers=true doesn't make sense when using nixos-vscode-server as a home-manager module";
22+
assertion = !cfg.enableForUsers.enable;
23+
message = "enableForUsers.enable=true doesn't make sense when using nixos-vscode-server as a home-manager module";
2424
}];
2525
}
2626
)

modules/vscode-server/module.nix

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ moduleConfig: {
66
}: {
77
options.services.vscode-server = let
88
inherit (lib) mkEnableOption mkOption;
9-
inherit (lib.types) lines listOf nullOr package str bool;
9+
inherit (lib.types) lines listOf nullOr package str bool passwdEntry;
1010
in {
1111
enable = mkEnableOption "VS Code Server autofix";
1212

@@ -50,17 +50,31 @@ moduleConfig: {
5050
'';
5151
};
5252

53-
enableForAllUsers = mkOption {
54-
type = bool;
55-
default = false;
56-
example = true;
57-
description = ''
58-
Whether to enable the VS Code Server auto-fix service for all users.
53+
enableForUsers = {
54+
enable = mkOption {
55+
type = bool;
56+
default = false;
57+
example = true;
58+
description = ''
59+
Whether to enable the VS Code Server auto-fix service for each user.
5960
60-
This only makes sense if auto-fix-vscode-server is installed as a NixOS module.
61+
This only makes sense if auto-fix-vscode-server is installed as a NixOS module.
6162
62-
This automatically sets up the service's symlinks for systemd in each users' home directory.
63-
'';
63+
This automatically sets up the service's symlinks for systemd in each users' home directory.
64+
'';
65+
};
66+
67+
users = mkOption {
68+
type = listOf (passwdEntry str);
69+
default = builtins.attrNames (lib.attrsets.filterAttrs (username: userOptions: userOptions.isNormalUser) config.users.users);
70+
defaultText = "builtins.attrNames (lib.filterAttrs (_: userOptions: userOptions.isNormalUser) config.users.users)";
71+
example = [ "alice" "bob" ];
72+
description = ''
73+
List of users to enable the VS Code Server auto-fix service for.
74+
75+
By default this will fallback to the list of "normal" users.
76+
'';
77+
};
6478
};
6579
};
6680

@@ -69,7 +83,7 @@ moduleConfig: {
6983
cfg = config.services.vscode-server;
7084
auto-fix-vscode-server =
7185
pkgs.callPackage ../../pkgs/auto-fix-vscode-server.nix
72-
(removeAttrs cfg [ "enable" "enableForAllUsers" ]);
86+
(removeAttrs cfg [ "enable" "enableForUsers" ]);
7387
in
7488
mkIf cfg.enable (mkMerge [
7589
{

0 commit comments

Comments
 (0)