further modularization + systemd template

This commit is contained in:
2024-05-11 21:35:31 -06:00
parent 0380c32b9a
commit 02d600cc73
16 changed files with 149 additions and 85 deletions

View File

@@ -19,7 +19,7 @@
internet.enable = lib.mkDefault false;
multimedia.enable = lib.mkDefault false;
office.enable = lib.mkDefault false;
misx.enable = lib.mkDefault false;
misc.enable = lib.mkDefault false;
};
};
}

View File

@@ -1,9 +1,20 @@
{ config, lib, pkgs, ... }: {
imports = [ ./dev/haskell.nix ./dev/nix.nix ./dev/python.nix ./emacs.nix ];
imports = [
./dev/sh.nix
./dev/nix.nix
./dev/docker.nix
./dev/python.nix
./dev/haskell.nix
./dev/javascript.nix
./emacs.nix
];
my.emacs.enable = lib.mkDefault false;
my.dev = {
haskell.enable = lib.mkDefault false;
sh.enable = lib.mkDefault false;
nix.enable = lib.mkDefault false;
docker.enable = lib.mkDefault false;
python.enable = lib.mkDefault false;
haskell.enable = lib.mkDefault false;
javascript.enable = lib.mkDefault false;
};
}

7
modules/dev/docker.nix Normal file
View File

@@ -0,0 +1,7 @@
{ config, lib, pkgs, ... }: {
options.my.dev.docker.enable = lib.mkEnableOption "enable";
config = lib.mkIf config.my.dev.docker.enable {
users.users.jawz.packages = (with pkgs; [ dockfmt ])
++ (with pkgs.nodePackages; [ dockerfile-language-server-nodejs ]);
};
}

View File

@@ -0,0 +1,7 @@
{ config, lib, pkgs, ... }: {
options.my.dev.javascript.enable = lib.mkEnableOption "enable";
config = lib.mkIf config.my.dev.javascript.enable {
users.users.jawz.packages = (with pkgs; [ nodejs ])
++ (with pkgs.nodePackages; [ pnpm ]);
};
}

View File

@@ -1,7 +1,7 @@
{ config, lib, pkgs, ... }: {
options.my.dev.python.enable = lib.mkEnableOption "enable";
config = lib.mkIf config.my.dev.python.enable {
users.users.jawz.packages = with pkgs; ([
users.users.jawz.packages = (with pkgs; ([
pipenv # python development workflow for humans
(python3.withPackages (ps:
with ps; [
@@ -16,6 +16,9 @@
# poetry # dependency management made easy
# pytest # framework for writing tests
]))
]);
])) ++ (with pkgs.nodePackages;
[
pyright # LSP
]);
};
}

10
modules/dev/sh.nix Normal file
View File

@@ -0,0 +1,10 @@
{ config, lib, pkgs, ... }: {
options.my.dev.sh.enable = lib.mkEnableOption "enable";
config = lib.mkIf config.my.dev.sh.enable {
users.users.jawz.packages = (with pkgs; [
bashdb # autocomplete
shellcheck # linting
shfmt # a shell parser and formatter
]) ++ (with pkgs.nodePackages; [ bash-language-server ]);
};
}

View File

