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";
in {
# Enable Flatpaks.
@ -12,8 +12,8 @@ in {
after = [ "dotfiles.service" ];
serviceConfig.Type = "oneshot";
script = ''
${pkgs.flatpak}/bin/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 {}
${lib.getExe pkgs.flatpak} remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
[[ -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, ... }: {
environment.systemPackages = with pkgs; [ ollama ];
systemd.services.ollama = {
systemd.user.services.ollama = {
description = "Ollama LLM server.";
wantedBy = [ "multi-user.target" "default.target" ];
wantedBy = [ "default.target" ];
wants = [ "NetworkManager-wait-online.service" ];
after = [ "NetworkManager-wait-online.service" ];
serviceConfig.Type = "simple";
@ -10,11 +10,11 @@
${lib.getExe pkgs.ollama} serve
'';
};
systemd.services.ollamamodel = {
systemd.user.services.ollamamodel = {
description = "Ollama LLM model.";
wantedBy = [ "multi-user.target" "default.target" ];
wants = [ "NetworkManager-wait-online.service" "ollama.service" ];
after = [ "NetworkManager-wait-online.service" "ollama.service" ];
wantedBy = [ "default.target" ];
wants = [ "ollama.service" ];
after = [ "ollama.service" ];
serviceConfig.Type = "simple";
script = ''
${lib.getExe pkgs.ollama} pull mistral

View file

@ -1,13 +1,13 @@
{ pkgs, ... }: {
{ pkgs, lib, ... }: {
systemd.services.powerlimit = {
description = "Limit battery charge.";
enable = true;
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
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;'";
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;'";
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 = "${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 = {
description = "AMD disable Boost";
enable = true;
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
RemainAfterExit = "yes";
ExecStart = "${pkgs.bash}/bin/bash -c 'echo 0 > /sys/devices/system/cpu/cpufreq/boost'";
ExecStop = "${pkgs.bash}/bin/bash -c 'echo 1 > /sys/devices/system/cpu/cpufreq/boost'";
ExecStart = "${lib.getExe pkgs.bash} -c 'echo 0 > /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 = {
description = "Intel disable Boost";
enable = true;
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
RemainAfterExit = "yes";
ExecStart = "${pkgs.bash}/bin/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'";
ExecStart = "${lib.getExe pkgs.bash} -c 'echo 1 > /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 = {
description = "Install/update dotfiles on startup.";
wantedBy = [ "multi-user.target" "default.target" ];
@ -11,21 +11,21 @@
cp -r ${inputs.dotfiles}/{*,.*} .
chmod +200 -R .
chmod -77 -R .
${pkgs.git}/bin/git init
${pkgs.git}/bin/git remote add origin https://git.voronind.com/voronind/linux.git
${pkgs.git}/bin/git fetch || {
${lib.getExe pkgs.git} init
${lib.getExe pkgs.git} remote add origin https://git.voronind.com/voronind/linux.git
${lib.getExe pkgs.git} fetch || {
echo "Dotfiles init failed, cleaning up.."
rm -rf .git
exit 1
};
${pkgs.git}/bin/git reset origin/main
${pkgs.git}/bin/git reset --hard HEAD
${pkgs.git}/bin/git checkout main
${pkgs.git}/bin/git branch --set-upstream-to=origin/main main
${pkgs.git}/bin/git branch -D master || true
${pkgs.git}/bin/git clean -f
${lib.getExe pkgs.git} reset origin/main
${lib.getExe pkgs.git} reset --hard HEAD
${lib.getExe pkgs.git} checkout main
${lib.getExe pkgs.git} branch --set-upstream-to=origin/main main
${lib.getExe pkgs.git} branch -D master || true
${lib.getExe pkgs.git} clean -f
};
${pkgs.git}/bin/git pull
${lib.getExe pkgs.git} pull
'';
};
timer = {