Skip to content

Commit

Permalink
Make it possible to customize user list
Browse files Browse the repository at this point in the history
  • Loading branch information
Ten0 committed Oct 19, 2024
1 parent a04361c commit be0d05d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use:
{
services.vscode-server = {
enable = true;
enableForAllUsers = true;
enableForUsers.enable = true;
};
}
```
Expand Down
21 changes: 11 additions & 10 deletions modules/vscode-server/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ import ./module.nix (
wantedBy = [ "default.target" ];
};
}
(lib.mkIf cfg.enableForAllUsers {
(lib.mkIf cfg.enableForUsers.enable {
systemd.tmpfiles.settings =
let
forEachUser = ({ path, file }: lib.attrsets.mapAttrs'
(username: userOptions:
{
# Create the directory so that it has the appropriate permissions if it doesn't already exist
# Otherwise the directive below creating the symlink would have that owned by root
name = "${userOptions.home}/${path}";
value = file username;
})
(lib.attrsets.filterAttrs (username: userOptions: userOptions.isNormalUser) config.users.users));
forEachUser = ({ path, file }: builtins.listToAttrs
(builtins.map
(username:
{
# Create the directory so that it has the appropriate permissions if it doesn't already exist
# Otherwise the directive below creating the symlink would have that owned by root
name = let s = "${config.users.users.${username}.home}/${path}"; in builtins.trace s s;
value = file username;
})
cfg.enableForUsers.users));
homeDirectory = (path: forEachUser {
inherit path;
file = (username: {
Expand Down
4 changes: 2 additions & 2 deletions modules/vscode-server/home.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import ./module.nix (
};

assertions = [{
assertion = !cfg.enableForAllUsers;
message = "enableForAllUsers=true doesn't make sense when using nixos-vscode-server as a home-manager module";
assertion = !cfg.enableForUsers.enable;
message = "enableForUsers.enable=true doesn't make sense when using nixos-vscode-server as a home-manager module";
}];
}
)
36 changes: 25 additions & 11 deletions modules/vscode-server/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ moduleConfig: {
}: {
options.services.vscode-server = let
inherit (lib) mkEnableOption mkOption;
inherit (lib.types) lines listOf nullOr package str bool;
inherit (lib.types) lines listOf nullOr package str bool passwdEntry;
in {
enable = mkEnableOption "VS Code Server autofix";

Expand Down Expand Up @@ -50,17 +50,31 @@ moduleConfig: {
'';
};

enableForAllUsers = mkOption {
type = bool;
default = false;
example = true;
description = ''
Whether to enable the VS Code Server auto-fix service for all users.
enableForUsers = {
enable = mkOption {
type = bool;
default = false;
example = true;
description = ''
Whether to enable the VS Code Server auto-fix service for each user.
This only makes sense if auto-fix-vscode-server is installed as a NixOS module.
This only makes sense if auto-fix-vscode-server is installed as a NixOS module.
This automatically sets up the service's symlinks for systemd in each users' home directory.
'';
This automatically sets up the service's symlinks for systemd in each users' home directory.
'';
};

users = mkOption {
type = listOf (passwdEntry str);
default = builtins.attrNames (lib.attrsets.filterAttrs (username: userOptions: userOptions.isNormalUser) config.users.users);
defaultText = "builtins.attrNames (lib.filterAttrs (_: userOptions: userOptions.isNormalUser) config.users.users)";
example = [ "alice" "bob" ];
description = ''
List of users to enable the VS Code Server auto-fix service for.
By default this will fallback to the list of "normal" users.
'';
};
};
};

Expand All @@ -69,7 +83,7 @@ moduleConfig: {
cfg = config.services.vscode-server;
auto-fix-vscode-server =
pkgs.callPackage ../../pkgs/auto-fix-vscode-server.nix
(removeAttrs cfg [ "enable" "enableForAllUsers" ]);
(removeAttrs cfg [ "enable" "enableForUsers" ]);
in
mkIf cfg.enable (mkMerge [
{
Expand Down

0 comments on commit be0d05d

Please sign in to comment.