nix: refactor Nix flake files (#323)

This commit is contained in:
Pol Dellaiera 2023-10-22 21:47:26 +02:00 committed by GitHub
parent 73f788e8e7
commit 1a0dff2289
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 213 additions and 200 deletions

View File

@ -4,3 +4,4 @@
/docs/ /docs/
/build/ /build/
CHANGELOG.md CHANGELOG.md
flake.lock

View File

@ -5,11 +5,11 @@
"nixpkgs-lib": "nixpkgs-lib" "nixpkgs-lib": "nixpkgs-lib"
}, },
"locked": { "locked": {
"lastModified": 1680392223, "lastModified": 1696343447,
"narHash": "sha256-n3g7QFr85lDODKt250rkZj2IFS3i4/8HBU2yKHO3tqw=", "narHash": "sha256-B2xAZKLkkeRFG5XcHHSXXcP7To9Xzr59KXeZiRf4vdQ=",
"owner": "hercules-ci", "owner": "hercules-ci",
"repo": "flake-parts", "repo": "flake-parts",
"rev": "dcc36e45d054d7bb554c9cdab69093debd91a0b5", "rev": "c9afaba3dfa4085dbd2ccb38dfade5141e33d9d4",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -19,11 +19,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1680942619, "lastModified": 1697915759,
"narHash": "sha256-kpCW1IegAZfEjCVJW7IPN/hEtRL/9dxaFFYiHS5qVAk=", "narHash": "sha256-WyMj5jGcecD+KC8gEs+wFth1J1wjisZf8kVZH13f1Zo=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "6f95dd4fd050daf017cae2dfeb1cea1ec0e4c1a1", "rev": "51d906d2341c9e866e48c2efcaac0f2d70bfd43e",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -36,11 +36,11 @@
"nixpkgs-lib": { "nixpkgs-lib": {
"locked": { "locked": {
"dir": "lib", "dir": "lib",
"lastModified": 1680213900, "lastModified": 1696019113,
"narHash": "sha256-cIDr5WZIj3EkKyCgj/6j3HBH4Jj1W296z7HTcWj1aMA=", "narHash": "sha256-X3+DKYWJm93DRSdC5M6K5hLqzSya9BjibtBsuARoPco=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "e3652e0735fbec227f342712f180f4f21f0594f2", "rev": "f5892ddac112a1e9b3612c39af1b72987ee5783a",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -54,7 +54,23 @@
"root": { "root": {
"inputs": { "inputs": {
"flake-parts": "flake-parts", "flake-parts": "flake-parts",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs",
"systems": "systems"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
} }
} }
}, },

View File

@ -2,28 +2,14 @@
description = "Category Theory for Programmers"; description = "Category Theory for Programmers";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.systems.url = "github:nix-systems/default";
outputs = inputs @ { outputs = inputs@{ self, flake-parts, nixpkgs, ... }:
self, flake-parts.lib.mkFlake { inherit inputs; } {
flake-parts, systems = import inputs.systems;
nixpkgs,
}:
flake-parts.lib.mkFlake {inherit inputs;} {
systems = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-linux"
"aarch64-darwin"
];
perSystem = {
config,
pkgs,
system,
...
}: let
inherit (nixpkgs) lib;
perSystem = { config, pkgs, system, lib, ... }:
let
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
######################################################################## ########################################################################
@ -109,7 +95,7 @@
; ;
inconsolata-lgc-latex = { inconsolata-lgc-latex = {
pkgs = [inconsolata-lgc-latex]; pkgs = [ inconsolata-lgc-latex ];
}; };
}; };
@ -117,13 +103,14 @@
nativeBuildInputs = [ nativeBuildInputs = [
texliveEnv texliveEnv
( (
pkgs.python3.withPackages (p: [p.pygments p.pygments-style-github]) pkgs.python3.withPackages (p: [ p.pygments p.pygments-style-github ])
) )
pkgs.which pkgs.which
]; ];
}; };
mkLatex = variant: edition: let mkLatex = variant: edition:
let
maybeVariant = lib.optionalString (variant != null) "-${variant}"; maybeVariant = lib.optionalString (variant != null) "-${variant}";
maybeEdition = lib.optionalString (edition != null) "-${edition}"; maybeEdition = lib.optionalString (edition != null) "-${edition}";
variantStr = variantStr =
@ -161,20 +148,29 @@
runHook postBuild runHook postBuild
''; '';
installPhase = "install -m 0644 -vD ctfp.pdf \"$out/${fullname}.pdf\""; installPhase = "
runHook preInstall
install -m 0644 -vD ctfp.pdf \"$out/${fullname}.pdf\"
runHook postInstall
";
passthru.packageName = fullname; passthru.packageName = fullname;
}); });
editions = [null "scala" "ocaml" "reason"]; editions = [ null "scala" "ocaml" "reason" ];
variants = [null "print"]; variants = [ null "print" ];
in rec { in
formatter = pkgs.alejandra; {
formatter = pkgs.nixpkgs-fmt;
packages = lib.listToAttrs (lib.concatMap (variant: packages = lib.listToAttrs (lib.concatMap
map (edition: rec { (variant:
name = value.packageName; map
(edition: rec {
value = mkLatex variant edition; value = mkLatex variant edition;
name = value.packageName;
}) })
editions) editions)
variants); variants);