@@ -1,7 +1,7 @@
{ config, lib, pkgs, ... }: {
options.my.emacs.enable = lib.mkEnableOption "enable";
config = lib.mkIf config.my.emacs.enable {
users.users.jawz.packages = with pkgs; ([
users.users.jawz.packages = (with pkgs; ([
fd # modern find, faster searches
fzf # fuzzy finder! super cool and useful
ripgrep # modern grep
@@ -14,6 +14,14 @@
xorg.xwininfo
xdotool
xclip
# lsps
yaml-language-server
markdownlint-cli
])) ++ (with pkgs.nodePackages; [
vscode-json-languageserver
# linters
prettier
]);
services.emacs = {
enable = true;

4
modules/scripts.nix Normal file
View File

@@ -0,0 +1,4 @@
{ config, lib, pkgs, ... }: {
imports = [ ./scripts/tasks.nix ];
my.scripts.tasks.enable = lib.mkDefault false;
}

46
modules/scripts/base.nix Normal file
View File

@@ -0,0 +1,46 @@
{ config, lib, pkgs, ... }: {
options.my.script = {
name = lib.mkOption {
type = lib.types.str;
default = "my-script";
description = "Name of the script.";
};
timer = lib.mkOption {
type = lib.types.str;
default = "*:0/10";
description = "Systemd timer schedule.";
};
description = lib.mkOption {
type = lib.types.str;
default = "A service that runs a script.";
description = "Description of the service.";
};
package = lib.mkOption {
type = lib.types.package;
default = pkgs.writeScriptBin "my-script" "echo Hello World";
description = "Package containing the executable script.";
};
};
config = {
users.users.jawz.packages = [ config.my.script.package ];
systemd.user = with config.my.script; {
services."${name}" = {
restartIfChanged = true;
description = description;
wantedBy = [ "default.target" ];
path = [ pkgs.nix package ];
serviceConfig = {
Restart = "on-failure";
RestartSec = 30;
ExecStart = "${package}/bin/${name}";
};
};
timers."${name}" = {
enable = true;
description = description;
wantedBy = [ "timers.target" ];
timerConfig = { OnCalendar = timer; };
};
};
};
}

13
modules/scripts/tasks.nix Normal file
View File

@@ -0,0 +1,13 @@
{ config, lib, pkgs, ... }: {
imports = [ ./base.nix ];
options.my.scripts.tasks.enable = lib.mkEnableOption "enable";
config = lib.mkIf config.my.scripts.tasks.enable {
my.script = {
name = "tasks";
timer = "*:0/10";
description = "runs a bunch of organizing tasks on selected directories";
package = (pkgs.writeScriptBin "tasks"
(builtins.readFile ../../scripts/tasks.sh));
};
};
}

View File

@@ -1,10 +1,8 @@
{ config, lib, pkgs, ... }: {
imports = [ ./shell/exercism.nix ./shell/multimedia.nix ./shell/tools.nix ];
my = {
shell = {
exercism.enable = lib.mkDefault false;
multimedia.enable = lib.mkDefault false;
tools.enable = lib.mkDefault false;
};
my.shell = {
exercism.enable = lib.mkDefault false;
multimedia.enable = lib.mkDefault false;
tools.enable = lib.mkDefault false;
};
}

View File

@@ -1,22 +1,25 @@
{ config, lib, pkgs, ... }: {
options.my.shell.multimedia.enable = lib.mkEnableOption "enable";
config = lib.mkIf config.my.shell.multimedia.enable {
users.users.jawz.packages = with pkgs; [
gallery-dl # similar to yt-dlp but for most image gallery websites
yt-dlp # downloads videos from most video websites
ffmpeg # not ffmpreg, the coolest video conversion tool!
imagemagick # photoshop what??
(buildPythonApplication rec {
pname = "ffpb";
version = "0.4.1";
src = fetchPypi {
inherit pname version;
sha256 = "sha256-7eVqbLpMHS1sBw2vYS4cTtyVdnnknGtEI8190VlXflk=";
};
doCheck = false;
buildInputs = [ setuptools ];
propagatedBuildInputs = [ tqdm ];
})
];
users.users.jawz.packages = with pkgs;
[
gallery-dl # similar to yt-dlp but for most image gallery websites
yt-dlp # downloads videos from most video websites
ffmpeg # not ffmpreg, the coolest video conversion tool!
imagemagick # photoshop what??
] ++ (with pkgs.python3Packages;
[
(buildPythonApplication rec {
pname = "ffpb";
version = "0.4.1";
src = fetchPypi {
inherit pname version;
sha256 = "sha256-7eVqbLpMHS1sBw2vYS4cTtyVdnnknGtEI8190VlXflk=";
};
doCheck = false;
buildInputs = [ setuptools ];
propagatedBuildInputs = [ tqdm ];
})
]);
};
}

View File

@@ -11,6 +11,7 @@
rmlint # amazing dupe finder that integrates well with BTRFS
tldr # man for retards
trash-cli # oop! did not meant to delete that
jq # linting
];
};
}

View File

@@ -1,26 +0,0 @@
{ config, lib, pkgs, ... }:
let
jawzTasks =
pkgs.writeScriptBin "tasks" (builtins.readFile ../../scripts/tasks.sh);
description = "Run a tasks script which keeps a lot of things organized";
in {
systemd.user = {
services.tasks = {
restartIfChanged = true;
description = description;
wantedBy = [ "default.target" ];
path = [ pkgs.bash pkgs.nix jawzTasks ];
serviceConfig = {
Restart = "on-failure";
RestartSec = 30;
ExecStart = "${jawzTasks}/bin/tasks";
};
};
timers.tasks = {
enable = true;
description = description;
wantedBy = [ "timers.target" ];
timerConfig = { OnCalendar = "*:0/10"; };
};
};
}