www
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYestin L. Harrison <yestin@ylh.io>2022-06-24 12:24:02 -0700
committerYestin L. Harrison <yestin@ylh.io>2022-06-24 14:40:49 -0700
commit9a9449aa7384eb1af399551d5240d4eba3b11752 (patch)
tree19ea277c77e784df0e369ba1008f3381d3ec7f96
parent5d48f5ee655a5ba8e7de1888fb99d076899ed632 (diff)
downloaddyn-9a9449aa7384eb1af399551d5240d4eba3b11752.tar.gz
dyn-9a9449aa7384eb1af399551d5240d4eba3b11752.tar.xz
dyn-9a9449aa7384eb1af399551d5240d4eba3b11752.zip
modules/linux: add owner.nix
-rw-r--r--modules/linux/owner.nix43
1 files changed, 43 insertions, 0 deletions
diff --git a/modules/linux/owner.nix b/modules/linux/owner.nix
new file mode 100644
index 0000000..c68d17f
--- /dev/null
+++ b/modules/linux/owner.nix
@@ -0,0 +1,43 @@
+{ config, lib, ... }:
+with lib;
+with lib.types;
+let
+ cfg = config.dyn;
+in {
+ options.dyn = {
+ location = mkOption {
+ type = path;
+ default = builtins.toString ../..;
+ readOnly = true;
+ description = ''
+ Path to dyn, for access from other modules.
+ '';
+ };
+ owner = mkOption {
+ type = nullOr str;
+ default = null;
+ description = ''
+ Username (strictly, key into <literal>users.users</literal>) that will take
+ ownership of dyn on system activation.
+ '';
+ };
+ extraDeps = mkOption {
+ type = listOf string;
+ default = [];
+ description = ''
+ Additional activation scripts to run before taking ownership.
+ '';
+ };
+ };
+ config = mkIf (cfg.owner != null) {
+ system.activationScripts.dyn-take-ownership = let
+ u = config.users.users.${cfg.owner};
+ in {
+ deps = [ "users" "groups" ] ++ cfg.extraDeps;
+ text = ''
+ chown -R ${u.name}:${u.group} ${cfg.location}
+ '';
+ };
+ };
+}
+