From d007d1f2f7d9b4c658d684c60b2767718e5f2383 Mon Sep 17 00:00:00 2001 From: "Agatha V. Lovelace" Date: Sat, 15 Apr 2023 12:29:10 +0200 Subject: [PATCH] Provide NixOS module --- README.md | 39 +++++++++++++-------------------------- flake.nix | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 206fdf8..aa5a51b 100644 --- a/README.md +++ b/README.md @@ -43,35 +43,22 @@ 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" '' - 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" - } - ''; -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} +{ ... }: { + services.url-eater = { + enable = true; + filters = '' + 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" + } ''; }; } diff --git a/flake.nix b/flake.nix index 845d2de..573f9b1 100644 --- a/flake.nix +++ b/flake.nix @@ -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} + ''; + }; + }; + }; + }; }