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,35 +43,22 @@ This repository also contains a Nix flake. It can be used in a NixOS configurati
```nix ```nix
url-eater.url = "github:AgathaSorceress/url-eater"; url-eater.url = "github:AgathaSorceress/url-eater";
``` ```
2. Add package 2. Import NixOS module
```nix ```nix
nixpkgs.overlays = [ imports = [ url-eater.nixosModule ];
(final: prev: {
url-eater = url-eater.defaultPackage.${final.system};
})
];
``` ```
3. Add a module that defines a systemd service: 3. Configure the module:
```nix ```nix
{ pkgs, ... }: { ... }: {
let services.url-eater = {
filters = pkgs.writeText "filters.kdl" '' enable = true;
category "Spotify" { filters = ''
params "context@open.spotify.com" "si@open.spotify.com" 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" category "Twitter" {
} 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; 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}
'';
};
};
};
};
} }