Ollama : Make a user service.

This commit is contained in:
Dmitry Voronin 2024-02-29 09:30:35 +03:00
parent 020fa448e3
commit 99ebc1e529
6 changed files with 31 additions and 31 deletions

View file

@ -1,4 +1,4 @@
{ pkgs, ... }: let { pkgs, lib, ... }: let
list = "~/.config/linux/Flatpak.txt"; list = "~/.config/linux/Flatpak.txt";
in { in {
# Enable Flatpaks. # Enable Flatpaks.
@ -12,8 +12,8 @@ in {
after = [ "dotfiles.service" ]; after = [ "dotfiles.service" ];
serviceConfig.Type = "oneshot"; serviceConfig.Type = "oneshot";
script = '' script = ''
${pkgs.flatpak}/bin/flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo ${lib.getExe pkgs.flatpak} remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
[[ -f ${list} ]] && cat ${list} | cut -f2 | ${pkgs.parallel}/bin/parallel -j1 -- ${pkgs.flatpak}/bin/flatpak install -y --system {} [[ -f ${list} ]] && cat ${list} | cut -f2 | ${lib.getExe pkgs.parallel} -j1 -- ${lib.getExe pkgs.flatpak} install -y --system {}
''; '';
}; };
} }

View file

@ -1,8 +1,8 @@
{ pkgs, lib, ... }: { { pkgs, lib, ... }: {
environment.systemPackages = with pkgs; [ ollama ]; environment.systemPackages = with pkgs; [ ollama ];
systemd.services.ollama = { systemd.user.services.ollama = {
description = "Ollama LLM server."; description = "Ollama LLM server.";
wantedBy = [ "multi-user.target" "default.target" ]; wantedBy = [ "default.target" ];
wants = [ "NetworkManager-wait-online.service" ]; wants = [ "NetworkManager-wait-online.service" ];
after = [ "NetworkManager-wait-online.service" ]; after = [ "NetworkManager-wait-online.service" ];
serviceConfig.Type = "simple"; serviceConfig.Type = "simple";
@ -10,11 +10,11 @@
${lib.getExe pkgs.ollama} serve ${lib.getExe pkgs.ollama} serve
''; '';
}; };
systemd.services.ollamamodel = { systemd.user.services.ollamamodel = {
description = "Ollama LLM model."; description = "Ollama LLM model.";
wantedBy = [ "multi-user.target" "default.target" ]; wantedBy = [ "default.target" ];
wants = [ "NetworkManager-wait-online.service" "ollama.service" ]; wants = [ "ollama.service" ];
after = [ "NetworkManager-wait-online.service" "ollama.service" ]; after = [ "ollama.service" ];
serviceConfig.Type = "simple"; serviceConfig.Type = "simple";
script = '' script = ''
${lib.getExe pkgs.ollama} pull mistral ${lib.getExe pkgs.ollama} pull mistral

View file

@ -1,13 +1,13 @@
{ pkgs, ... }: { { pkgs, lib, ... }: {
systemd.services.powerlimit = { systemd.services.powerlimit = {
description = "Limit battery charge."; description = "Limit battery charge.";
enable = true; enable = true;
wantedBy = [ "multi-user.target" ];
serviceConfig = { serviceConfig = {
Type = "simple"; Type = "simple";
RemainAfterExit = "yes"; RemainAfterExit = "yes";
ExecStart = "${pkgs.bash}/bin/bash -c 'echo 40 > /sys/class/power_supply/BAT0/charge_control_start_threshold; echo 80 > /sys/class/power_supply/BAT0/charge_control_end_threshold;'"; ExecStart = "${lib.getExe pkgs.bash} -c 'echo 40 > /sys/class/power_supply/BAT0/charge_control_start_threshold; echo 80 > /sys/class/power_supply/BAT0/charge_control_end_threshold;'";
ExecStop = "${pkgs.bash}/bin/bash -c 'echo 95 > /sys/class/power_supply/BAT0/charge_control_end_threshold; echo 90 > /sys/class/power_supply/BAT0/charge_control_start_threshold;'"; ExecStop = "${lib.getExe pkgs.bash} -c 'echo 95 > /sys/class/power_supply/BAT0/charge_control_end_threshold; echo 90 > /sys/class/power_supply/BAT0/charge_control_start_threshold;'";
}; };
wantedBy = [ "multi-user.target" ];
}; };
} }

View file

@ -5,12 +5,12 @@
systemd.services.powersave = { systemd.services.powersave = {
description = "AMD disable Boost"; description = "AMD disable Boost";
enable = true; enable = true;
wantedBy = [ "multi-user.target" ];
serviceConfig = { serviceConfig = {
Type = "simple"; Type = "simple";
RemainAfterExit = "yes"; RemainAfterExit = "yes";
ExecStart = "${pkgs.bash}/bin/bash -c 'echo 0 > /sys/devices/system/cpu/cpufreq/boost'"; ExecStart = "${lib.getExe pkgs.bash} -c 'echo 0 > /sys/devices/system/cpu/cpufreq/boost'";
ExecStop = "${pkgs.bash}/bin/bash -c 'echo 1 > /sys/devices/system/cpu/cpufreq/boost'"; ExecStop = "${lib.getExe pkgs.bash} -c 'echo 1 > /sys/devices/system/cpu/cpufreq/boost'";
}; };
wantedBy = [ "multi-user.target" ];
}; };
} }

View file

@ -1,13 +1,13 @@
{ pkgs, ... }: { { pkgs, lib, ... }: {
systemd.services.powersave = { systemd.services.powersave = {
description = "Intel disable Boost"; description = "Intel disable Boost";
enable = true; enable = true;
wantedBy = [ "multi-user.target" ];
serviceConfig = { serviceConfig = {
Type = "simple"; Type = "simple";
RemainAfterExit = "yes"; RemainAfterExit = "yes";
ExecStart = "${pkgs.bash}/bin/bash -c 'echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo'"; ExecStart = "${lib.getExe pkgs.bash} -c 'echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo'";
ExecStop = "${pkgs.bash}/bin/bash -c 'echo 0 > /sys/devices/system/cpu/intel_pstate/no_turbo'"; ExecStop = "${lib.getExe pkgs.bash} -c 'echo 0 > /sys/devices/system/cpu/intel_pstate/no_turbo'";
}; };
wantedBy = [ "multi-user.target" ];
}; };
} }

View file

@ -1,4 +1,4 @@
{ pkgs, inputs, ... }: let { pkgs, inputs, lib, ... }: let
unit = { unit = {
description = "Install/update dotfiles on startup."; description = "Install/update dotfiles on startup.";
wantedBy = [ "multi-user.target" "default.target" ]; wantedBy = [ "multi-user.target" "default.target" ];
@ -11,21 +11,21 @@
cp -r ${inputs.dotfiles}/{*,.*} . cp -r ${inputs.dotfiles}/{*,.*} .
chmod +200 -R . chmod +200 -R .
chmod -77 -R . chmod -77 -R .
${pkgs.git}/bin/git init ${lib.getExe pkgs.git} init
${pkgs.git}/bin/git remote add origin https://git.voronind.com/voronind/linux.git ${lib.getExe pkgs.git} remote add origin https://git.voronind.com/voronind/linux.git
${pkgs.git}/bin/git fetch || { ${lib.getExe pkgs.git} fetch || {
echo "Dotfiles init failed, cleaning up.." echo "Dotfiles init failed, cleaning up.."
rm -rf .git rm -rf .git
exit 1 exit 1
}; };
${pkgs.git}/bin/git reset origin/main ${lib.getExe pkgs.git} reset origin/main
${pkgs.git}/bin/git reset --hard HEAD ${lib.getExe pkgs.git} reset --hard HEAD
${pkgs.git}/bin/git checkout main ${lib.getExe pkgs.git} checkout main
${pkgs.git}/bin/git branch --set-upstream-to=origin/main main ${lib.getExe pkgs.git} branch --set-upstream-to=origin/main main
${pkgs.git}/bin/git branch -D master || true ${lib.getExe pkgs.git} branch -D master || true
${pkgs.git}/bin/git clean -f ${lib.getExe pkgs.git} clean -f
}; };
${pkgs.git}/bin/git pull ${lib.getExe pkgs.git} pull
''; '';
}; };
timer = { timer = {