1
0
Fork 0
mirror of https://codeberg.org/icewind/shelve.git synced 2026-06-03 03:54:10 +02:00

flake reorg + updates

This commit is contained in:
Robin Appelman 2024-12-01 17:29:24 +01:00
commit bde8457b34
12 changed files with 483 additions and 630 deletions

View file

@ -1,104 +1,17 @@
on: [push, pull_request]
name: Continuous integration
name: "CI"
on:
pull_request:
push:
jobs:
check:
checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20
- 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 .#check
clippy:
runs-on: ubuntu-latest
needs: check
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20
- 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@v3
- uses: cachix/install-nix-action@v20
- uses: icewind1991/attic-action@v1
with:
name: ci
instance: https://cache.icewind.me
authToken: '${{ secrets.ATTIC_TOKEN }}'
- run: nix build .#msrv
matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20
- id: set-matrix
run: echo "matrix=$(nix eval --json ".#matrix.x86_64-linux")" | tee $GITHUB_OUTPUT
build:
runs-on: ubuntu-latest
needs: [check, matrix]
strategy:
fail-fast: false
matrix: ${{fromJson(needs.matrix.outputs.matrix)}}
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20
- uses: icewind1991/attic-action@v1
with:
name: ci
instance: https://cache.icewind.me
authToken: '${{ secrets.ATTIC_TOKEN }}'
- run: nix build .#${{ matrix.target }}
- uses: actions/upload-artifact@v3
with:
name: shelve-${{ matrix.target }}
path: result/bin/shelve${{ matrix.artifactSuffix }}
build-nixpkgs:
runs-on: ubuntu-latest
needs: check
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20
- uses: icewind1991/attic-action@v1
with:
name: ci
instance: https://cache.icewind.me
authToken: '${{ secrets.ATTIC_TOKEN }}'
- run: nix build .#shelve
docker:
runs-on: ubuntu-latest
needs: build-nixpkgs
steps:
- name: Checkout code
uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20
- 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/master'
run: |
skopeo copy --dest-creds="${{ secrets.DOCKERHUB_USERNAME }}:${{ secrets.DOCKERHUB_TOKEN }}" "docker-archive:$(nix build .#docker --print-out-paths)" "docker://icewind1991/shelve"
authToken: "${{ secrets.ATTIC_TOKEN }}"
- run: nix flake check --keep-going

677
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -4,17 +4,17 @@ version = "0.1.0"
authors = ["Robin Appelman <robin@icewind.nl>"]
edition = "2018"
license = "MIT OR Apache-2.0"
rust-version = "1.69.0"
rust-version = "1.70.0"
[dependencies]
rocket = "0.5.0"
priority-queue = "1.3.2"
rocket = "0.5.1"
priority-queue = "2.1.1"
dotenvy = "0.15.7"
thiserror = "1.0.51"
thiserror = "2.0.3"
rand = "0.8.5"
uuid = { version = "1.6.1", features = ["serde", "v4"] }
rust-embed = "8.1.0"
serde = "1.0.193"
serde_json = "1.0.108"
async-trait = "0.1.75"
futures-util = "0.3.30"
uuid = { version = "1.11.0", features = ["serde", "v4"] }
rust-embed = "8.4.0"
serde = "1.0.215"
serde_json = "1.0.133"
async-trait = "0.1.83"
futures-util = "0.3.31"

View file

@ -12,8 +12,8 @@ Upload tokens are configured by setting the `TOKENS` environment variable to a c
Licensed under either of
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or https://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or https://opensource.org/licenses/MIT)
- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or https://opensource.org/licenses/MIT)
at your option.
@ -22,4 +22,4 @@ at your option.
Unless you explicitly state otherwise, any contribution intentionally
submitted for inclusion in the work by you, as defined in the Apache-2.0
license, shall be dual licensed as above, without any additional terms or
conditions.
conditions.

View file

