flake rework

This commit is contained in:
Robin Appelman 2024-11-21 15:03:38 +01:00
commit 8f9eeadb74
20 changed files with 256 additions and 382 deletions

View file

@ -4,65 +4,29 @@ on:
push:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
machine:
- platform: x86_64-linux
- platform: aarch64-linux
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- if: matrix.machine.platform != 'x86_64-linux'
uses: docker/setup-qemu-action@v3
- uses: cachix/install-nix-action@v26
with:
extra_nix_config: |
extra-platforms = aarch64-linux
- uses: icewind1991/attic-action@v1
with:
name: ci
instance: https://cache.icewind.me
authToken: '${{ secrets.ATTIC_TOKEN }}'
- run: nix build --option system ${{ matrix.machine.platform }} .#frontend
- uses: cachix/install-nix-action@v27
- id: set-matrix
run: echo "matrix={\"check\":$(nix eval --json '.#checks.x86_64-linux' --apply 'builtins.attrNames')}" | tee -a $GITHUB_OUTPUT
build-docker:
checks:
runs-on: ubuntu-latest
needs: [build]
needs: [matrix]
strategy:
matrix:
machine:
- platform: x86_64-linux
- platform: aarch64-linux
fail-fast: false
matrix: ${{fromJson(needs.matrix.outputs.matrix)}}
name: ${{ matrix.check }}
steps:
- uses: actions/checkout@v4
- if: matrix.machine.platform != 'x86_64-linux'
uses: docker/setup-qemu-action@v3
- uses: cachix/install-nix-action@v26
with:
extra_nix_config: |
extra-platforms = aarch64-linux
- uses: icewind1991/attic-action@v1
with:
name: ci
instance: https://cache.icewind.me
authToken: '${{ secrets.ATTIC_TOKEN }}'
- run: nix build --option system ${{ matrix.machine.platform }} .#docker
docker:
runs-on: ubuntu-latest
needs: [build-docker]
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
- run: nix run .#dockerManifest
if: github.ref == 'refs/heads/main'
env:
VERSION: "1.0.0"
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
authToken: "${{ secrets.ATTIC_TOKEN }}"
- run: nix build .#checks.x86_64-linux.${{ matrix.check }}

View file

@ -45,20 +45,9 @@
}
],
"parameters": {
"Left": [
"Int4"
]
"Left": ["Int4"]
},
"nullable": [
null,
null,
null,
null,
null,
null,
null,
null
]
"nullable": [null, null, null, null, null, null, null, null]
},
"hash": "047f7ac22872178be671d3994baec9116658520f0ff83d09ae8321ac096b28de"
}

View file

@ -52,17 +52,7 @@
"parameters": {
"Left": []
},
"nullable": [
false,
false,
false,
false,
false,
false,
false,
false,
false
]
"nullable": [false, false, false, false, false, false, false, false, false]
},
"hash": "05e9dfee9d5ee8ea3bd13d7433ba0ba39ed00ab0ffb0c3fc9021921382be00bd"
}

View file

@ -15,14 +15,9 @@
}
],
"parameters": {
"Left": [
"Text"
]
"Left": ["Text"]
},
"nullable": [
false,
false
]
"nullable": [false, false]
},
"hash": "44fdd79c15ce83bff64db5558711a40d097ff41c029e096f29138a1d5bbc8762"
}

View file

@ -20,15 +20,9 @@
}
],
"parameters": {
"Left": [
"Int4"
]
"Left": ["Int4"]
},
"nullable": [
false,
false,
false
]
"nullable": [false, false, false]
},
"hash": "4c62efff159fa311007f71db061e4eeb040c79977f0c452065d5361fb134b0d3"
}

View file

@ -4,12 +4,7 @@
"describe": {
"columns": [],
"parameters": {
"Left": [
"Varchar",
"Varchar",
"Varchar",
"Varchar"
]
"Left": ["Varchar", "Varchar", "Varchar", "Varchar"]
},
"nullable": []
},

