refactor: improve flake
This commit is contained in:
parent
14b4baf6e3
commit
86ec666da3
5 changed files with 58 additions and 56 deletions
|
@ -1,3 +0,0 @@
|
||||||
[target.x86_64-unknown-linux-gnu]
|
|
||||||
linker = "clang"
|
|
||||||
|
|
18
flake.lock
18
flake.lock
|
@ -28,11 +28,11 @@
|
||||||
"rust-analyzer-src": "rust-analyzer-src"
|
"rust-analyzer-src": "rust-analyzer-src"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1705731714,
|
"lastModified": 1705818179,
|
||||||
"narHash": "sha256-aMeN/ASG4n7RIIPLiy+txoMdDTvIcaRDX6acbeeRtEU=",
|
"narHash": "sha256-eNlzk9S9MiV8h1Z4vYpNWHrgFh0wkJCoSPDLhMYEJhU=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "fenix",
|
"repo": "fenix",
|
||||||
"rev": "712f25ec7e1f5839d486b246a5afa5e31f5df6ff",
|
"rev": "40f11d5591036cd03dffaae9aea1d3fec3c62b54",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -61,11 +61,11 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1705496572,
|
"lastModified": 1705677747,
|
||||||
"narHash": "sha256-rPIe9G5EBLXdBdn9ilGc0nq082lzQd0xGGe092R/5QE=",
|
"narHash": "sha256-eyM3okYtMgYDgmYukoUzrmuoY4xl4FUujnsv/P6I/zI=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "842d9d80cfd4560648c785f8a4e6f3b096790e19",
|
"rev": "bbe7d8f876fbbe7c959c90ba2ae2852220573261",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -85,11 +85,11 @@
|
||||||
"rust-analyzer-src": {
|
"rust-analyzer-src": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1705697225,
|
"lastModified": 1705767842,
|
||||||
"narHash": "sha256-eLMwix3LPsgqnbdLMWivBCSBrWnaAA50JtMNnInTopg=",
|
"narHash": "sha256-lBvKPxeJ/UJPBxncu622hts0xbYfmo2GYu5E7K3MZt0=",
|
||||||
"owner": "rust-lang",
|
"owner": "rust-lang",
|
||||||
"repo": "rust-analyzer",
|
"repo": "rust-analyzer",
|
||||||
"rev": "67cfbf231c1e2ba3129529de950d1c4ca7921404",
|
"rev": "a9116523604c998e7781f60d3b5a6f586e0414a9",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
78
flake.nix
78
flake.nix
|
@ -1,53 +1,55 @@
|
||||||
{
|
{
|
||||||
inputs = {
|
inputs = {
|
||||||
crane = {
|
crane.url = "github:ipetkov/crane";
|
||||||
url = "github:ipetkov/crane";
|
crane.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
inputs = {
|
fenix.url = "github:nix-community/fenix";
|
||||||
flake-utils.follows = "flake-utils";
|
fenix.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
nixpkgs.follows = "nixpkgs";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
fenix = {
|
|
||||||
url = "github:nix-community/fenix";
|
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
|
||||||
};
|
|
||||||
flake-utils.url = "github:numtide/flake-utils";
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
nixpkgs.url = "nixpkgs/nixos-unstable";
|
nixpkgs.url = "nixpkgs/nixos-unstable";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, crane, fenix, flake-utils, nixpkgs }:
|
outputs = { self, crane, flake-utils, nixpkgs, ... }@inputs:
|
||||||
flake-utils.lib.eachDefaultSystem (system:
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
let
|
let
|
||||||
pkgs = (import nixpkgs) {
|
inherit (pkgs) lib;
|
||||||
inherit system;
|
pkgs = import nixpkgs { inherit system; };
|
||||||
};
|
fenix = inputs.fenix.packages.${system};
|
||||||
toolchain = fenix.packages.${system}.stable;
|
|
||||||
craneLib = crane.lib.${system}.overrideToolchain toolchain.toolchain;
|
craneLib = crane.lib.${system}.overrideToolchain toolchain.toolchain;
|
||||||
|
mkSrc = extraPaths: with lib.fileset; let
|
||||||
|
root = ./.;
|
||||||
|
rustFiles = fromSource (craneLib.cleanCargoSource root);
|
||||||
|
fileset = union rustFiles (unions extraPaths);
|
||||||
|
in
|
||||||
|
toSource { inherit root fileset; };
|
||||||
|
|
||||||
|
## Customize here ##
|
||||||
|
toolchain = fenix.complete; # or fenix.stable;
|
||||||
|
stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.stdenv;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
packages.default =
|
packages.default = craneLib.buildPackage {
|
||||||
let
|
inherit stdenv;
|
||||||
inherit (pkgs.lib) fileset;
|
src = mkSrc [ ./templates ];
|
||||||
in
|
strictDeps = true;
|
||||||
craneLib.buildPackage {
|
buildInputs = pkgs.stdenv.isDarwin [
|
||||||
src = fileset.toSource {
|
pkgs.libiconv
|
||||||
root = ./.;
|
];
|
||||||
fileset = fileset.intersection
|
};
|
||||||
(fileset.difference ./.
|
|
||||||
(fileset.unions [ ./.cargo ./flake.nix ./flake.lock ./.envrc ]))
|
|
||||||
(fileset.gitTracked ./.);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
devShell = pkgs.mkShell.override
|
devShells.default = pkgs.mkShell.override { inherit stdenv; }
|
||||||
{
|
{
|
||||||
stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.clangStdenv;
|
nativeBuildInputs = with pkgs; [
|
||||||
}
|
entr
|
||||||
{
|
htmx-lsp
|
||||||
nativeBuildInputs = with toolchain;
|
] ++ (with toolchain; [
|
||||||
[ rustc cargo rust-analyzer clippy ] ++ (with pkgs;
|
cargo
|
||||||
[ entr ]
|
clippy
|
||||||
);
|
rustfmt
|
||||||
|
rustc
|
||||||
|
fenix.rust-analyzer
|
||||||
|
]);
|
||||||
|
RUST_SRC_PATH = "${toolchain.rust-src}/lib/rustlib/src/rust/library";
|
||||||
};
|
};
|
||||||
});
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
1
rustfmt.toml
Normal file
1
rustfmt.toml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
edition = "2021"
|
14
src/main.rs
14
src/main.rs
|
@ -1,12 +1,12 @@
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
use actix_web::{App, HttpServer};
|
|
||||||
use actix_web::web;
|
use actix_web::web;
|
||||||
|
use actix_web::{App, HttpServer};
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct AppState {
|
struct AppState {
|
||||||
counter: Mutex<i32>
|
counter: Mutex<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
|
@ -25,7 +25,9 @@ struct IndexTemplate {
|
||||||
async fn index(data: web::Data<AppState>) -> impl actix_web::Responder {
|
async fn index(data: web::Data<AppState>) -> impl actix_web::Responder {
|
||||||
let counter = data.counter.lock().unwrap();
|
let counter = data.counter.lock().unwrap();
|
||||||
let counter_template = CounterTemplate { counter: *counter };
|
let counter_template = CounterTemplate { counter: *counter };
|
||||||
IndexTemplate { counter: counter_template }
|
IndexTemplate {
|
||||||
|
counter: counter_template,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_web::post("/api/increment")]
|
#[actix_web::post("/api/increment")]
|
||||||
|
@ -47,10 +49,10 @@ async fn main() -> std::io::Result<()> {
|
||||||
std::env::set_var("RUST_LOG", "debug");
|
std::env::set_var("RUST_LOG", "debug");
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
println!("Starting webserver on port 8080");
|
println!("Starting webserver on port 8080");
|
||||||
let app_state = web::Data::new( AppState {
|
let app_state = web::Data::new(AppState {
|
||||||
counter: Mutex::new(0)
|
counter: Mutex::new(0),
|
||||||
});
|
});
|
||||||
HttpServer::new(move|| {
|
HttpServer::new(move || {
|
||||||
App::new()
|
App::new()
|
||||||
.app_data(app_state.clone())
|
.app_data(app_state.clone())
|
||||||
.service(index)
|
.service(index)
|
||||||
|
|
Loading…
Reference in a new issue