@ -1,6 +1,6 @@
{
dockerTools,
shelve,
{ dockerTools
, shelve
,
}:
dockerTools.buildLayeredImage {
name = "icewind1991/shelve";
@ -11,9 +11,9 @@ dockerTools.buildLayeredImage {
dockerTools.caCertificates
];
config = {
Cmd = ["shelve"];
Cmd = [ "shelve" ];
ExposedPorts = {
"80/tcp" = {};
"80/tcp" = { };
};
Env = [
"ROCKET_ADDRESS=0.0.0.0"

136
flake.lock generated
View file

@ -1,105 +1,98 @@
{
"nodes": {
"cross-naersk": {
"crane": {
"locked": {
"lastModified": 1730060262,
"narHash": "sha256-RMgSVkZ9H03sxC+Vh4jxtLTCzSjPq18UWpiM0gq6shQ=",
"owner": "ipetkov",
"repo": "crane",
"rev": "498d9f122c413ee1154e8131ace5a35a80d8fa76",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"flakelight": {
"inputs": {
"naersk": [
"naersk"
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1732697024,
"narHash": "sha256-GcLauDQQI4xO4vy3e2QxPneR86FsJ1ubAbFDlTyEZ9s=",
"owner": "nix-community",
"repo": "flakelight",
"rev": "1af817b5987e78b7a260dff6d62793716b98d794",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "flakelight",
"type": "github"
}
},
"mill-scale": {
"inputs": {
"crane": "crane",
"flakelight": [
"flakelight"
],
"nixpkgs": [
"nixpkgs"
]
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1689107909,
"narHash": "sha256-fb+zxf7AWesECHx1foXOM3NcKHLrdeXzGb6s2AhT6pE=",
"lastModified": 1732306573,
"narHash": "sha256-wE12kIIE0qb9V9y0JiVm5RsRrMNX+KeeMwkzwefdHhY=",
"owner": "icewind1991",
"repo": "cross-naersk",
"rev": "51de54599de569e6faa2ee33dd659c5c028d9911",
"repo": "mill-scale",
"rev": "8b4cbf174a9728d7e58bbfde5b5a6685dcbf1015",
"type": "github"
},
"original": {
"owner": "icewind1991",
"repo": "cross-naersk",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1701680307,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"naersk": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1698420672,
"narHash": "sha256-/TdeHMPRjjdJub7p7+w55vyABrsJlt5QkznPYy55vKA=",
"owner": "nix-community",
"repo": "naersk",
"rev": "aeb58d5e8faead8980a807c840232697982d47b9",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "naersk",
"repo": "mill-scale",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1704420045,
"narHash": "sha256-C36QmoJd5tdQ5R9MC1jM7fBkZW9zBUqbUCsgwS6j4QU=",
"lastModified": 1732981179,
"narHash": "sha256-F7thesZPvAMSwjRu0K8uFshTk3ZZSNAsXTIFvXBT+34=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "c1be43e8e837b8dbee2b3665a007e761680f0c3d",
"rev": "62c435d93bf046a5396f3016472e8f7c8e2aed65",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-23.11",
"ref": "nixos-24.11",
"type": "indirect"
}
},
"root": {
"inputs": {
"cross-naersk": "cross-naersk",
"flake-utils": "flake-utils",
"naersk": "naersk",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"
"flakelight": "flakelight",
"mill-scale": "mill-scale",
"nixpkgs": "nixpkgs"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": [
"flake-utils"
],
"nixpkgs": [
"mill-scale",
"flakelight",
"nixpkgs"
]
},
"locked": {
"lastModified": 1704507282,
"narHash": "sha256-PDfS8fj40mm2QWpbd/aiocgwcI/WHzqLKERRJkoEvXU=",
"lastModified": 1731897198,
"narHash": "sha256-Ou7vLETSKwmE/HRQz4cImXXJBr/k9gp4J4z/PF8LzTE=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "a127cccf7943beae944953963ba118d643299c3b",
"rev": "0be641045af6d8666c11c2c40e45ffc9667839b5",
"type": "github"
},
"original": {
@ -107,21 +100,6 @@
"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",

142
flake.nix
View file

@ -1,118 +1,32 @@
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-23.11";
flake-utils.url = "github:numtide/flake-utils";
naersk.url = "github:nix-community/naersk";
naersk.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";
cross-naersk.url = "github:icewind1991/cross-naersk";
cross-naersk.inputs.nixpkgs.follows = "nixpkgs";
cross-naersk.inputs.naersk.follows = "naersk";
};
outputs = {
self,
nixpkgs,
flake-utils,
naersk,
rust-overlay,
cross-naersk,
}:
flake-utils.lib.eachDefaultSystem (
system: let
overlays = [
(import rust-overlay)
(import ./overlay.nix)
];
pkgs = (import nixpkgs) {
inherit system overlays;
};
inherit (pkgs) lib callPackage rust-bin mkShell;
inherit (lib.sources) sourceByRegex;
inherit (builtins) fromTOML readFile map;
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;
};
cross-naersk' = pkgs.callPackage cross-naersk {inherit naersk;};
buildMatrix = targets: {
include =
map (target: {
inherit target;
artifactSuffix = cross-naersk'.execSufficForTarget target;
})
targets;
};
hostTarget = pkgs.hostPlatform.config;
targets = [
"x86_64-unknown-linux-musl"
"x86_64-pc-windows-gnu"
hostTarget
];
releaseTargets = lib.lists.remove hostTarget targets;
src = sourceByRegex ./. ["Cargo.*" "(src|templates)(/.*)?"];
nearskOpt = {
pname = "shelve";
root = src;
};
in rec {
packages =
lib.attrsets.genAttrs targets (target:
(cross-naersk'.buildPackage target) nearskOpt)
// {
shelve = pkgs.shelve;
check = naersk'.buildPackage (nearskOpt
// {
mode = "check";
});
clippy = naersk'.buildPackage (nearskOpt
// {
mode = "clippy";
});
msrv = msrvNaersk.buildPackage (nearskOpt
// {
mode = "check";
});
docker = callPackage ./docker.nix {};
default = pkgs.shelve;
};
apps.default = packages.default;
matrix = buildMatrix targets;
releaseMatrix = buildMatrix releaseTargets;
devShells.default = mkShell {
nativeBuildInputs = with pkgs; [toolchain bacon cargo-msrv];
};
}
)
// {
overlays.default = import ./overlay.nix;
nixosModules.default = {
pkgs,
config,
lib,
...
}: {
imports = [./module.nix];
config = lib.mkIf config.services.shelve.enable {
nixpkgs.overlays = [self.overlays.default];
services.shelve.package = lib.mkDefault pkgs.shelve;
};
};
nixpkgs.url = "nixpkgs/nixos-24.11";
flakelight = {
url = "github:nix-community/flakelight";
inputs.nixpkgs.follows = "nixpkgs";
};
mill-scale = {
url = "github:icewind1991/mill-scale";
inputs.flakelight.follows = "flakelight";
};
};
outputs = { mill-scale, ... }: mill-scale ./. {
extraPaths = [
./templates
];
nixosModules = { outputs, ... }: {
default =
{ pkgs
, config
, lib
, ...
}: {
imports = [ ./nix/module.nix ];
config = lib.mkIf config.services.shelve.enable {
nixpkgs.overlays = [ outputs.overlays.default ];
services.shelve.package = lib.mkDefault pkgs.shelve;
};
};
};
};
}

View file

@ -1,12 +1,12 @@
{
config,
lib,
pkgs,
...
{ config
, lib
, pkgs
, ...
}:
with lib; let
cfg = config.services.shelve;
in {
in
{
options.services.shelve = {
enable = mkEnableOption "Enables the shelve service";
@ -24,8 +24,8 @@ in {
tokens = mkOption {
type = types.listOf types.str;
default = [];
example = ["foo" "bar"];
default = [ ];
example = [ "foo" "bar" ];
description = "upload tokens";
};
@ -51,14 +51,14 @@ in {
config = mkIf cfg.enable {
networking.firewall.allowedTCPPorts = lib.optional cfg.openPort cfg.port;
users.groups.shelve = {};
users.groups.shelve = { };
users.users.shelve = {
isSystemUser = true;
group = "shelve";
};
systemd.services.shelve = {
wantedBy = ["multi-user.target"];
wantedBy = [ "multi-user.target" ];
environment = {
ROCKET_PORT = toString cfg.port;
ROCKET_ADDRESS = cfg.bindAddress;

3
nix/overlay.nix Normal file
View file

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

21
nix/package.nix Normal file
View file

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

View file

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

View file

@ -1,18 +0,0 @@
{
stdenv,
rustPlatform,
lib,
}: let
inherit (lib.sources) sourceByRegex;
src = sourceByRegex ./. ["Cargo.*" "(src|templates)(/.*)?"];
in
rustPlatform.buildRustPackage rec {
pname = "shelve";
version = "0.1.0";
inherit src;
cargoLock = {
lockFile = ./Cargo.lock;
};
}