View file

@ -15,14 +15,9 @@
}
],
"parameters": {
"Left": [
"Text"
]
"Left": ["Text"]
},
"nullable": [
true,
true
]
"nullable": [true, true]
},
"hash": "5073fab60c719e464b592393d94372067be0ea36e4a1d138646f496b8cad56c7"
}

View file

@ -90,9 +90,7 @@
}
],
"parameters": {
"Left": [
"Int4"
]
"Left": ["Int4"]
},
"nullable": [
false,

View file

@ -12,9 +12,7 @@
"parameters": {
"Left": []
},
"nullable": [
true
]
"nullable": [true]
},
"hash": "af217d7d86c606e4d76bd0c79a2551ed5d423b3900cb1d6d8b0fe3789414eb27"
}

View file

@ -11,11 +11,7 @@ use std::path::Path;
pub fn bundle_style(style: &str) -> Vec<u8> {
// todo build time?
let fs = FileProvider::new();
let mut bundler = Bundler::new(
&fs,
None,
ParserOptions::default(),
);
let mut bundler = Bundler::new(&fs, None, ParserOptions::default());
let mut stylesheet = bundler
.bundle(Path::new(style))
.expect("failed to bundle css");

View file

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

205
flake.lock generated
View file

@ -1,113 +1,77 @@
{
"nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"crane": {
"locked": {
"lastModified": 1701473968,
"narHash": "sha256-YcVE5emp1qQ8ieHUnxt1wCZCC3ZfAS+SRRWZ2TMda7E=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "34fed993f1674c8d06d58b37ce1e0fe5eebcb9f5",
"lastModified": 1730060262,
"narHash": "sha256-RMgSVkZ9H03sxC+Vh4jxtLTCzSjPq18UWpiM0gq6shQ=",
"owner": "ipetkov",
"repo": "crane",
"rev": "498d9f122c413ee1154e8131ace5a35a80d8fa76",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"flake-utils": {
"flakelight": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1705309234,
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flocken": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": [
"nixpkgs"
],
"systems": "systems"
]
},
"locked": {
"lastModified": 1704105102,
"narHash": "sha256-c4VWO9plhINjQzYPHSKURWgQ2D2q24aI3OIN0MTPjz0=",
"owner": "mirkolenz",
"repo": "flocken",
"rev": "3a846dfca17f989805d9f4177de85c96dc0f8542",
"lastModified": 1731933812,
"narHash": "sha256-PeuRDDq1DcHxbOmXWb3nWMp5PqWUn5PSKimNbUzWEaQ=",
"owner": "nix-community",
"repo": "flakelight",
"rev": "f4b26f683be5c9ac1ec05f968dbbcb35f4bb6346",
"type": "github"
},
"original": {
"owner": "mirkolenz",
"ref": "v2",
"repo": "flocken",
"owner": "nix-community",
"repo": "flakelight",
"type": "github"
}
},
"mill-scale": {
"inputs": {
"crane": "crane",
"flakelight": [
"flakelight"
],
"rust-overlay": "rust-overlay"
},
"locked": {
"lastModified": 1732197065,
"narHash": "sha256-Lyosd/rJHFp1xnWPNhukQkW1hFtIiIiVDxQ+fcVypgI=",
"owner": "icewind1991",
"repo": "mill-scale",
"rev": "8051d162308a80dde168b7efe012bfa1363be4ba",
"type": "github"
},
"original": {
"owner": "icewind1991",
"repo": "mill-scale",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1717763955,
"narHash": "sha256-KTFz7DM0eHpsvuXky0xOmDSp+dCSsB2ODH69UDaGdIs=",
"lastModified": 1731797254,
"narHash": "sha256-df3dJApLPhd11AlueuoN0Q4fHo/hagP75LlM5K1sz9g=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "4984dd33b2b489065500233eae7defc4659c3c59",
"rev": "e8c38b73aeb218e27163376a2d617e61a2ad9b59",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "release-24.05",
"ref": "nixos-24.05",
"type": "indirect"
}
},
"nixpkgs-lib": {
"locked": {
"dir": "lib",
"lastModified": 1701253981,
"narHash": "sha256-ztaDIyZ7HrTAfEEUt9AtTDNoCYxUdSd6NrRHaYOIxtk=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e92039b55bcd58469325ded85d4f58dd5a4eaf58",
"type": "github"
},
"original": {
"dir": "lib",
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1706487304,
"narHash": "sha256-LE8lVX28MV2jWJsidW13D2qrHU/RUUONendL2Q/WlJg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "90f456026d284c22b3e3497be980b2e47d0b28ac",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"npmlock2nix": {
"flake": false,
"locked": {
@ -126,24 +90,26 @@
},
"root": {
"inputs": {
"flocken": "flocken",
"flakelight": "flakelight",
"mill-scale": "mill-scale",
"nixpkgs": "nixpkgs",
"npmlock2nix": "npmlock2nix",
"rust-overlay": "rust-overlay",
"utils": "utils"
"npmlock2nix": "npmlock2nix"
}
},
"rust-overlay": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs_2"
"nixpkgs": [
"mill-scale",
"flakelight",
"nixpkgs"
]
},
"locked": {
"lastModified": 1717726729,
"narHash": "sha256-2WDKLjVRKWXbadnJHSOUb46PTq3D5nS89vhHTphRw1M=",
"lastModified": 1731897198,
"narHash": "sha256-Ou7vLETSKwmE/HRQz4cImXXJBr/k9gp4J4z/PF8LzTE=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "7f52ac9ae95bd60c0780d6e32baea22e542e11e1",
"rev": "0be641045af6d8666c11c2c40e45ffc9667839b5",
"type": "github"
},
"original": {
@ -151,69 +117,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"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_3": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"utils": {
"inputs": {
"systems": "systems_3"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
}
},
"root": "root",

View file

@ -1,82 +1,46 @@
{
inputs = {
utils.url = "github:numtide/flake-utils";
nixpkgs.url = "nixpkgs/release-24.05";
rust-overlay.url = "github:oxalica/rust-overlay";
npmlock2nix.url = "github:nix-community/npmlock2nix";
npmlock2nix.flake = false;
flocken = {
url = "github:mirkolenz/flocken/v2";
nixpkgs.url = "nixpkgs/nixos-24.05";
flakelight = {
url = "github:nix-community/flakelight";
inputs.nixpkgs.follows = "nixpkgs";
};
mill-scale = {
url = "github:icewind1991/mill-scale";
inputs.flakelight.follows = "flakelight";
};
outputs = {
self,
nixpkgs,
utils,
rust-overlay,
npmlock2nix,
flocken,
}:
utils.lib.eachDefaultSystem (system: let
overlays = [
(import rust-overlay)
npmlock2nix = {
url = "github:nix-community/npmlock2nix";
flake = false;
};
};
outputs = { mill-scale, npmlock2nix, ... }: mill-scale ./. {
packageOpts = { demostf-frontend-node-modules, ... }: {
preBuild = ''
ln -s ${demostf-frontend-node-modules}/node_modules .
'';
};
extraPaths = [
./.sqlx
./images
./script
./style
];
withOverlays = [
(final: prev: {
npmlock2nix = final.callPackage npmlock2nix {};
npmlock2nix = final.callPackage npmlock2nix { };
})
(final: prev: {
demostf-frontend-toolchain = final.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
})
(import ./overlay.nix)
(final: prev: {
demostf-frontend-toolchain = final.rust-bin.nightly."2024-06-04".default;
})
];
pkgs = (import nixpkgs) {
inherit system overlays;
};
inherit (flocken.legacyPackages.${system}) mkDockerManifest;
inherit (builtins) fromTOML readFile;
version = (fromTOML (readFile ./Cargo.toml)).package.version;
in rec {
packages = rec {
node_modules = pkgs.demostf-frontend-node-modules;
frontend = pkgs.demostf-frontend;
docker = pkgs.demostf-frontend-docker;
default = frontend;
dockerManifest = mkDockerManifest {
tags = ["latest"];
registries = {
"docker.io" = {
enable = true;
repo = "demostf/frontend";
username = "$DOCKERHUB_USERNAME";
password = "$DOCKERHUB_TOKEN";
};
};
inherit version;
images = with self.packages; [x86_64-linux.docker aarch64-linux.docker];
};
};
devShells.default = pkgs.mkShell {
OPENSSL_NO_VENDOR = 1;
nativeBuildInputs = with pkgs; [
demostf-frontend-toolchain
bacon
cargo-edit
cargo-outdated
clippy
cargo-audit
cargo-watch
pkg-config
openssl
toolchain = pkgs: pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
tools = pkgs: with pkgs; [
nodejs
nodePackages.svgo
typescript
sqlx-cli
];
};
}) // {
overlays.default = import ./overlay.nix;
};
}

86
flake_.nix Normal file
View file

@ -0,0 +1,86 @@
{
inputs = {
utils.url = "github:numtide/flake-utils";
nixpkgs.url = "nixpkgs/release-24.05";
rust-overlay.url = "github:oxalica/rust-overlay";
npmlock2nix.url = "github:nix-community/npmlock2nix";
npmlock2nix.flake = false;
flocken = {
url = "github:mirkolenz/flocken/v2";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{ self
, nixpkgs
, utils
, rust-overlay
, npmlock2nix
, flocken
,
}:
utils.lib.eachDefaultSystem
(system:
let
overlays = [
(import rust-overlay)
(final: prev: {
npmlock2nix = final.callPackage npmlock2nix { };
})
(import ./overlay.nix)
(final: prev: {
demostf-frontend-toolchain = final.rust-bin.nightly."2024-06-04".default;
})
];
pkgs = (import nixpkgs) {
inherit system overlays;
};
inherit (flocken.legacyPackages.${system}) mkDockerManifest;
inherit (builtins) fromTOML readFile;
version = (fromTOML (readFile ./Cargo.toml)).package.version;
in
rec {
packages = rec {
node_modules = pkgs.demostf-frontend-node-modules;
frontend = pkgs.demostf-frontend;
docker = pkgs.demostf-frontend-docker;
default = frontend;
dockerManifest = mkDockerManifest {
tags = [ "latest" ];
registries = {
"docker.io" = {
enable = true;
repo = "demostf/frontend";
username = "$DOCKERHUB_USERNAME";
password = "$DOCKERHUB_TOKEN";
};
};
inherit version;
images = with self.packages; [ x86_64-linux.docker aarch64-linux.docker ];
};
};
devShells.default = pkgs.mkShell {
OPENSSL_NO_VENDOR = 1;
nativeBuildInputs = with pkgs; [
demostf-frontend-toolchain
bacon
cargo-edit
cargo-outdated
clippy
cargo-audit
cargo-watch
pkg-config
openssl
nodejs
nodePackages.svgo
typescript
sqlx-cli
];
};
}) // {
overlays.default = import ./overlay.nix;
};
}

View file

@ -1,11 +1,10 @@
{
config,
lib,
pkgs,
...
{ config
, lib
, pkgs
, ...
}:
with lib; let
format = pkgs.formats.toml {};
format = pkgs.formats.toml { };
configFile = format.generate "demostf-frontend.toml" {
output.target = cfg.outputPath;
mqtt = {
@ -15,7 +14,8 @@ with lib; let
device."password-file" = "$CREDENTIALS_DIRECTORY/device_password";
};
cfg = config.services.demostf-frontend;
in {
in
{
options.services.demostf-frontend = {
enable = mkEnableOption "Log archiver";
@ -77,7 +77,7 @@ in {
"mqtt_password:${cfg.mqtt.passwordFile}"
"device_password:${cfg.devicePasswordFile}"
];
ReadWritePaths = [cfg.outputPath];
ReadWritePaths = [ cfg.outputPath ];
Restart = "on-failure";
DynamicUser = true;
PrivateTmp = true;
@ -99,7 +99,7 @@ in {
RestrictAddressFamilies = "AF_INET AF_INET6";
RestrictRealtime = true;
ProtectProc = "noaccess";
SystemCallFilter = ["@system-service" "~@resources" "~@privileged"];
SystemCallFilter = [ "@system-service" "~@resources" "~@privileged" ];
IPAddressDeny = "multicast";
PrivateUsers = true;
ProcSubset = "pid";
@ -112,7 +112,7 @@ in {
inherit (config.systemd.services."demostf-frontend") description;
enable = true;
wantedBy = ["multi-user.target"];
wantedBy = [ "multi-user.target" ];
timerConfig = {
OnCalendar = cfg.interval;
RandomizedDelaySec = "15m";

View file

@ -1,10 +1,12 @@
{
npmlock2nix,
nodejs_20,
lib,
}: let
{ npmlock2nix
, nodejs_20
, lib
,
}:
let
inherit (lib.sources) sourceByRegex;
in npmlock2nix.v2.node_modules {
src = sourceByRegex ./. ["package.*"];
in
npmlock2nix.v2.node_modules {
src = sourceByRegex ./. [ "package.*" ];
nodejs = nodejs_20;
}

View file

@ -1,5 +1,5 @@
prev: final: {
demostf-frontend-node-modules = final.callPackage ./node_modules.nix {};
demostf-frontend = final.callPackage ./package.nix {};
demostf-frontend-docker = final.callPackage ./docker.nix {};
demostf-frontend-node-modules = final.callPackage ./node_modules.nix { };
demostf-frontend = final.callPackage ./package.nix { };
demostf-frontend-docker = final.callPackage ./docker.nix { };
}

View file

@ -1,27 +1,28 @@
{
stdenv,
makeRustPlatform,
lib,
demostf-frontend-toolchain,
pkg-config,
openssl,
demostf-frontend-node-modules,
}: let
{ stdenv
, makeRustPlatform
, lib
, demostf-frontend-toolchain
, pkg-config
, openssl
, demostf-frontend-node-modules
,
}:
let
inherit (lib.sources) sourceByRegex;
rustPlatform = makeRustPlatform {
rustc = demostf-frontend-toolchain;
cargo = demostf-frontend-toolchain;
};
in
rustPlatform.buildRustPackage rec {
rustPlatform.buildRustPackage rec {
pname = "demostf-frontend";
version = "0.1.0";
src = sourceByRegex ./. ["Cargo.*" "(src|build|images|script|style|.sqlx)(/.*)?"];
src = sourceByRegex ./. [ "Cargo.*" "(src|build|images|script|style|.sqlx)(/.*)?" ];
buildInputs = [openssl];
buildInputs = [ openssl ];
nativeBuildInputs = [pkg-config];
nativeBuildInputs = [ pkg-config ];
preBuild = ''
ln -s ${demostf-frontend-node-modules}/node_modules .
@ -35,4 +36,4 @@ in
"jsx-dom-expressions-0.1.0" = "sha256-5TN9FBfPYznTkpL9ZtnKv3RghX7r8c2WvSL1sc+F0cw=";
};
};
}
}

4
rust-toolchain.toml Normal file
View file

@ -0,0 +1,4 @@
[toolchain]
channel = "nightly-2024-11-18"
components = [ "rustfmt", "rust-std", "clippy", "rust-src" ]
targets = [ "riscv32imc-unknown-none-elf" ]