flake reorg

This commit is contained in:
Robin Appelman 2024-12-14 19:26:31 +01:00
commit 9b6e80d522
11 changed files with 125 additions and 231 deletions

View file

@ -4,7 +4,7 @@ on:
push: push:
jobs: jobs:
check: checks:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@ -13,62 +13,5 @@ jobs:
with: with:
name: ci name: ci
instance: https://cache.icewind.me instance: https://cache.icewind.me
authToken: '${{ secrets.ATTIC_TOKEN }}' authToken: "${{ secrets.ATTIC_TOKEN }}"
- run: nix build .#check - run: nix flake check --keep-going
clippy:
runs-on: ubuntu-latest
needs: check
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v26
- uses: icewind1991/attic-action@v1
with:
name: ci
instance: https://cache.icewind.me
authToken: '${{ secrets.ATTIC_TOKEN }}'
- run: nix build .#clippy
msrv:
runs-on: ubuntu-latest
needs: check
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v26
- uses: icewind1991/attic-action@v1
with:
name: ci
instance: https://cache.icewind.me
authToken: '${{ secrets.ATTIC_TOKEN }}'
- run: nix build .#msrv
build:
runs-on: ubuntu-latest
needs: check
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v26
- uses: icewind1991/attic-action@v1
with:
name: ci
instance: https://cache.icewind.me
authToken: '${{ secrets.ATTIC_TOKEN }}'
- run: nix build .#rss-webhook-trigger
docker:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: cachix/install-nix-action@v26
- uses: icewind1991/attic-action@v1
with:
name: ci
instance: https://cache.icewind.me
authToken: '${{ secrets.ATTIC_TOKEN }}'
- run: nix build .#docker
- name: Push image
if: github.ref == 'refs/heads/main'
run: |
skopeo copy --dest-creds="${{ secrets.DOCKERHUB_USERNAME }}:${{ secrets.DOCKERHUB_TOKEN }}" "docker-archive:$(nix build .#docker --print-out-paths)" "docker://icewind1991/rss-webhook-trigger"

View file

