-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to enable the service for all users
- Loading branch information
Showing
4 changed files
with
139 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,57 @@ | ||
import ./module.nix ({ | ||
name, | ||
description, | ||
serviceConfig, | ||
}: { | ||
systemd.user.services.${name} = { | ||
inherit description serviceConfig; | ||
wantedBy = [ "default.target" ]; | ||
}; | ||
}) | ||
import ./module.nix ( | ||
{ name | ||
, description | ||
, serviceConfig | ||
, lib | ||
, config | ||
, cfg | ||
}: lib.mkMerge [ | ||
{ | ||
systemd.user.services.${name} = { | ||
inherit description serviceConfig; | ||
wantedBy = [ "default.target" ]; | ||
}; | ||
} | ||
(lib.mkIf cfg.enableForAllUsers { | ||
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)); | ||
homeDirectory = (path: forEachUser { | ||
inherit path; | ||
file = (username: { | ||
"d" = { | ||
user = username; | ||
group = "users"; | ||
mode = "0755"; | ||
}; | ||
}); | ||
}); | ||
in | ||
{ | ||
# We need to create each of the folders before the next file otherwise parents get owned by root | ||
"80-setup-config-folder-for-all-users" = homeDirectory ".config"; | ||
"81-setup-systemd-folder-for-all-users" = homeDirectory ".config/systemd"; | ||
"82-setup-systemd-user-folder-for-all-users" = homeDirectory ".config/systemd/user"; | ||
"83-enable-auto-fix-vscode-server-service-for-all-users" = forEachUser { | ||
path = ".config/systemd/user/auto-fix-vscode-server.service"; | ||
file = (username: { | ||
"L+" = { | ||
user = username; | ||
group = "users"; | ||
# This path is made available by `services.vscode-server.enable = true;` | ||
argument = "/run/current-system/etc/systemd/user/auto-fix-vscode-server.service"; | ||
}; | ||
}); | ||
}; | ||
}; | ||
}) | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
import ./module.nix ({ | ||
name, | ||
description, | ||
serviceConfig, | ||
}: { | ||
systemd.user.services.${name} = { | ||
Unit = { | ||
Description = description; | ||
}; | ||
import ./module.nix ( | ||
{ name | ||
, description | ||
, serviceConfig | ||
, cfg | ||
, ... | ||
}: | ||
{ | ||
systemd.user.services.${name} = { | ||
Unit = { | ||
Description = description; | ||
}; | ||
|
||
Service = serviceConfig; | ||
Service = serviceConfig; | ||
|
||
Install = { | ||
WantedBy = [ "default.target" ]; | ||
Install = { | ||
WantedBy = [ "default.target" ]; | ||
}; | ||
}; | ||
}; | ||
}) | ||
|
||
assertions = [{ | ||
assertion = !cfg.enableForAllUsers; | ||
message = "enableForAllUsers=true doesn't make sense when using nixos-vscode-server as a home-manager module"; | ||
}]; | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters