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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,6 +1,6 @@
{ { dockerTools
dockerTools, , demostf-frontend
demostf-frontend, ,
}: }:
dockerTools.buildLayeredImage { dockerTools.buildLayeredImage {
name = "demostf/frontend"; name = "demostf/frontend";

205
flake.lock generated
View file

@ -1,113 +1,77 @@
{ {
"nodes": { "nodes": {
"flake-parts": { "crane": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": { "locked": {
"lastModified": 1701473968, "lastModified": 1730060262,
"narHash": "sha256-YcVE5emp1qQ8ieHUnxt1wCZCC3ZfAS+SRRWZ2TMda7E=", "narHash": "sha256-RMgSVkZ9H03sxC+Vh4jxtLTCzSjPq18UWpiM0gq6shQ=",
"owner": "hercules-ci", "owner": "ipetkov",
"repo": "flake-parts", "repo": "crane",
"rev": "34fed993f1674c8d06d58b37ce1e0fe5eebcb9f5", "rev": "498d9f122c413ee1154e8131ace5a35a80d8fa76",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "hercules-ci", "owner": "ipetkov",
"repo": "flake-parts", "repo": "crane",
"type": "github" "type": "github"
} }
}, },
"flake-utils": { "flakelight": {
"inputs": { "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": [
"nixpkgs" "nixpkgs"
], ]
"systems": "systems"
}, },
"locked": { "locked": {
"lastModified": 1704105102, "lastModified": 1731933812,
"narHash": "sha256-c4VWO9plhINjQzYPHSKURWgQ2D2q24aI3OIN0MTPjz0=", "narHash": "sha256-PeuRDDq1DcHxbOmXWb3nWMp5PqWUn5PSKimNbUzWEaQ=",
"owner": "mirkolenz", "owner": "nix-community",
"repo": "flocken", "repo": "flakelight",
"rev": "3a846dfca17f989805d9f4177de85c96dc0f8542", "rev": "f4b26f683be5c9ac1ec05f968dbbcb35f4bb6346",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "mirkolenz", "owner": "nix-community",
"ref": "v2", "repo": "flakelight",
"repo": "flocken", "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" "type": "github"
} }
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1717763955, "lastModified": 1731797254,
"narHash": "sha256-KTFz7DM0eHpsvuXky0xOmDSp+dCSsB2ODH69UDaGdIs=", "narHash": "sha256-df3dJApLPhd11AlueuoN0Q4fHo/hagP75LlM5K1sz9g=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "4984dd33b2b489065500233eae7defc4659c3c59", "rev": "e8c38b73aeb218e27163376a2d617e61a2ad9b59",
"type": "github" "type": "github"
}, },
"original": { "original": {
"id": "nixpkgs", "id": "nixpkgs",
"ref": "release-24.05", "ref": "nixos-24.05",
"type": "indirect" "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": { "npmlock2nix": {
"flake": false, "flake": false,
"locked": { "locked": {
@ -126,24 +90,26 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"flocken": "flocken", "flakelight": "flakelight",
"mill-scale": "mill-scale",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"npmlock2nix": "npmlock2nix", "npmlock2nix": "npmlock2nix"
"rust-overlay": "rust-overlay",
"utils": "utils"
} }
}, },
"rust-overlay": { "rust-overlay": {
"inputs": { "inputs": {
"flake-utils": "flake-utils", "nixpkgs": [
"nixpkgs": "nixpkgs_2" "mill-scale",
"flakelight",
"nixpkgs"
]
}, },
"locked": { "locked": {
"lastModified": 1717726729, "lastModified": 1731897198,
"narHash": "sha256-2WDKLjVRKWXbadnJHSOUb46PTq3D5nS89vhHTphRw1M=", "narHash": "sha256-Ou7vLETSKwmE/HRQz4cImXXJBr/k9gp4J4z/PF8LzTE=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "7f52ac9ae95bd60c0780d6e32baea22e542e11e1", "rev": "0be641045af6d8666c11c2c40e45ffc9667839b5",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -151,69 +117,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"
}
},
"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", "root": "root",

View file

@ -1,82 +1,46 @@
{ {
inputs = { inputs = {
utils.url = "github:numtide/flake-utils"; nixpkgs.url = "nixpkgs/nixos-24.05";
nixpkgs.url = "nixpkgs/release-24.05"; flakelight = {
rust-overlay.url = "github:oxalica/rust-overlay"; url = "github:nix-community/flakelight";
npmlock2nix.url = "github:nix-community/npmlock2nix";
npmlock2nix.flake = false;
flocken = {
url = "github:mirkolenz/flocken/v2";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
mill-scale = {
url = "github:icewind1991/mill-scale";
inputs.flakelight.follows = "flakelight";
}; };
npmlock2nix = {
outputs = { url = "github:nix-community/npmlock2nix";
self, flake = false;
nixpkgs, };
utils, };
rust-overlay, outputs = { mill-scale, npmlock2nix, ... }: mill-scale ./. {
npmlock2nix, packageOpts = { demostf-frontend-node-modules, ... }: {
flocken, preBuild = ''
}: ln -s ${demostf-frontend-node-modules}/node_modules .
utils.lib.eachDefaultSystem (system: let '';
overlays = [ };
(import rust-overlay) extraPaths = [
./.sqlx
./images
./script
./style
];
withOverlays = [
(final: prev: { (final: prev: {
npmlock2nix = final.callPackage npmlock2nix { }; npmlock2nix = final.callPackage npmlock2nix { };
}) })
(import ./overlay.nix)
(final: prev: { (final: prev: {
demostf-frontend-toolchain = final.rust-bin.nightly."2024-06-04".default; demostf-frontend-toolchain = final.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
}) })
(import ./overlay.nix)
]; ];
pkgs = (import nixpkgs) { toolchain = pkgs: pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
inherit system overlays; tools = pkgs: with pkgs; [
};
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 nodejs
nodePackages.svgo nodePackages.svgo
typescript typescript
sqlx-cli 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,8 +1,7 @@
{ { config
config, , lib
lib, , pkgs
pkgs, , ...
...
}: }:
with lib; let with lib; let
format = pkgs.formats.toml { }; format = pkgs.formats.toml { };
@ -15,7 +14,8 @@ with lib; let
device."password-file" = "$CREDENTIALS_DIRECTORY/device_password"; device."password-file" = "$CREDENTIALS_DIRECTORY/device_password";
}; };
cfg = config.services.demostf-frontend; cfg = config.services.demostf-frontend;
in { in
{
options.services.demostf-frontend = { options.services.demostf-frontend = {
enable = mkEnableOption "Log archiver"; enable = mkEnableOption "Log archiver";

View file

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

View file

@ -1,12 +1,13 @@
{ { stdenv
stdenv, , makeRustPlatform
makeRustPlatform, , lib
lib, , demostf-frontend-toolchain
demostf-frontend-toolchain, , pkg-config
pkg-config, , openssl
openssl, , demostf-frontend-node-modules
demostf-frontend-node-modules, ,
}: let }:
let
inherit (lib.sources) sourceByRegex; inherit (lib.sources) sourceByRegex;
rustPlatform = makeRustPlatform { rustPlatform = makeRustPlatform {
rustc = demostf-frontend-toolchain; rustc = demostf-frontend-toolchain;

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" ]