@ -46,7 +46,7 @@ A NixOS module is included and can be used like this:
outputs = { self, nixpkgs, rss-webhook-trigger }: { outputs = { self, nixpkgs, rss-webhook-trigger }: {
nixosConfigurations.my-machine = nixpkgs.lib.nixosSystem { nixosConfigurations.my-machine = nixpkgs.lib.nixosSystem {
modules = modules =
[ [
rss-webhook-trigger.nixosModules.default rss-webhook-trigger.nixosModules.default
{ {
services.rss-webhook-trigger = { services.rss-webhook-trigger = {
@ -64,4 +64,4 @@ A NixOS module is included and can be used like this:
}; };
}; };
} }
``` ```

View file

@ -1,6 +1,6 @@
{ { dockerTools
dockerTools, , rss-webhook-trigger
rss-webhook-trigger, ,
}: }:
dockerTools.buildLayeredImage { dockerTools.buildLayeredImage {
name = "icewind1991/rss-webhook-trigger"; name = "icewind1991/rss-webhook-trigger";
@ -11,6 +11,6 @@ dockerTools.buildLayeredImage {
dockerTools.caCertificates dockerTools.caCertificates
]; ];
config = { config = {
Cmd = ["rss-webhook-trigger"]; Cmd = [ "rss-webhook-trigger" ];
}; };
} }

91
flake.lock generated
View file

@ -1,78 +1,98 @@
{ {
"nodes": { "nodes": {
"flake-utils": { "crane": {
"inputs": {
"systems": "systems"
},
"locked": { "locked": {
"lastModified": 1710146030, "lastModified": 1733688869,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "narHash": "sha256-KrhxxFj1CjESDrL5+u/zsVH0K+Ik9tvoac/oFPoxSB8=",
"owner": "numtide", "owner": "ipetkov",
"repo": "flake-utils", "repo": "crane",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "rev": "604637106e420ad99907cae401e13ab6b452e7d9",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "numtide", "owner": "ipetkov",
"repo": "flake-utils", "repo": "crane",
"type": "github" "type": "github"
} }
}, },
"naersk": { "flakelight": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
"nixpkgs" "nixpkgs"
] ]
}, },
"locked": { "locked": {
"lastModified": 1721727458, "lastModified": 1733748390,
"narHash": "sha256-r/xppY958gmZ4oTfLiHN0ZGuQ+RSTijDblVgVLFi1mw=", "narHash": "sha256-UqTETFjEkwu7WAtlRJPoM7rZpkMnvM9LeupKes+Breg=",
"owner": "nix-community", "owner": "nix-community",
"repo": "naersk", "repo": "flakelight",
"rev": "3fb418eaf352498f6b6c30592e3beb63df42ef11", "rev": "3b6d1f0651f7cf4f4dc17c45e12782778a11520b",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nix-community", "owner": "nix-community",
"repo": "naersk", "repo": "flakelight",
"type": "github"
}
},
"mill-scale": {
"inputs": {
"crane": "crane",
"flakelight": [
"flakelight"
],
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1734188451,
"narHash": "sha256-bLsT74oXirSNn2oaSRd61/V/+OZ4jRKEkdBpzSZkBbM=",
"owner": "icewind1991",
"repo": "mill-scale",
"rev": "d8e263916aa788a98e28fce06e26940001f38d5b",
"type": "github"
},
"original": {
"owner": "icewind1991",
"repo": "mill-scale",
"type": "github" "type": "github"
} }
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1722519197, "lastModified": 1733808091,
"narHash": "sha256-VEdJmVU2eLFtLqCjTYJd1J7+Go8idAcZoT11IewFiRg=", "narHash": "sha256-KWwINTQelKOoQgrXftxoqxmKFZb9pLVfnRvK270nkVk=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "05405724efa137a0b899cce5ab4dde463b4fd30b", "rev": "a0f3e10d94359665dba45b71b4227b0aeb851f8e",
"type": "github" "type": "github"
}, },
"original": { "original": {
"id": "nixpkgs", "id": "nixpkgs",
"ref": "nixos-24.05", "ref": "nixos-24.11",
"type": "indirect" "type": "indirect"
} }
}, },
"root": { "root": {
"inputs": { "inputs": {
"flake-utils": "flake-utils", "flakelight": "flakelight",
"naersk": "naersk", "mill-scale": "mill-scale",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs"
"rust-overlay": "rust-overlay"
} }
}, },
"rust-overlay": { "rust-overlay": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
"mill-scale",
"flakelight",
"nixpkgs" "nixpkgs"
] ]
}, },
"locked": { "locked": {
"lastModified": 1722651535, "lastModified": 1733884434,
"narHash": "sha256-2uRmNwxe3CO5h7PfvqXrRe8OplXaEdwhqOUtaF13rpU=", "narHash": "sha256-8GXR9kC07dyOIshAyfZhG11xfvBRSZzYghnZ2weOKJU=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "56d83ca6f3c557647476f3720426a7615c22b860", "rev": "d0483df44ddf0fd1985f564abccbe568e020ddf2",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -80,21 +100,6 @@
"repo": "rust-overlay", "repo": "rust-overlay",
"type": "github" "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", "root": "root",

109
flake.nix
View file

@ -1,88 +1,29 @@
{ {
inputs = { inputs = {
flake-utils.url = "github:numtide/flake-utils"; nixpkgs.url = "nixpkgs/nixos-24.11";
nixpkgs.url = "nixpkgs/nixos-24.05"; flakelight = {
naersk.url = "github:nix-community/naersk"; url = "github:nix-community/flakelight";
naersk.inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
rust-overlay.inputs.flake-utils.follows = "flake-utils";
};
outputs = {
self,
nixpkgs,
flake-utils,
naersk,
rust-overlay,
}:
flake-utils.lib.eachDefaultSystem (
system: let
overlays = [
(import rust-overlay)
(import ./overlay.nix)
];
pkgs = import nixpkgs {
inherit system overlays;
};
inherit (pkgs) lib rust-bin callPackage;
inherit (builtins) fromTOML readFile;
msrv = (fromTOML (readFile ./Cargo.toml)).package.rust-version;
toolchain = rust-bin.stable.latest.default;
msrvToolchain = rust-bin.stable."${msrv}".default;
naersk' = callPackage naersk {
rustc = toolchain;
cargo = toolchain;
};
msrvNaersk = callPackage naersk {
rustc = msrvToolchain;
cargo = msrvToolchain;
};
nearskOpt = {
pname = "rss-webhook-trigger";
root = pkgs.rss-webhook-trigger.src;
};
in rec {
packages = rec {
rss-webhook-trigger = pkgs.rss-webhook-trigger;
check = naersk'.buildPackage (nearskOpt
// {
mode = "check";
});
clippy = naersk'.buildPackage (nearskOpt
// {
mode = "clippy";
});
msrv = msrvNaersk.buildPackage (nearskOpt
// {
mode = "check";
});
docker = callPackage ./docker.nix {};
default = rss-webhook-trigger;
};
devShells.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [toolchain bacon cargo-edit cargo-outdated cargo-msrv];
};
}
)
// {
overlays.default = import ./overlay.nix;
nixosModules.default = {
pkgs,
config,
lib,
...
}: {
imports = [./module.nix];
config = lib.mkIf config.services.rss-webhook-trigger.enable {
nixpkgs.overlays = [self.overlays.default];
services.rss-webhook-trigger.package = lib.mkDefault pkgs.rss-webhook-trigger;
};
};
}; };
mill-scale = {
url = "github:icewind1991/mill-scale";
inputs.flakelight.follows = "flakelight";
};
};
outputs = { mill-scale, ... }: mill-scale ./. {
nixosModules = { outputs, ... }: {
default =
{ pkgs
, config
, lib
, ...
}: {
imports = [ ./nix/module.nix ];
config = lib.mkIf config.services.rss-webhook-trigger.enable {
nixpkgs.overlays = [ outputs.overlays.default ];
services.rss-webhook-trigger.package = lib.mkDefault pkgs.rss-webhook-trigger;
};
};
};
};
} }

