1
Fork 0

Update flake to add package

This commit is contained in:
Tobias Berger 2024-05-02 20:39:19 +02:00
parent 0768ed5ebc
commit c82cd98302
Signed by: toby
GPG key ID: 2D05EFAB764D6A88
9 changed files with 135 additions and 99 deletions

View file

@ -1,3 +0,0 @@
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=mold"]

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
/target /target
.direnv .direnv
result

2
Cargo.lock generated
View file

@ -296,7 +296,7 @@ checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
[[package]] [[package]]
name = "minesweeper-nojs" name = "minesweeper-nojs"
version = "0.1.2" version = "0.1.3"
dependencies = [ dependencies = [
"http-body-util", "http-body-util",
"hyper", "hyper",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "minesweeper-nojs" name = "minesweeper-nojs"
version = "0.1.2" version = "0.1.3"
edition = "2021" edition = "2021"
[profile.release] [profile.release]

View file

@ -1,92 +1,83 @@
{ {
"nodes": { "nodes": {
"flake-utils": { "fenix": {
"inputs": { "inputs": {
"systems": "systems" "nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
}, },
"locked": { "locked": {
"lastModified": 1681202837, "lastModified": 1714631076,
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", "narHash": "sha256-at4+1R9gx3CGvX0ZJo9GwDZyt3RzOft7qDCTsYHjI4M=",
"owner": "numtide", "owner": "nix-community",
"repo": "flake-utils", "repo": "fenix",
"rev": "cfacdce06f30d2b68473a46042957675eebb3401", "rev": "22a9eb3f20dd340d084cee4426f386a90b1351ca",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "numtide", "owner": "nix-community",
"repo": "flake-utils", "repo": "fenix",
"type": "github" "type": "github"
} }
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1703499205, "lastModified": 1714253743,
"narHash": "sha256-lF9rK5mSUfIZJgZxC3ge40tp1gmyyOXZ+lRY3P8bfbg=", "narHash": "sha256-mdTQw2XlariysyScCv2tTE45QSU9v/ezLcHJ22f0Nxc=",
"owner": "NixOS", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "e1fa12d4f6c6fe19ccb59cac54b5b3f25e160870", "rev": "58a1abdbae3217ca6b702f03d3b35125d88a2994",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "NixOS", "owner": "nixos",
"ref": "nixpkgs-unstable", "ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1681358109,
"narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "96ba1c52e54e74c3197f4d43026b3f3d92e83ff9",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
}, },
"root": { "root": {
"inputs": { "inputs": {
"fenix": "fenix",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay" "treefmt-nix": "treefmt-nix"
} }
}, },
"rust-overlay": { "rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1714572655,
"narHash": "sha256-xjD8vmit0Nz1qaSSSpeXOK3saSvAZtOGHS2SHZE75Ek=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "cfce2bb46da62950a8b70ddb0b2a12332da1b1e1",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
},
"treefmt-nix": {
"inputs": { "inputs": {
"flake-utils": "flake-utils", "nixpkgs": [
"nixpkgs": "nixpkgs_2" "nixpkgs"
]
}, },
"locked": { "locked": {
"lastModified": 1703902408, "lastModified": 1714058656,
"narHash": "sha256-qXdWvu+tlgNjeoz8yQMRKSom6QyRROfgpmeOhwbujqw=", "narHash": "sha256-Qv4RBm4LKuO4fNOfx9wl40W2rBbv5u5m+whxRYUMiaA=",
"owner": "oxalica", "owner": "numtide",
"repo": "rust-overlay", "repo": "treefmt-nix",
"rev": "319f57cd2c34348c55970a4bf2b35afe82088681", "rev": "c6aaf729f34a36c445618580a9f95a48f5e4e03f",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "oxalica", "owner": "numtide",
"repo": "rust-overlay", "repo": "treefmt-nix",
"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" "type": "github"
} }
} }

106
flake.nix
View file

@ -2,47 +2,83 @@
description = "A Nix-flake-based Rust development environment"; description = "A Nix-flake-based Rust development environment";
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
}; };
outputs = { self, nixpkgs, rust-overlay }: fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
treefmt-nix,
fenix,
}:
let let
overlays = [ supportedSystems = [
rust-overlay.overlays.default "x86_64-linux"
(final: prev: { "aarch64-linux"
rustToolchain = "x86_64-darwin"
let "aarch64-darwin"
rust = prev.rust-bin;
in
if builtins.pathExists ./rust-toolchain.toml then
rust.fromRustupToolchainFile ./rust-toolchain.toml
else if builtins.pathExists ./rust-toolchain then
rust.fromRustupToolchainFile ./rust-toolchain
else
rust.stable.latest.default;
})
]; ];
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; forEachSupportedSystem =
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f { f:
pkgs = import nixpkgs { inherit overlays system; }; nixpkgs.lib.genAttrs supportedSystems (
}); system:
f (
let
pkgs = import nixpkgs { inherit system; };
fenix' = (import fenix { inherit system pkgs; });
toolchain = fenix'.complete.withComponents (
(builtins.fromTOML (builtins.readFile ./rust-toolchain.toml)).toolchain.components
);
in in
{ {
devShells = forEachSupportedSystem ({ pkgs }: { inherit pkgs toolchain;
}
)
);
in
{
formatter = forEachSupportedSystem (
{ pkgs, ... }: (treefmt-nix.lib.evalModule pkgs ./treefmt.nix).config.build.wrapper
);
devShells = forEachSupportedSystem (
{ pkgs, toolchain }:
{
default = pkgs.mkShell { default = pkgs.mkShell {
packages = with pkgs; [ nativeBuildInputs = [ toolchain ];
mold buildInputs = [ toolchain ];
clang };
rustToolchain }
openssl );
pkg-config packages = forEachSupportedSystem (
cargo-deny { pkgs, toolchain }:
cargo-edit {
cargo-watch default = (
rust-analyzer let
]; manifest = (pkgs.lib.importTOML ./Cargo.toml).package;
}; rustPlatform = pkgs.makeRustPlatform {
}); cargo = toolchain;
rustc = toolchain;
};
in
rustPlatform.buildRustPackage {
pname = manifest.name;
version = manifest.version;
cargoLock.lockFile = ./Cargo.lock;
src = pkgs.lib.cleanSource ./.;
}
);
}
);
}; };
} }

3
rust-toolchain.toml Normal file
View file

@ -0,0 +1,3 @@
[toolchain]
channel = "stable"
components = ["rustfmt", "cargo", "rustc", "rust-src"]

View file

@ -23,7 +23,7 @@ use tokio::net::TcpListener;
// Pseudorandom number generator from the "Xorshift RNGs" paper by George Marsaglia. // Pseudorandom number generator from the "Xorshift RNGs" paper by George Marsaglia.
// //
// https://github.com/rust-lang/rust/blob/1.55.0/library/core/src/slice/sort.rs#L559-L573 // https://github.com/rust-lang/rust/blob/1.55.0/library/core/src/slice/sort.rs#L559-L573
pub fn random_numbers() -> impl Iterator<Item = usize> { pub fn random_numbers() -> std::iter::RepeatWith<impl FnMut() -> usize> {
let mut random = SystemTime::now() let mut random = SystemTime::now()
.duration_since(UNIX_EPOCH) .duration_since(UNIX_EPOCH)
.unwrap_or(Duration::new(0, 0)) .unwrap_or(Duration::new(0, 0))

8
treefmt.nix Normal file
View file

@ -0,0 +1,8 @@
{ ... }:
{
projectRootFile = "flake.nix";
programs = {
nixfmt-rfc-style.enable = true;
rustfmt.enable = true;
};
}