From 054ee23448d8250726b0efe7e9bdf93b8a65cba3 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Fri, 20 Sep 2024 18:50:36 +0200 Subject: [PATCH] refactor: nix stack --- flake.lock | 40 +++++++---- flake.nix | 66 +++++++++---------- nix/imports/formatter.nix | 8 --- nix/imports/overlay.nix | 9 --- nix/imports/pkgs.nix | 3 - nix/imports/shell.nix | 17 ----- nix/pkgs/sign-pdf/package.nix | 21 ++++++ .../package.nix} | 4 +- nix/pkgs/typst-wrapper.nix | 15 ----- 9 files changed, 83 insertions(+), 100 deletions(-) delete mode 100644 nix/imports/formatter.nix delete mode 100644 nix/imports/overlay.nix delete mode 100644 nix/imports/shell.nix create mode 100644 nix/pkgs/sign-pdf/package.nix rename nix/pkgs/{typst-packages.nix => typst-packages/package.nix} (81%) delete mode 100644 nix/pkgs/typst-wrapper.nix diff --git a/flake.lock b/flake.lock index 6e40233..e53effa 100644 --- a/flake.lock +++ b/flake.lock @@ -58,11 +58,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1726243404, - "narHash": "sha256-sjiGsMh+1cWXb53Tecsm4skyFNag33GPbVgCdfj3n9I=", + "lastModified": 1726642912, + "narHash": "sha256-wiZzKGHRAhItEuoE599Wm3ic+Lg/NykuBvhb+awf7N8=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "345c263f2f53a3710abe117f28a5cb86d0ba4059", + "rev": "395c52d142ec1df377acd67db6d4a22950b02a98", "type": "github" }, "original": { @@ -104,11 +104,11 @@ }, "nixpkgs-unstable": { "locked": { - "lastModified": 1726481836, - "narHash": "sha256-MWTBH4dd5zIz2iatDb8IkqSjIeFum9jAqkFxgHLdzO4=", + "lastModified": 1726583932, + "narHash": "sha256-zACxiQx8knB3F8+Ze+1BpiYrI+CbhxyWpcSID9kVhkQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "20f9370d5f588fb8c72e844c54511cab054b5f40", + "rev": "658e7223191d2598641d50ee4e898126768fe847", "type": "github" }, "original": { @@ -134,11 +134,27 @@ "type": "github" } }, + "pkgs-by-name-for-flake-parts": { + "locked": { + "lastModified": 1726843639, + "narHash": "sha256-3ztPGGVbSyGHAycwJbgzpH0JoeC+tvU1pFjOuBGyHSE=", + "owner": "drupol", + "repo": "pkgs-by-name-for-flake-parts", + "rev": "d7f356eba1e202e850f6abb10c9cd8bf3f5db8a0", + "type": "github" + }, + "original": { + "owner": "drupol", + "repo": "pkgs-by-name-for-flake-parts", + "type": "github" + } + }, "root": { "inputs": { "flake-parts": "flake-parts", "nixpkgs": "nixpkgs", "nixpkgs-unstable": "nixpkgs-unstable", + "pkgs-by-name-for-flake-parts": "pkgs-by-name-for-flake-parts", "systems": "systems", "typst-dev": "typst-dev", "typst-packages": "typst-packages" @@ -182,11 +198,11 @@ "systems": "systems_2" }, "locked": { - "lastModified": 1726503444, - "narHash": "sha256-Huo0j4a+VPeJL81+4H4thgpufVQ/EfsKy8BxEK6u6EE=", + "lastModified": 1726588455, + "narHash": "sha256-4Xace2ql8MEVPXYWQicf2QdfipNuXRFcITE4iaKCm/o=", "owner": "typst", "repo": "typst", - "rev": "ea145ff33bb6c3babb9765b5d0059612b2ea54f0", + "rev": "92ec56601831b9c454dbeaf28dba84e2769c7726", "type": "github" }, "original": { @@ -198,11 +214,11 @@ "typst-packages": { "flake": false, "locked": { - "lastModified": 1726476449, - "narHash": "sha256-DG7WagGDzQ5XNGfRLHkZsnRbGTLiTZ0Saz4knHIxZ4w=", + "lastModified": 1726771917, + "narHash": "sha256-Xy3cVxw7CKIGIj0kfBRmxQ/0iGyj8OMdTFlaCdT6LaE=", "owner": "typst", "repo": "packages", - "rev": "d209ecdb935804c4a32be279a9f43a9f683d2745", + "rev": "b27156611758e4439a774d484b206a18e7aee6b0", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 68ca930..349bcb1 100644 --- a/flake.nix +++ b/flake.nix @@ -9,6 +9,7 @@ flake = false; url = "github:typst/packages"; }; + pkgs-by-name-for-flake-parts.url = "github:drupol/pkgs-by-name-for-flake-parts"; }; outputs = @@ -18,12 +19,11 @@ imports = [ ./nix/imports/pkgs.nix - ./nix/imports/overlay.nix - ./nix/imports/formatter.nix + inputs.pkgs-by-name-for-flake-parts.flakeModule ]; perSystem = - { pkgs, lib, ... }: + { pkgs, lib, config, ... }: let # Change here to typst-dev if needed typst = pkgs.nixpkgs-unstable.typst; @@ -39,8 +39,22 @@ ]; }; - typst-wrapper = pkgs.typst-wrapper typst pkgs.typst-packages fontsConf; - typstyle = pkgs.typstyle; + typst-wrapper-factory = + typstDrv: typst-packages: typstFontPaths: + pkgs.writeShellApplication { + name = "typst-wrapper"; + + runtimeInputs = [ + typstDrv + typst-packages + ]; + + text = '' + TYPST_FONT_PATHS=${typstFontPaths} XDG_CACHE_HOME=${typst-packages} ${lib.getExe typstDrv} "$@" + ''; + }; + + typst-wrapper = typst-wrapper-factory typst config.packages.typst-packages fontsConf; mkBuildDocumentDrv = documentName: @@ -120,37 +134,21 @@ lib.filterAttrs (k: v: (v == "directory")) (builtins.readDir ./src) )) (d: mkBuildDocumentDrv d); - signPDF = pkgs.writeShellApplication { - name = "sign-pdf"; - - runtimeInputs = [ pkgs.open-pdf-sign ]; - - text = '' - open-pdf-sign \ - --certificate cert.pem \ - --key private-key.pem \ - --no-hint \ - --timestamp \ - --tsa http://timestamp.digicert.com \ - --baseline-lt \ - --add-page \ - --page \ - -1 \ - --width 19 \ - "$@" - ''; - }; - - scriptDrvs = { "sign-pdf" = signPDF; } // lib.foldl' ( - a: i: - a - // { - "build-${i}" = mkBuildDocumentScript i; - "watch-${i}" = mkWatchDocumentScript i; + scriptDrvs = + { + "sign-pdf" = config.packages.sign-pdf; } - ) { } (lib.attrNames documentDrvs); + // lib.foldl' ( + a: i: + a + // { + "build-${i}" = mkBuildDocumentScript i; + "watch-${i}" = mkWatchDocumentScript i; + } + ) { } (lib.attrNames documentDrvs); in { + pkgsDirectory = ./nix/pkgs; packages = documentDrvs; devShells.default = pkgs.mkShellNoCC { @@ -165,7 +163,7 @@ echo "Typst version: ${typst.version}" echo "Typst bin: ${lib.getExe typst}" echo "Typst wrapper bin: ${lib.getExe typst-wrapper}" - echo "Typst packages directory: ${pkgs.typst-packages}" + echo "Typst packages directory: ${config.packages.typst-packages}" echo "Typst fonts directory: ${fontsConf}" ''; diff --git a/nix/imports/formatter.nix b/nix/imports/formatter.nix deleted file mode 100644 index d2553a2..0000000 --- a/nix/imports/formatter.nix +++ /dev/null @@ -1,8 +0,0 @@ -{ ... }: -{ - perSystem = - { pkgs, ... }: - { - formatter = pkgs.nixfmt-rfc-style; - }; -} diff --git a/nix/imports/overlay.nix b/nix/imports/overlay.nix deleted file mode 100644 index 23733a6..0000000 --- a/nix/imports/overlay.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ inputs, ... }: -{ - flake = { - overlays.default = final: prev: { - typst-packages = prev.callPackage ../pkgs/typst-packages.nix { src = inputs.typst-packages; }; - typst-wrapper = prev.callPackage ../pkgs/typst-wrapper.nix { }; - }; - }; -} diff --git a/nix/imports/pkgs.nix b/nix/imports/pkgs.nix index 189087d..6e5a329 100644 --- a/nix/imports/pkgs.nix +++ b/nix/imports/pkgs.nix @@ -7,11 +7,8 @@ inherit system; overlays = [ inputs.typst-dev.overlays.default - inputs.self.overlays.default (final: prev: { nixpkgs-unstable = import inputs.nixpkgs-unstable { inherit system; }; }) ]; - config = { - }; }; }; } diff --git a/nix/imports/shell.nix b/nix/imports/shell.nix deleted file mode 100644 index f9059e7..0000000 --- a/nix/imports/shell.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ inputs, self, ... }: -{ - perSystem = - { system, ... }: - { - _module.args.pkgs = import self.inputs.nixpkgs { - inherit system; - overlays = [ - inputs.typst-dev.overlays.default - inputs.self.overlays.default - ]; - config = { - allowUnfree = true; - }; - }; - }; -} diff --git a/nix/pkgs/sign-pdf/package.nix b/nix/pkgs/sign-pdf/package.nix new file mode 100644 index 0000000..703e271 --- /dev/null +++ b/nix/pkgs/sign-pdf/package.nix @@ -0,0 +1,21 @@ +{ pkgs, ... }: +pkgs.writeShellApplication { + name = "sign-pdf"; + + runtimeInputs = [ pkgs.open-pdf-sign ]; + + text = '' + open-pdf-sign \ + --certificate cert.pem \ + --key private-key.pem \ + --no-hint \ + --timestamp \ + --tsa http://timestamp.digicert.com \ + --baseline-lt \ + --add-page \ + --page \ + -1 \ + --width 19 \ + "$@" + ''; +} diff --git a/nix/pkgs/typst-packages.nix b/nix/pkgs/typst-packages/package.nix similarity index 81% rename from nix/pkgs/typst-packages.nix rename to nix/pkgs/typst-packages/package.nix index ab06a39..86cc021 100644 --- a/nix/pkgs/typst-packages.nix +++ b/nix/pkgs/typst-packages/package.nix @@ -1,9 +1,9 @@ -{ stdenvNoCC, src }: +{ stdenvNoCC, inputs }: stdenvNoCC.mkDerivation { name = "typst-packages"; - inherit src; + src = inputs.typst-packages; dontBuild = true; diff --git a/nix/pkgs/typst-wrapper.nix b/nix/pkgs/typst-wrapper.nix deleted file mode 100644 index 3570825..0000000 --- a/nix/pkgs/typst-wrapper.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ lib, writeShellApplication, ... }: - -typstDrv: typst-packages: typstFontPaths: -writeShellApplication { - name = "typst-wrapper"; - - runtimeInputs = [ - typstDrv - typst-packages - ]; - - text = '' - TYPST_FONT_PATHS=${typstFontPaths} XDG_CACHE_HOME=${typst-packages} ${lib.getExe typstDrv} "$@" - ''; -}