flake.nix: modernize

This commit is contained in:
Oystein Kristoffer Tveit 2024-04-29 00:28:59 +02:00
parent f6dac0b2fc
commit 5894a41db3
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
2 changed files with 123 additions and 17 deletions

View File

@ -1,5 +1,26 @@
{
"nodes": {
"fenix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1714285404,
"narHash": "sha256-MmoQIO+KRiH3UnH0myAp2Fgi84rmpROMfw9VIbqrjHA=",
"owner": "nix-community",
"repo": "fenix",
"rev": "94be183087845937b0fd77281c37d0796572b899",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1707546158,
@ -18,8 +39,26 @@
},
"root": {
"inputs": {
"fenix": "fenix",
"nixpkgs": "nixpkgs"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1714217560,
"narHash": "sha256-zttBYGaoHpZfqWHQ8OI5f9OkGHCHb8tDBMySwsYNa2U=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "f216be4a0746142c5f30835b254871256a7637b8",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
}
},
"root": "root",

101
flake.nix
View File

@ -1,28 +1,94 @@
# {
# inputs = {
# nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# };
# outputs = { self, nixpkgs }: let
# supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
# forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system nixpkgs.legacyPackages.${system});
# in {
# devShells = forAllSystems (system: pkgs: {
# default = let
# rustPlatform = pkgs.rust.packages.stable.rustPlatform;
# in pkgs.mkShell {
# packages = with pkgs; [
# cargo
# clippy
# rust-analyzer
# rustc
# rustfmt
# ];
# RUST_SRC_PATH = "${rustPlatform.rustLibSrc}";
# };
# });
# packages = (forAllSystems (system: pkgs: {
# default = pkgs.rustPlatform.buildRustPackage rec {
# pname = "polyglot-zip";
# version = (pkgs.lib.importTOML ./Cargo.toml).package.version;
# src = ./.;
# cargoSha256 = "sha256-3oHEH6DlooWg0sQ+oIvsYoU6FAs7gP9PRwv1xJjGDYA=";
# meta = with pkgs.lib; {
# description = "A tool to convert and extract zip files with non-UTF-8 contents";
# homepage = "https://github.com/h7x4/polyglot-zip";
# license = licenses.mit;
# platforms = supportedSystems;
# };
# };
# }));
# };
# }
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
fenix.url = "github:nix-community/fenix";
fenix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs }: let
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system nixpkgs.legacyPackages.${system});
in {
devShells = forAllSystems (system: pkgs: {
default = let
rustPlatform = pkgs.rust.packages.stable.rustPlatform;
in pkgs.mkShell {
packages = with pkgs; [
cargo
clippy
rust-analyzer
rustc
rustfmt
outputs = { self, nixpkgs, fenix }@inputs:
let
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: let
toolchain = fenix.packages.${system}.complete;
pkgs = import nixpkgs {
inherit system;
overlays = [
(_: super: let pkgs = fenix.inputs.nixpkgs.legacyPackages.${system}; in fenix.overlays.default pkgs pkgs)
];
RUST_SRC_PATH = "${rustPlatform.rustLibSrc}";
};
in f system pkgs toolchain);
in {
apps = forAllSystems (system: pkgs: _: let
mkApp = program: {
type = "app";
program = "${nixpkgs.lib.getExe program}";
};
in {
default = mkApp self.packages.${system}.default;
});
packages = (forAllSystems (system: pkgs: {
devShell = forAllSystems (system: pkgs: toolchain: pkgs.mkShell {
packages = [
(toolchain.withComponents [
"cargo" "rustc" "rustfmt" "clippy"
])
pkgs.openssl
pkgs.pkg-config
];
RUST_SRC_PATH = "${toolchain.rust-src}/lib/rustlib/src/rust/";
});
overlays.default = final: prev: self.packages.${final.system};
packages = (forAllSystems (system: pkgs: _: {
default = pkgs.rustPlatform.buildRustPackage rec {
pname = "polyglot-zip";
version = (pkgs.lib.importTOML ./Cargo.toml).package.version;
@ -34,7 +100,8 @@
description = "A tool to convert and extract zip files with non-UTF-8 contents";
homepage = "https://github.com/h7x4/polyglot-zip";
license = licenses.mit;
platforms = supportedSystems;
platforms = systems;
mainProgram = "polyzip";
};
};
}));