extend nixpkgs's lib instead
This commit is contained in:
parent
3ba8c1a5a6
commit
7f7dc03a20
59
flake.nix
59
flake.nix
@ -135,37 +135,8 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
serviceMountDeps = serviceName: dirs: pkgs: {
|
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
||||||
systemd.services."${serviceName}_mounts" =
|
lib = import ./lib.nix { inherit inputs pkgs; };
|
||||||
let
|
|
||||||
lib = nixpkgs.lib;
|
|
||||||
zfslistmounted = pkgs.writeShellApplication {
|
|
||||||
name = "zfslistmounted";
|
|
||||||
runtimeInputs = with pkgs; [
|
|
||||||
zfs
|
|
||||||
gnugrep
|
|
||||||
gawk
|
|
||||||
coreutils
|
|
||||||
];
|
|
||||||
text = ''
|
|
||||||
#!/bin/sh
|
|
||||||
zfs list -o mountpoint,mounted -H | awk '$2 == "yes" {print $1}' | grep -c '${lib.strings.concatStringsSep "\|" dirs}' | grep -Fq ${toString (lib.length dirs)}
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
in
|
|
||||||
{
|
|
||||||
unitConfig.Wants = "zfs.target";
|
|
||||||
serviceConfig = {
|
|
||||||
Type = "oneshot";
|
|
||||||
RemainAfterExit = true;
|
|
||||||
ExecStart = nixpkgs.lib.getExe zfslistmounted;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
systemd.services.${serviceName} = {
|
|
||||||
wants = [ "${serviceName}_mounts.service" ];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt-rfc-style;
|
formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt-rfc-style;
|
||||||
@ -177,32 +148,8 @@
|
|||||||
eth_interface
|
eth_interface
|
||||||
service_configs
|
service_configs
|
||||||
inputs
|
inputs
|
||||||
serviceMountDeps
|
lib
|
||||||
;
|
;
|
||||||
|
|
||||||
# stolen from: https://stackoverflow.com/a/42398526
|
|
||||||
optimizeWithFlags =
|
|
||||||
pkg: flags:
|
|
||||||
nixpkgs.lib.overrideDerivation pkg (
|
|
||||||
old:
|
|
||||||
let
|
|
||||||
newflags = nixpkgs.lib.foldl' (acc: x: "${acc} ${x}") "" flags;
|
|
||||||
oldflags =
|
|
||||||
if (nixpkgs.lib.hasAttr "NIX_CFLAGS_COMPILE" old) then "${old.NIX_CFLAGS_COMPILE}" else "";
|
|
||||||
in
|
|
||||||
{
|
|
||||||
NIX_CFLAGS_COMPILE = "${oldflags} ${newflags}";
|
|
||||||
# stdenv = pkgs.clang19Stdenv;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
optimizePackage =
|
|
||||||
pkg:
|
|
||||||
optimizeWithFlags pkg [
|
|
||||||
"-O3"
|
|
||||||
"-march=znver3"
|
|
||||||
"-mtune=znver3"
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
modules =
|
modules =
|
||||||
[
|
[
|
||||||
|
|||||||
66
lib.nix
Normal file
66
lib.nix
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
{
|
||||||
|
inputs,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
inputs.nixpkgs.lib.extend (
|
||||||
|
final: prev:
|
||||||
|
let
|
||||||
|
lib = prev;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
ensureZfsMounts =
|
||||||
|
dirs:
|
||||||
|
pkgs.writeShellApplication {
|
||||||
|
name = "zfslistmounted";
|
||||||
|
runtimeInputs = with pkgs; [
|
||||||
|
zfs
|
||||||
|
gnugrep
|
||||||
|
gawk
|
||||||
|
coreutils
|
||||||
|
];
|
||||||
|
text = ''
|
||||||
|
#!/bin/sh
|
||||||
|
zfs list -o mountpoint,mounted -H | awk '$2 == "yes" {print $1}' | grep -c '${lib.strings.concatStringsSep "\|" dirs}' | grep -Fq ${toString (lib.length dirs)}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
serviceMountDeps = serviceName: dirs: {
|
||||||
|
systemd.services."${serviceName}_mounts" = {
|
||||||
|
unitConfig.Wants = "zfs.target";
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
RemainAfterExit = true;
|
||||||
|
ExecStart = lib.getExe (final.ensureZfsMounts dirs);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.services.${serviceName} = {
|
||||||
|
wants = [ "${serviceName}_mounts.service" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# stolen from: https://stackoverflow.com/a/42398526
|
||||||
|
optimizeWithFlags =
|
||||||
|
pkg: flags:
|
||||||
|
lib.overrideDerivation pkg (
|
||||||
|
old:
|
||||||
|
let
|
||||||
|
newflags = lib.foldl' (acc: x: "${acc} ${x}") "" flags;
|
||||||
|
oldflags = if (lib.hasAttr "NIX_CFLAGS_COMPILE" old) then "${old.NIX_CFLAGS_COMPILE}" else "";
|
||||||
|
in
|
||||||
|
{
|
||||||
|
NIX_CFLAGS_COMPILE = "${oldflags} ${newflags}";
|
||||||
|
# stdenv = pkgs.clang19Stdenv;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
optimizePackage =
|
||||||
|
pkg:
|
||||||
|
final.optimizeWithFlags pkg [
|
||||||
|
"-O3"
|
||||||
|
"-march=znver3"
|
||||||
|
"-mtune=znver3"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
)
|
||||||
@ -3,15 +3,15 @@
|
|||||||
service_configs,
|
service_configs,
|
||||||
username,
|
username,
|
||||||
pkgs,
|
pkgs,
|
||||||
serviceMountDeps,
|
lib,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
(serviceMountDeps "caddy" [
|
(lib.serviceMountDeps "caddy" [
|
||||||
"/var/lib/caddy"
|
"/var/lib/caddy"
|
||||||
service_configs.https.data_dir
|
service_configs.https.data_dir
|
||||||
] pkgs)
|
])
|
||||||
];
|
];
|
||||||
|
|
||||||
services.caddy = {
|
services.caddy = {
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
{
|
{
|
||||||
pkgs,
|
pkgs,
|
||||||
|
lib,
|
||||||
config,
|
config,
|
||||||
service_configs,
|
service_configs,
|
||||||
username,
|
username,
|
||||||
serviceMountDeps,
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
(serviceMountDeps "gitea" [ config.services.gitea.stateDir ] pkgs)
|
(lib.serviceMountDeps "gitea" [ config.services.gitea.stateDir ])
|
||||||
];
|
];
|
||||||
|
|
||||||
services.gitea = {
|
services.gitea = {
|
||||||
|
|||||||
@ -3,13 +3,13 @@
|
|||||||
pkgs,
|
pkgs,
|
||||||
config,
|
config,
|
||||||
username,
|
username,
|
||||||
serviceMountDeps,
|
lib,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
(serviceMountDeps "immich-server" [ config.services.immich.mediaLocation ] pkgs)
|
(lib.serviceMountDeps "immich-server" [ config.services.immich.mediaLocation ])
|
||||||
(serviceMountDeps "immich-machine-learning" [ config.services.immich.mediaLocation ] pkgs)
|
(lib.serviceMountDeps "immich-machine-learning" [ config.services.immich.mediaLocation ])
|
||||||
];
|
];
|
||||||
|
|
||||||
services.immich = {
|
services.immich = {
|
||||||
|
|||||||
@ -3,23 +3,22 @@
|
|||||||
config,
|
config,
|
||||||
service_configs,
|
service_configs,
|
||||||
username,
|
username,
|
||||||
serviceMountDeps,
|
lib,
|
||||||
optimizePackage,
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
(serviceMountDeps "jellyfin" [
|
(lib.serviceMountDeps "jellyfin" [
|
||||||
config.services.jellyfin.dataDir
|
config.services.jellyfin.dataDir
|
||||||
config.services.jellyfin.cacheDir
|
config.services.jellyfin.cacheDir
|
||||||
] pkgs)
|
])
|
||||||
];
|
];
|
||||||
|
|
||||||
services.jellyfin = {
|
services.jellyfin = {
|
||||||
enable = true;
|
enable = true;
|
||||||
# used for local streaming
|
# used for local streaming
|
||||||
openFirewall = true;
|
openFirewall = true;
|
||||||
package = pkgs.jellyfin.override { jellyfin-ffmpeg = (optimizePackage pkgs.jellyfin-ffmpeg); };
|
package = pkgs.jellyfin.override { jellyfin-ffmpeg = (lib.optimizePackage pkgs.jellyfin-ffmpeg); };
|
||||||
|
|
||||||
dataDir = service_configs.jellyfin.dataDir;
|
dataDir = service_configs.jellyfin.dataDir;
|
||||||
cacheDir = service_configs.jellyfin.cacheDir;
|
cacheDir = service_configs.jellyfin.cacheDir;
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
service_configs,
|
service_configs,
|
||||||
config,
|
config,
|
||||||
inputs,
|
inputs,
|
||||||
optimizePackage,
|
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
@ -19,7 +18,7 @@
|
|||||||
port = service_configs.ports.llama_cpp;
|
port = service_configs.ports.llama_cpp;
|
||||||
host = "0.0.0.0";
|
host = "0.0.0.0";
|
||||||
# vulkan broken: https://github.com/ggml-org/llama.cpp/issues/13801
|
# vulkan broken: https://github.com/ggml-org/llama.cpp/issues/13801
|
||||||
package = (optimizePackage inputs.llamacpp.packages.${pkgs.system}.default);
|
package = (lib.optimizePackage inputs.llamacpp.packages.${pkgs.system}.default);
|
||||||
extraFlags = [
|
extraFlags = [
|
||||||
# "-ngl"
|
# "-ngl"
|
||||||
# "9999"
|
# "9999"
|
||||||
|
|||||||
@ -4,14 +4,13 @@
|
|||||||
lib,
|
lib,
|
||||||
username,
|
username,
|
||||||
config,
|
config,
|
||||||
serviceMountDeps,
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
(serviceMountDeps "minecraft-server-${service_configs.minecraft.server_name}" [
|
(lib.serviceMountDeps "minecraft-server-${service_configs.minecraft.server_name}" [
|
||||||
"${service_configs.minecraft.parent_dir}/${service_configs.minecraft.server_name}"
|
"${service_configs.minecraft.parent_dir}/${service_configs.minecraft.server_name}"
|
||||||
] pkgs)
|
])
|
||||||
];
|
];
|
||||||
|
|
||||||
environment.systemPackages = [
|
environment.systemPackages = [
|
||||||
|
|||||||
@ -3,12 +3,12 @@
|
|||||||
config,
|
config,
|
||||||
username,
|
username,
|
||||||
service_configs,
|
service_configs,
|
||||||
serviceMountDeps,
|
lib,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
(serviceMountDeps "postgresql" [ config.services.postgresql.dataDir ] pkgs)
|
(lib.serviceMountDeps "postgresql" [ config.services.postgresql.dataDir ])
|
||||||
];
|
];
|
||||||
|
|
||||||
services.postgresql = {
|
services.postgresql = {
|
||||||
|
|||||||
@ -4,16 +4,15 @@
|
|||||||
service_configs,
|
service_configs,
|
||||||
username,
|
username,
|
||||||
lib,
|
lib,
|
||||||
serviceMountDeps,
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
(serviceMountDeps "qbittorrent" [
|
(lib.serviceMountDeps "qbittorrent" [
|
||||||
service_configs.torrents_path
|
service_configs.torrents_path
|
||||||
config.services.qbittorrent.serverConfig.Preferences.Downloads.TempPath
|
config.services.qbittorrent.serverConfig.Preferences.Downloads.TempPath
|
||||||
"/var/lib/qBittorrent/qBittorrent"
|
"/var/lib/qBittorrent/qBittorrent"
|
||||||
] pkgs)
|
])
|
||||||
];
|
];
|
||||||
|
|
||||||
# network namespace that is proxied through mullvad
|
# network namespace that is proxied through mullvad
|
||||||
|
|||||||
@ -4,7 +4,6 @@
|
|||||||
lib,
|
lib,
|
||||||
service_configs,
|
service_configs,
|
||||||
username,
|
username,
|
||||||
serviceMountDeps,
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
@ -12,11 +11,11 @@ let
|
|||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
(serviceMountDeps "slskd" [
|
(lib.serviceMountDeps "slskd" [
|
||||||
service_configs.slskd.base
|
service_configs.slskd.base
|
||||||
# service_configs.slskd.downloads
|
# service_configs.slskd.downloads
|
||||||
# service_configs.slskd.incomplete
|
# service_configs.slskd.incomplete
|
||||||
] pkgs)
|
])
|
||||||
];
|
];
|
||||||
|
|
||||||
users.groups."music" = { };
|
users.groups."music" = { };
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user