Provide NixOS module

This commit is contained in:
Agatha Lovelace 2023-04-15 12:29:10 +02:00
parent 5bd65faa55
commit d007d1f2f7
Signed by: sorceress
GPG Key ID: 01D0B3AB10CED4F8
2 changed files with 53 additions and 27 deletions

View File

@ -43,19 +43,16 @@ This repository also contains a Nix flake. It can be used in a NixOS configurati
```nix
url-eater.url = "github:AgathaSorceress/url-eater";
```
2. Add package
2. Import NixOS module
```nix
nixpkgs.overlays = [
(final: prev: {
url-eater = url-eater.defaultPackage.${final.system};
})
];
imports = [ url-eater.nixosModule ];
```
3. Add a module that defines a systemd service:
3. Configure the module:
```nix
{ pkgs, ... }:
let
filters = pkgs.writeText "filters.kdl" ''
{ ... }: {
services.url-eater = {
enable = true;
filters = ''
category "Spotify" {
params "context@open.spotify.com" "si@open.spotify.com"
}
@ -63,16 +60,6 @@ let
params "cxt@*.twitter.com" "ref_*@*.twitter.com" "s@*.twitter.com" "t@*.twitter.com" "twclid"
}
'';
in {
systemd.user.services."url-eater" = {
description = "Clipboard URL cleanup service";
after = [ "graphical-session-pre.target" ];
wantedBy = [ "graphical-session.target" ];
script = ''
exec ${pkgs.url-eater}/bin/url-eater ${filters}
'';
};
}
```

View File

@ -24,5 +24,44 @@
];
RUST_SRC_PATH = rustPlatform.rustLibSrc;
};
});
}) // {
nixosModule = { config, lib, pkgs, ... }:
with lib;
let cfg = config.services.url-eater;
in {
options.services.url-eater = {
enable = mkEnableOption "Enables the URL Eater service";
filters = mkOption {
type = types.str;
example = ''
category "Spotify" {
params "context@open.spotify.com" "si@open.spotify.com"
}
category "Twitter" {
params "cxt@*.twitter.com" "ref_*@*.twitter.com" "s@*.twitter.com" "t@*.twitter.com" "twclid"
}
'';
description = mdDoc ''
A list of filters to use, in the KDL file format.
'';
};
};
config = mkIf cfg.enable {
systemd.user.services."url-eater" = let
filters = pkgs.writeText "filters.kdl" cfg.filters;
pkg = self.defaultPackage.${pkgs.system};
in {
description = "Clipboard URL cleanup service";
after = [ "graphical-session-pre.target" ];
wantedBy = [ "graphical-session.target" ];
script = ''
exec ${pkg}/bin/url-eater ${filters}
'';
};
};
};
};
}