Merge pull request #267983 from nikstur/replace-simple-activation-2
nixos: replace activationScripts 2/x
This commit is contained in:
commit
5a9c0b7600
13 changed files with 177 additions and 132 deletions
|
@ -226,18 +226,6 @@ in
|
||||||
"ldap.conf" = ldapConfig;
|
"ldap.conf" = ldapConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
system.activationScripts = mkIf (!cfg.daemon.enable) {
|
|
||||||
ldap = stringAfter [ "etc" "groups" "users" ] ''
|
|
||||||
if test -f "${cfg.bind.passwordFile}" ; then
|
|
||||||
umask 0077
|
|
||||||
conf="$(mktemp)"
|
|
||||||
printf 'bindpw %s\n' "$(cat ${cfg.bind.passwordFile})" |
|
|
||||||
cat ${ldapConfig.source} - >"$conf"
|
|
||||||
mv -fT "$conf" /etc/ldap.conf
|
|
||||||
fi
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
system.nssModules = mkIf cfg.nsswitch (singleton (
|
system.nssModules = mkIf cfg.nsswitch (singleton (
|
||||||
if cfg.daemon.enable then nss_pam_ldapd else nss_ldap
|
if cfg.daemon.enable then nss_pam_ldapd else nss_ldap
|
||||||
));
|
));
|
||||||
|
@ -258,7 +246,28 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.services = mkIf cfg.daemon.enable {
|
systemd.services = mkMerge [
|
||||||
|
(mkIf (!cfg.daemon.enable) {
|
||||||
|
ldap-password = {
|
||||||
|
wantedBy = [ "sysinit.target" ];
|
||||||
|
before = [ "sysinit.target" "shutdown.target" ];
|
||||||
|
conflicts = [ "shutdown.target" ];
|
||||||
|
unitConfig.DefaultDependencies = false;
|
||||||
|
serviceConfig.Type = "oneshot";
|
||||||
|
serviceConfig.RemainAfterExit = true;
|
||||||
|
script = ''
|
||||||
|
if test -f "${cfg.bind.passwordFile}" ; then
|
||||||
|
umask 0077
|
||||||
|
conf="$(mktemp)"
|
||||||
|
printf 'bindpw %s\n' "$(cat ${cfg.bind.passwordFile})" |
|
||||||
|
cat ${ldapConfig.source} - >"$conf"
|
||||||
|
mv -fT "$conf" /etc/ldap.conf
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
})
|
||||||
|
|
||||||
|
(mkIf cfg.daemon.enable {
|
||||||
nslcd = {
|
nslcd = {
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
|
||||||
|
@ -292,8 +301,8 @@ in
|
||||||
AmbientCapabilities = "CAP_SYS_RESOURCE";
|
AmbientCapabilities = "CAP_SYS_RESOURCE";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
})
|
||||||
};
|
];
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ let
|
||||||
mkDefault
|
mkDefault
|
||||||
mkIf
|
mkIf
|
||||||
mkOption
|
mkOption
|
||||||
stringAfter
|
|
||||||
types
|
types
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
|
@ -39,9 +39,10 @@ in
|
||||||
|
|
||||||
hardware.firmware = [ package.fw ];
|
hardware.firmware = [ package.fw ];
|
||||||
|
|
||||||
system.activationScripts.setup-amdgpu-pro = ''
|
systemd.tmpfiles.settings.amdgpu-pro = {
|
||||||
ln -sfn ${package}/opt/amdgpu{,-pro} /run
|
"/run/amdgpu"."L+".argument = "${package}/opt/amdgpu";
|
||||||
'';
|
"/run/amdgpu-pro"."L+".argument = "${package}/opt/amdgpu-pro";
|
||||||
|
};
|
||||||
|
|
||||||
system.requiredKernelConfig = with config.lib.kernelConfig; [
|
system.requiredKernelConfig = with config.lib.kernelConfig; [
|
||||||
(isYes "DEVICE_PRIVATE")
|
(isYes "DEVICE_PRIVATE")
|
||||||
|
|
|
@ -181,7 +181,14 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
system.activationScripts.ipa = stringAfter ["etc"] ''
|
systemd.services."ipa-activation" = {
|
||||||
|
wantedBy = [ "sysinit.target" ];
|
||||||
|
before = [ "sysinit.target" "shutdown.target" ];
|
||||||
|
conflicts = [ "shutdown.target" ];
|
||||||
|
unitConfig.DefaultDependencies = false;
|
||||||
|
serviceConfig.Type = "oneshot";
|
||||||
|
serviceConfig.RemainAfterExit = true;
|
||||||
|
script = ''
|
||||||
# libcurl requires a hard copy of the certificate
|
# libcurl requires a hard copy of the certificate
|
||||||
if ! ${pkgs.diffutils}/bin/diff ${cfg.certificate} /etc/ipa/ca.crt > /dev/null 2>&1; then
|
if ! ${pkgs.diffutils}/bin/diff ${cfg.certificate} /etc/ipa/ca.crt > /dev/null 2>&1; then
|
||||||
rm -f /etc/ipa/ca.crt
|
rm -f /etc/ipa/ca.crt
|
||||||
|
@ -200,6 +207,7 @@ in {
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
services.sssd.config = ''
|
services.sssd.config = ''
|
||||||
[domain/${cfg.domain}]
|
[domain/${cfg.domain}]
|
||||||
|
|
|
@ -280,6 +280,7 @@ in
|
||||||
wantedBy = [ "sysinit.target" ];
|
wantedBy = [ "sysinit.target" ];
|
||||||
before = [ "sysinit.target" "shutdown.target" ];
|
before = [ "sysinit.target" "shutdown.target" ];
|
||||||
conflicts = [ "shutdown.target" ];
|
conflicts = [ "shutdown.target" ];
|
||||||
|
after = [ "systemd-sysusers.service" ];
|
||||||
unitConfig.DefaultDependencies = false;
|
unitConfig.DefaultDependencies = false;
|
||||||
unitConfig.RequiresMountsFor = [ "/nix/store" "/run/wrappers" ];
|
unitConfig.RequiresMountsFor = [ "/nix/store" "/run/wrappers" ];
|
||||||
serviceConfig.Type = "oneshot";
|
serviceConfig.Type = "oneshot";
|
||||||
|
|
|
@ -143,20 +143,15 @@ let
|
||||||
};
|
};
|
||||||
|
|
||||||
# Paths listed in ReadWritePaths must exist before service is started
|
# Paths listed in ReadWritePaths must exist before service is started
|
||||||
mkActivationScript = name: cfg:
|
mkTmpfiles = name: cfg:
|
||||||
let
|
let
|
||||||
install = "install -o ${cfg.user} -g ${cfg.group}";
|
settings = { inherit (cfg) user group; };
|
||||||
in
|
in lib.nameValuePair "borgbackup-job-${name}" ({
|
||||||
nameValuePair "borgbackup-job-${name}" (stringAfter [ "users" ] (''
|
"${config.users.users."${cfg.user}".home}/.config/borg".d = settings;
|
||||||
# Ensure that the home directory already exists
|
"${config.users.users."${cfg.user}".home}/.cache/borg".d = settings;
|
||||||
# We can't assert createHome == true because that's not the case for root
|
} // optionalAttrs (isLocalPath cfg.repo && !cfg.removableDevice) {
|
||||||
cd "${config.users.users.${cfg.user}.home}"
|
"${cfg.repo}".d = settings;
|
||||||
# Create each directory separately to prevent root owned parent dirs
|
});
|
||||||
${install} -d .config .config/borg
|
|
||||||
${install} -d .cache .cache/borg
|
|
||||||
'' + optionalString (isLocalPath cfg.repo && !cfg.removableDevice) ''
|
|
||||||
${install} -d ${escapeShellArg cfg.repo}
|
|
||||||
''));
|
|
||||||
|
|
||||||
mkPassAssertion = name: cfg: {
|
mkPassAssertion = name: cfg: {
|
||||||
assertion = with cfg.encryption;
|
assertion = with cfg.encryption;
|
||||||
|
@ -760,7 +755,7 @@ in {
|
||||||
++ mapAttrsToList mkSourceAssertions jobs
|
++ mapAttrsToList mkSourceAssertions jobs
|
||||||
++ mapAttrsToList mkRemovableDeviceAssertions jobs;
|
++ mapAttrsToList mkRemovableDeviceAssertions jobs;
|
||||||
|
|
||||||
system.activationScripts = mapAttrs' mkActivationScript jobs;
|
systemd.tmpfiles.settings = mapAttrs' mkTmpfiles jobs;
|
||||||
|
|
||||||
systemd.services =
|
systemd.services =
|
||||||
# A job named "foo" is mapped to systemd.services.borgbackup-job-foo
|
# A job named "foo" is mapped to systemd.services.borgbackup-job-foo
|
||||||
|
|
|
@ -220,10 +220,16 @@ in
|
||||||
logcheck = {};
|
logcheck = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
system.activationScripts.logcheck = ''
|
systemd.tmpfiles.settings.logcheck = {
|
||||||
mkdir -m 700 -p /var/{lib,lock}/logcheck
|
"/var/lib/logcheck".d = {
|
||||||
chown ${cfg.user} /var/{lib,lock}/logcheck
|
mode = "700";
|
||||||
'';
|
inherit (cfg) user;
|
||||||
|
};
|
||||||
|
"/var/lock/logcheck".d = {
|
||||||
|
mode = "700";
|
||||||
|
inherit (cfg) user;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
services.cron.systemCronJobs =
|
services.cron.systemCronJobs =
|
||||||
let withTime = name: {timeArgs, ...}: timeArgs != null;
|
let withTime = name: {timeArgs, ...}: timeArgs != null;
|
||||||
|
|
|
@ -137,7 +137,14 @@ in
|
||||||
message = "networking.enableIPv6 must be true for yggdrasil to work";
|
message = "networking.enableIPv6 must be true for yggdrasil to work";
|
||||||
}];
|
}];
|
||||||
|
|
||||||
system.activationScripts.yggdrasil = mkIf cfg.persistentKeys ''
|
# This needs to be a separate service. The yggdrasil service fails if
|
||||||
|
# this is put into its preStart.
|
||||||
|
systemd.services.yggdrasil-persistent-keys = lib.mkIf cfg.persistentKeys {
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
before = [ "yggdrasil.service" ];
|
||||||
|
serviceConfig.Type = "oneshot";
|
||||||
|
serviceConfig.RemainAfterExit = true;
|
||||||
|
script = ''
|
||||||
if [ ! -e ${keysPath} ]
|
if [ ! -e ${keysPath} ]
|
||||||
then
|
then
|
||||||
mkdir --mode=700 -p ${builtins.dirOf keysPath}
|
mkdir --mode=700 -p ${builtins.dirOf keysPath}
|
||||||
|
@ -147,6 +154,7 @@ in
|
||||||
> ${keysPath}
|
> ${keysPath}
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
systemd.services.yggdrasil = {
|
systemd.services.yggdrasil = {
|
||||||
description = "Yggdrasil Network Service";
|
description = "Yggdrasil Network Service";
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib) mkOption mkDefault types optionalString stringAfter;
|
inherit (lib) mkOption mkDefault types optionalString;
|
||||||
|
|
||||||
cfg = config.boot.binfmt;
|
cfg = config.boot.binfmt;
|
||||||
|
|
||||||
|
|
|
@ -80,10 +80,17 @@ with lib;
|
||||||
ACTION=="add|change", SUBSYSTEM=="input", ATTR{name}=="${cfg.device}", ATTR{device/speed}="${toString cfg.speed}", ATTR{device/sensitivity}="${toString cfg.sensitivity}"
|
ACTION=="add|change", SUBSYSTEM=="input", ATTR{name}=="${cfg.device}", ATTR{device/speed}="${toString cfg.speed}", ATTR{device/sensitivity}="${toString cfg.sensitivity}"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
system.activationScripts.trackpoint =
|
systemd.services.trackpoint = {
|
||||||
''
|
wantedBy = [ "sysinit.target" ] ;
|
||||||
${config.systemd.package}/bin/udevadm trigger --attr-match=name="${cfg.device}"
|
before = [ "sysinit.target" "shutdown.target" ];
|
||||||
|
conflicts = [ "shutdown.target" ];
|
||||||
|
unitConfig.DefaultDependencies = false;
|
||||||
|
serviceConfig.Type = "oneshot";
|
||||||
|
serviceConfig.RemainAfterExit = true;
|
||||||
|
serviceConfig.ExecStart = ''
|
||||||
|
${config.systemd.package}/bin/udevadm trigger --attr-match=name="${cfg.device}
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf (cfg.emulateWheel) {
|
(mkIf (cfg.emulateWheel) {
|
||||||
|
|
|
@ -85,11 +85,21 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
###### wrappers activation script
|
# Services
|
||||||
|
|
||||||
system.activationScripts.vmwareWrappers =
|
systemd.services."vmware-wrappers" = {
|
||||||
lib.stringAfter [ "specialfs" "users" ]
|
description = "Create VMVare Wrappers";
|
||||||
''
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
before = [
|
||||||
|
"vmware-authdlauncher.service"
|
||||||
|
"vmware-networks-configuration.service"
|
||||||
|
"vmware-networks.service"
|
||||||
|
"vmware-usbarbitrator.service"
|
||||||
|
];
|
||||||
|
after = [ "systemd-sysusers.service" ];
|
||||||
|
serviceConfig.Type = "oneshot";
|
||||||
|
serviceConfig.RemainAfterExit = true;
|
||||||
|
script = ''
|
||||||
mkdir -p "${parentWrapperDir}"
|
mkdir -p "${parentWrapperDir}"
|
||||||
chmod 755 "${parentWrapperDir}"
|
chmod 755 "${parentWrapperDir}"
|
||||||
# We want to place the tmpdirs for the wrappers to the parent dir.
|
# We want to place the tmpdirs for the wrappers to the parent dir.
|
||||||
|
@ -111,8 +121,7 @@ in
|
||||||
ln --symbolic "$wrapperDir" "${wrapperDir}"
|
ln --symbolic "$wrapperDir" "${wrapperDir}"
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
};
|
||||||
# Services
|
|
||||||
|
|
||||||
systemd.services."vmware-authdlauncher" = {
|
systemd.services."vmware-authdlauncher" = {
|
||||||
description = "VMware Authentication Daemon";
|
description = "VMware Authentication Daemon";
|
||||||
|
|
|
@ -13,9 +13,9 @@ import ./make-test-python.nix ({ pkgs, lib, ... }:
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# ensure the directory to be monitored exists before incron is started
|
# ensure the directory to be monitored exists before incron is started
|
||||||
system.activationScripts.incronTest = ''
|
systemd.tmpfiles.settings.incron-test = {
|
||||||
mkdir /test
|
"/test".d = { };
|
||||||
'';
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
testScript = ''
|
testScript = ''
|
||||||
|
|
|
@ -13,10 +13,12 @@ in {
|
||||||
# The only thing the client needs to do is download a file.
|
# The only thing the client needs to do is download a file.
|
||||||
client = { ... }: {
|
client = { ... }: {
|
||||||
services.davfs2.enable = true;
|
services.davfs2.enable = true;
|
||||||
system.activationScripts.davfs2-secrets = ''
|
systemd.tmpfiles.settings.nextcloud = {
|
||||||
echo "http://nextcloud/remote.php/dav/files/${adminuser} ${adminuser} ${adminpass}" > /tmp/davfs2-secrets
|
"/tmp/davfs2-secrets"."f+" = {
|
||||||
chmod 600 /tmp/davfs2-secrets
|
mode = "0600";
|
||||||
'';
|
argument = "http://nextcloud/remote.php/dav/files/${adminuser} ${adminuser} ${adminpass}";
|
||||||
|
};
|
||||||
|
};
|
||||||
virtualisation.fileSystems = {
|
virtualisation.fileSystems = {
|
||||||
"/mnt/dav" = {
|
"/mnt/dav" = {
|
||||||
device = "http://nextcloud/remote.php/dav/files/${adminuser}";
|
device = "http://nextcloud/remote.php/dav/files/${adminuser}";
|
||||||
|
|
Loading…
Reference in a new issue