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
.direnv
result

2
Cargo.lock generated
View file

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

View file

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

View file

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

108
flake.nix
View file

@ -2,47 +2,83 @@
description = "A Nix-flake-based Rust development environment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, rust-overlay }:
outputs =
{
self,
nixpkgs,
treefmt-nix,
fenix,
}:
let
overlays = [
rust-overlay.overlays.default
(final: prev: {
rustToolchain =
let
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"
];
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
pkgs = import nixpkgs { inherit overlays system; };
});
forEachSupportedSystem =
f:
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
{
inherit pkgs toolchain;
}
)
);
in
{
devShells = forEachSupportedSystem ({ pkgs }: {
default = pkgs.mkShell {
packages = with pkgs; [
mold
clang
rustToolchain
openssl
pkg-config
cargo-deny
cargo-edit
cargo-watch
rust-analyzer
];
};
});
formatter = forEachSupportedSystem (
{ pkgs, ... }: (treefmt-nix.lib.evalModule pkgs ./treefmt.nix).config.build.wrapper
);
devShells = forEachSupportedSystem (
{ pkgs, toolchain }:
{
default = pkgs.mkShell {
nativeBuildInputs = [ toolchain ];
buildInputs = [ toolchain ];
};
}
);
packages = forEachSupportedSystem (
{ pkgs, toolchain }:
{
default = (
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.
//
// 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()
.duration_since(UNIX_EPOCH)
.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;
};
}