~witcher/rss-email

e710946810f874e8ad3c0a43d26398a376065f2e — witcher 1 year, 3 months ago be44898 nix-flake-support
add nix flake support
6 files changed, 267 insertions(+), 8 deletions(-)

M .gitignore
M README.md
R config.example.toml => config/config.toml
A flake.lock
A flake.nix
A rust-toolchain.toml
M .gitignore => .gitignore +1 -0
@@ 1,3 1,4 @@
/target
.env
dev.db
result

M README.md => README.md +24 -8
@@ 15,11 15,11 @@ There are 2 packages available in the AUR:

Install the dependencies:

- Rust
- Rust (rustc, cargo)
- sqlite
- [sqlx-cli](https://github.com/launchbadge/sqlx/tree/main/sqlx-cli#install)
  (optional, only for development)
- scdoc (optional)
- scdoc (optional, for man pages)

First specify the `DATABASE_URL` environment variable and set up the database
with `cargo-sqlx`:


@@ 32,7 32,7 @@ cargo sqlx database setup
Then compile `rss-email`:

```
cargo build
cargo build --release
```

To build the man pages, use `scdoc`:


@@ 42,19 42,35 @@ scdoc < docs/rss-email.1.scd > docs/rss-email.1
scdoc < docs/rss-email.5.scd > docs/rss-email.5
```

### Nix

A nix flake is available.  
To build, use

```
nix build
```

For development, use

```
nix develop
```

## Usage

- Copy the `config.example.toml` to `~/.config/rss-email/config.toml` and adjust
- Copy the `config/config.toml` to `~/.config/rss-email/config.toml` and adjust
  the values
- Create a `urls` file at `~/.config/rss-email/urls` with one RSS url per line
- Create a `urls` file at `~/.config/rss-email/urls` with one RSS/Atom URL per
  line

The database used with `rss-email` is generated automatically if it doesn't exist
yet
yet.

See the man page or `-h` for more info. You can view the man page after
generating it with `scdoc` with `man -l docs/rss-email.1`.  
generating it with `scdoc` with `man -l rss-email.1`.  
A man page for the configuration exists, too, which you can view after building
with `scdoc`: `man -l doc/rss-email.5`.
with `scdoc`: `man -l rss-email.5`.

## Resources


R config.example.toml => config/config.toml +0 -0
A flake.lock => flake.lock +165 -0
@@ 0,0 1,165 @@
{
  "nodes": {
    "crane": {
      "inputs": {
        "flake-compat": "flake-compat",
        "flake-utils": "flake-utils",
        "nixpkgs": [
          "nixpkgs"
        ],
        "rust-overlay": "rust-overlay"
      },
      "locked": {
        "lastModified": 1681177078,
        "narHash": "sha256-ZNIjBDou2GOabcpctiQykEQVkI8BDwk7TyvlWlI4myE=",
        "owner": "ipetkov",
        "repo": "crane",
        "rev": "0c9f468ff00576577d83f5019a66c557ede5acf6",
        "type": "github"
      },
      "original": {
        "owner": "ipetkov",
        "repo": "crane",
        "type": "github"
      }
    },
    "flake-compat": {
      "flake": false,
      "locked": {
        "lastModified": 1673956053,
        "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
        "owner": "edolstra",
        "repo": "flake-compat",
        "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
        "type": "github"
      },
      "original": {
        "owner": "edolstra",
        "repo": "flake-compat",
        "type": "github"
      }
    },
    "flake-utils": {
      "locked": {
        "lastModified": 1678901627,
        "narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=",
        "owner": "numtide",
        "repo": "flake-utils",
        "rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6",
        "type": "github"
      },
      "original": {
        "owner": "numtide",
        "repo": "flake-utils",
        "type": "github"
      }
    },
    "flake-utils_2": {
      "inputs": {
        "systems": "systems"
      },
      "locked": {
        "lastModified": 1681037374,
        "narHash": "sha256-XL6X3VGbEFJZDUouv2xpKg2Aljzu/etPLv5e1FPt1q0=",
        "owner": "numtide",
        "repo": "flake-utils",
        "rev": "033b9f258ca96a10e543d4442071f614dc3f8412",
        "type": "github"
      },
      "original": {
        "owner": "numtide",
        "repo": "flake-utils",
        "type": "github"
      }
    },
    "nixpkgs": {
      "locked": {
        "lastModified": 1681036984,
        "narHash": "sha256-AbScJXshYzbeUKHh+Y3OICc3iAtr+NqJ3Xb81GW+ptU=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "fd531dee22c9a3d4336cc2da39e8dd905e8f3de4",
        "type": "github"
      },
      "original": {
        "owner": "NixOS",
        "ref": "nixos-unstable",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
    "root": {
      "inputs": {
        "crane": "crane",
        "flake-utils": "flake-utils_2",
        "nixpkgs": "nixpkgs",
        "rust-overlay": "rust-overlay_2"
      }
    },
    "rust-overlay": {
      "inputs": {
        "flake-utils": [
          "crane",
          "flake-utils"
        ],
        "nixpkgs": [
          "crane",
          "nixpkgs"
        ]
      },
      "locked": {
        "lastModified": 1680488274,
        "narHash": "sha256-0vYMrZDdokVmPQQXtFpnqA2wEgCCUXf5a3dDuDVshn0=",
        "owner": "oxalica",
        "repo": "rust-overlay",
        "rev": "7ec2ff598a172c6e8584457167575b3a1a5d80d8",
        "type": "github"
      },
      "original": {
        "owner": "oxalica",
        "repo": "rust-overlay",
        "type": "github"
      }
    },
    "rust-overlay_2": {
      "inputs": {
        "flake-utils": [
          "flake-utils"
        ],
        "nixpkgs": [
          "nixpkgs"
        ]
      },
      "locked": {
        "lastModified": 1681179516,
        "narHash": "sha256-Ij/3YM5Gz5AiDKnP77ODJp2RGRRWmGTWYlfnuUT3z78=",
        "owner": "oxalica",
        "repo": "rust-overlay",
        "rev": "9e7373ba5627ffe952f66a3e82e3a375bdc38565",
        "type": "github"
      },
      "original": {
        "owner": "oxalica",
        "repo": "rust-overlay",
        "type": "github"
      }
    },
    "systems": {
      "locked": {
        "lastModified": 1681028828,
        "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
        "owner": "nix-systems",
        "repo": "default",
        "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
        "type": "github"
      },
      "original": {
        "owner": "nix-systems",
        "repo": "default",
        "type": "github"
      }
    }
  },
  "root": "root",
  "version": 7
}

A flake.nix => flake.nix +75 -0
@@ 0,0 1,75 @@
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    crane = {
      url = "github:ipetkov/crane";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    flake-utils.url = "github:numtide/flake-utils";
    rust-overlay = {
      url = "github:oxalica/rust-overlay";
      inputs = {
        nixpkgs.follows = "nixpkgs";
        flake-utils.follows = "flake-utils";
      };
    };
  };

  outputs = { self, nixpkgs, crane, flake-utils, rust-overlay }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          system = system;
          overlays = [ (import rust-overlay) ];
        };

        rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile
          ./rust-toolchain.toml;
        lib = crane.lib.${system}.overrideToolchain rustToolchain;

        rss-email-deps = lib.buildDepsOnly {
          src = ./.;
        };

        rss-email = lib.buildPackage {
          cargoArtifacts = rss-email-deps;
          src = ./.;
          nativeBuildInputs = with pkgs; [ scdoc ];
          installCargoArtifactsMode = "use-symlink";
          postBuild = ''
            scdoc < docs/rss-email.1.scd > rss-email.1
            scdoc < docs/rss-email.5.scd > rss-email.5
          '';
          installPhase = ''
            export PREFIX=$out/
            export BINDIR=$PREFIX/bin
            export MANDIR=$PREFIX/share/man
            export SHAREDIR=$PREFIX/share/rss-email
            export LICENSEDIR=$out/usr/share/licenses/rss-email

            mkdir -p $out

            gzip rss-email.1
            gzip rss-email.5

            install -Dm755 target/release/rss-email $BINDIR/rss-email
            install -Dm644 rss-email.1.gz $MANDIR/man1/rss-email.1.gz
            install -Dm644 rss-email.5.gz $MANDIR/man5/rss-email.5.gz
            install -Dm644 config/config.toml $SHAREDIR/config.toml
            install -Dm644 LICENSE $LICENSEDIR/LICENSE
          '';
        };
      in
      rec
      {
        checks = {
          inherit rss-email;
        };
        packages.rss-email = rss-email;
        packages.default = packages.rss-email;
        devShells.default = pkgs.mkShell {
          inputsFrom = [ rss-email ];
        };
      }
    );
}

A rust-toolchain.toml => rust-toolchain.toml +2 -0
@@ 0,0 1,2 @@
[toolchain]
channel = "1.60.0"