From 5894a41db390cfb2b2cfce65b6d468da4402e887 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 29 Apr 2024 00:28:59 +0200 Subject: [PATCH] flake.nix: modernize --- flake.lock | 39 +++++++++++++++++++++ flake.nix | 101 ++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 123 insertions(+), 17 deletions(-) diff --git a/flake.lock b/flake.lock index a9185f0..ad99d95 100644 --- a/flake.lock +++ b/flake.lock @@ -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", diff --git a/flake.nix b/flake.nix index 04da095..eb81198 100644 --- a/flake.nix +++ b/flake.nix @@ -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"; }; }; }));