From b28b8455a912f89ac2d2d9ed6421d3b8e688ed75 Mon Sep 17 00:00:00 2001 From: Youwen Wu Date: Sun, 20 Oct 2024 17:09:11 -0700 Subject: [PATCH] refactor: use flake-parts for better management of per-system flake attributes --- 2024/flake.lock | 47 ++++++++++----------- 2024/flake.nix | 108 ++++++++++++++++++++++++++---------------------- 2 files changed, 81 insertions(+), 74 deletions(-) diff --git a/2024/flake.lock b/2024/flake.lock index 88aaaeb..ae5a677 100644 --- a/2024/flake.lock +++ b/2024/flake.lock @@ -1,20 +1,20 @@ { "nodes": { - "flake-utils": { + "flake-parts": { "inputs": { - "systems": "systems" + "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1726560853, - "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "lastModified": 1727826117, + "narHash": "sha256-K5ZLCyfO/Zj9mPFldf3iwS6oZStJcU4tSpiXTMYaaL0=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "3d04084d54bedc3d6b8b736c70ef449225c361b1", "type": "github" }, "original": { - "owner": "numtide", - "repo": "flake-utils", + "owner": "hercules-ci", + "repo": "flake-parts", "type": "github" } }, @@ -34,29 +34,26 @@ "type": "github" } }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1727825735, + "narHash": "sha256-0xHYkMkeLVQAMa7gvkddbPqpxph+hDzdu1XdGPJR+Os=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" + } + }, "root": { "inputs": { - "flake-utils": "flake-utils", + "flake-parts": "flake-parts", "nixpkgs": "nixpkgs", "typix": "typix", "typst-packages": "typst-packages" } }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, "typix": { "inputs": { "nixpkgs": [ diff --git a/2024/flake.nix b/2024/flake.nix index 7441991..5e2ef81 100644 --- a/2024/flake.nix +++ b/2024/flake.nix @@ -9,7 +9,7 @@ inputs.nixpkgs.follows = "nixpkgs"; }; - flake-utils.url = "github:numtide/flake-utils"; + flake-parts.url = "github:hercules-ci/flake-parts"; typst-packages = { url = "github:typst/packages"; @@ -25,58 +25,68 @@ outputs = inputs@{ - nixpkgs, - typix, - flake-utils, + flake-parts, self, + typix, + typst-packages, ... }: - flake-utils.lib.eachDefaultSystem ( - system: - let - pkgs = nixpkgs.legacyPackages.${system}; - in - let - typstPackagesSrc = "${inputs.typst-packages}/packages"; - - typstPackagesCache = pkgs.stdenv.mkDerivation { - name = "typst-packages-cache"; - src = typstPackagesSrc; - dontBuild = true; - installPhase = '' - mkdir -p "$out/typst/packages" - cp -LR --reflink=auto --no-preserve=mode -t "$out/typst/packages" "$src"/* - ''; + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + flake = { + hydraJobs = { + legacyPackages."x86_64-linux" = self.legacyPackages."x86_64-linux"; }; - typixLib = typix.lib.${system}; - in - let - alexandriaLib = import ./nix/lib { - inherit pkgs typixLib typstPackagesCache; - }; - - in - { - legacyPackages = ( - (alexandriaLib.indexByName ./documents/by-name) - // (alexandriaLib.indexByCourse ./documents/by-course) - ); - # devShells.default = typixLib.devShell { - # inherit (commonArgs) fontPaths virtualPaths; - # packages = [ - # # WARNING: Don't run `typst-build` directly, instead use `nix run .#build` - # # See https://github.com/loqusion/typix/issues/2 - # # build-script - # watch-script - # # More packages can be added here, like typstfmt - # pkgs.typstyle - # ]; - # }; - } - ) - // { - hydraJobs = { - legacyPackages."x86_64-linux" = self.legacyPackages."x86_64-linux"; }; + perSystem = + { + pkgs, + system, + ... + }: + let + typstPackagesSrc = "${typst-packages}/packages"; + + typstPackagesCache = pkgs.stdenv.mkDerivation { + name = "typst-packages-cache"; + src = typstPackagesSrc; + dontBuild = true; + installPhase = '' + mkdir -p "$out/typst/packages" + cp -LR --reflink=auto --no-preserve=mode -t "$out/typst/packages" "$src"/* + ''; + }; + typixLib = typix.lib.${system}; + in + let + alexandriaLib = import ./nix/lib { + inherit pkgs typixLib typstPackagesCache; + }; + + in + { + legacyPackages = ( + (alexandriaLib.indexByName ./documents/by-name) + // (alexandriaLib.indexByCourse ./documents/by-course) + ); + # devShells.default = typixLib.devShell { + # inherit (commonArgs) fontPaths virtualPaths; + # packages = [ + # # WARNING: Don't run `typst-build` directly, instead use `nix run .#build` + # # See https://github.com/loqusion/typix/issues/2 + # # build-script + # watch-script + # # More packages can be added here, like typstfmt + # pkgs.typstyle + # ]; + # }; + formatter = pkgs.nixfmt-rfc-style; + }; + # // { }; }