View file

@ -1,16 +1,16 @@
{ { config
config, , lib
lib, , pkgs
pkgs, , ...
...
}: }:
with lib; let with lib; let
cfg = config.services.rss-webhook-trigger; cfg = config.services.rss-webhook-trigger;
format = pkgs.formats.toml {}; format = pkgs.formats.toml { };
configFile = format.generate "trigger.toml" { configFile = format.generate "trigger.toml" {
feed = cfg.hooks; feed = cfg.hooks;
}; };
in { in
{
options.services.rss-webhook-trigger = { options.services.rss-webhook-trigger = {
enable = mkEnableOption "Enables the rss-webhook-trigger service"; enable = mkEnableOption "Enables the rss-webhook-trigger service";
@ -28,12 +28,12 @@ in {
}; };
headers = mkOption { headers = mkOption {
type = types.attrs; type = types.attrs;
default = {}; default = { };
description = "headers to send"; description = "headers to send";
}; };
body = mkOption { body = mkOption {
type = types.attrs; type = types.attrs;
default = {}; default = { };
description = "body to send"; description = "body to send";
}; };
}; };
@ -54,7 +54,7 @@ in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
systemd.services."rss-webhook-trigger" = { systemd.services."rss-webhook-trigger" = {
wantedBy = ["multi-user.target"]; wantedBy = [ "multi-user.target" ];
environment = { environment = {
RUST_LOG = cfg.log; RUST_LOG = cfg.log;
@ -83,7 +83,7 @@ in {
RestrictAddressFamilies = "AF_INET AF_INET6"; RestrictAddressFamilies = "AF_INET AF_INET6";
RestrictRealtime = true; RestrictRealtime = true;
ProtectProc = "noaccess"; ProtectProc = "noaccess";
SystemCallFilter = ["@system-service" "~@resources" "~@privileged"]; SystemCallFilter = [ "@system-service" "~@resources" "~@privileged" ];
IPAddressDeny = "localhost link-local multicast"; IPAddressDeny = "localhost link-local multicast";
}; };
}; };

3
nix/overlay.nix Normal file
View file

@ -0,0 +1,3 @@
final: prev: {
rss-webhook-trigger = final.callPackage ./package.nix { };
}

19
nix/package.nix Normal file
View file

@ -0,0 +1,19 @@
{ rustPlatform
, lib
}:
let
inherit (lib.sources) sourceByRegex;
inherit (builtins) fromTOML readFile;
src = sourceByRegex ../. [ "Cargo.*" "(src)(/.*)?" ];
cargoPackage = (fromTOML (readFile ../Cargo.toml)).package;
in
rustPlatform.buildRustPackage rec {
inherit (cargoPackage) version;
pname = cargoPackage.name;
inherit src;
cargoLock = {
lockFile = ../Cargo.lock;
};
}

View file

@ -1,3 +0,0 @@
final: prev: {
rss-webhook-trigger = final.callPackage ./package.nix {};
}

View file

@ -1,17 +0,0 @@
{
rustPlatform,
lib,
}: let
inherit (lib.sources) sourceByRegex;
src = sourceByRegex ./. ["Cargo.*" "(src)(/.*)?"];
in
rustPlatform.buildRustPackage rec {
name = "rss-webhook-trigger";
version = "0.1.0";
inherit src;
cargoLock = {
lockFile = ./Cargo.lock;
};
}

View file

@ -1,14 +1,14 @@
use color_eyre::{eyre::WrapErr, Result}; use color_eyre::{eyre::WrapErr, Result};
use serde::{Deserialize, Deserializer};
use std::fs::read_to_string;
use tokio::time::Duration;
use std::collections::HashMap;
use std::convert::{TryFrom, TryInto};
use std::path::Path;
use reqwest::header::{HeaderValue, InvalidHeaderValue}; use reqwest::header::{HeaderValue, InvalidHeaderValue};
use secretfile::{load, SecretError}; use secretfile::{load, SecretError};
use serde::de::Error; use serde::de::Error;
use serde::{Deserialize, Deserializer};
use serde_json::Value; use serde_json::Value;
use std::collections::HashMap;
use std::convert::{TryFrom, TryInto};
use std::fs::read_to_string;
use std::path::Path;
use tokio::time::Duration;
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct Config { pub struct Config {
@ -42,7 +42,10 @@ impl Config {
pub struct HeaderVal(String); pub struct HeaderVal(String);
impl<'de> Deserialize<'de> for HeaderVal { impl<'de> Deserialize<'de> for HeaderVal {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: Deserializer<'de> { fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let raw = String::deserialize(deserializer)?; let raw = String::deserialize(deserializer)?;
let str = load_secret(raw).map_err(D::Error::custom)?; let str = load_secret(raw).map_err(D::Error::custom)?;
Ok(HeaderVal(str)) Ok(HeaderVal(str))
@ -64,4 +67,4 @@ fn load_secret(raw: String) -> Result<String, SecretError> {
} else { } else {
Ok(raw) Ok(raw)
} }
} }