Skip to content
This repository has been archived by the owner on Dec 29, 2024. It is now read-only.

Commit

Permalink
fix(nix): reverted new option to build config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Wittano committed Apr 15, 2024
1 parent bae6294 commit b242a15
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 91 deletions.
8 changes: 3 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
outputs = { self, nixpkgs, }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
filebot = pkgs.callPackage ./default.nix { };
goSDK = pkgs.go;
in
{
packages.x86_64-linux.default = filebot;
nixosModules.default = import ./service.nix;
devShells.x86_64-linux.default = import ./shell.nix { inherit pkgs goSDK; };
packages.x86_64-linux.default = pkgs.callPackage ./default.nix { };
nixosModules.default = ./service.nix;
devShells.x86_64-linux.default = pkgs.callPackage ./shell.nix { };
};
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/wittano/filebot

go 1.22
go 1.21

require (
github.com/fsnotify/fsnotify v1.7.0
Expand Down
84 changes: 3 additions & 81 deletions service.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,6 @@ with lib;
let
cfg = config.services.filebot;
filebot = pkgs.callPackage ./default.nix { };

buildConfig = conf:
let
destAttrs = assert conf ? dest && (conf ? moveToTrash && conf.moveToTrash == true);
if conf ? dest
then { dest = conf.dest; }
else { moveToTrash = conf.moveToTrash; };
afterAttrs = assert conf ? after && conf.moveToTrash != true; { after = conf.after; };
in
{
name = conf.name;
value = {
src = conf.src;
exceptions = mkIf (conf ? exceptions) conf.exceptions;
recursive = mkIf (conf ? recursive) conf.recursive;
uid = conf.uid;
gid = conf.gid;
isRoot = assert cfg.user == "root"; conf.isRoot;
} // destAttrs // afterAttrs;
};

configs = builtins.listToAttrs (builtins.map buildConfig cfg.settings);

filebotConfig = (pkgs.formats.toml { }).generate "config.toml" configs;
in
{
options = {
Expand All @@ -38,58 +14,15 @@ in
description = "Specific user, who will be run service";
};
configPath = mkOption {
type = types.path;
default = "$HOME/.setting/filebot/setting.toml";
example = "/home/wittano/setting.toml";
type = with types; path;
example = ./home/wittano/setting.toml;
description = ''
Path to program configuration.
REMEMBER!
Program accept only toml-formatted files
'';
};
settings = mkOption {
type = with types; listOf (submodule {
options = {
name = mkOption {
type = str;
example = "File";
description = "Single entity of configuration. It's only nesessary for generatation config. It isn't affect on filebot";
};
isRoot = mkEnableOption "Set ownership files to root(required root permission)";
recursive = mkEnableOption "Observe files in directories inside src path";
moveToTrash = mkEnableOption "Move files to Trash directory. This option required abset 'dest' option";
after = mkOption {
type = ints.positive;
description = "Number of days, after files should move to Trash directory";
};
exceptions = mkOption {
type = listOf str;
example = [ "files.pdf" "files.ini" ];
description = "List of filenames, that should be ignored by filebot";
};
uid = mkOption {
type = ints.positive;
description = "New owner UID";
};
gid = mkOption {
type = ints.positive;
description = "New owner GID";
};
src = mkOption {
type = listOf str;
example = [ "/home/user/Documents" ];
description = "List of sources files, which should be observer";
};
dest = mkOption {
type = nullOr str;
example = "/home/user/Destination";
description = "Path to destination directory. This option can't set with moveToTrash";
};
};
});
description = "Configurtion for filebot";
};
updateInterval = mkOption {
type = types.str;
default = "10m";
Expand All @@ -102,24 +35,13 @@ in
};
};

assertions = [
{
assertion = cfg.settings != null && cfg.configPath != null;
message = "Option services.filebot.settings and services.filebot.configPath can't be set at the same time";
}
{
assertion = cfg.settings == null && cfg.configPath == null;
message = "One of option: services.filebot.settings and services.filebot.configPath must be set";
}
];

config = mkIf cfg.enable {
systemd.services.filebot = {
description = "Service to automaticlly sorting files";
serviceConfig.User = mkIf (cfg.user != "root") cfg.user;
wantedBy = [ "multi-user.target" ];
path = [ filebot ];
script = "filebot -c ${filebotConfig} -u ${cfg.updateInterval}";
script = "filebot -c ${cfg.configPath} -u ${cfg.updateInterval}";
};
};
}
8 changes: 4 additions & 4 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{ pkgs ? import <nixpkgs> { }, goSDK }: pkgs.mkShell {
{ mkShell, go, nixpkgs-fmt, nixd }: mkShell {
hardeningDisable = [ "all" ];
nativeBuildInputs = with pkgs; [
nativeBuildInputs = [
# Go tools
goSDK
go

# Nix
nixpkgs-fmt
nixd
];

GOROOT = "${goSDK}/share/go";
GOROOT = "${go}/share/go";
}

0 comments on commit b242a15

Please sign in to comment.