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/
/build/
CHANGELOG.md
flake.lock

View File

@ -5,11 +5,11 @@
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1680392223,
"narHash": "sha256-n3g7QFr85lDODKt250rkZj2IFS3i4/8HBU2yKHO3tqw=",
"lastModified": 1696343447,
"narHash": "sha256-B2xAZKLkkeRFG5XcHHSXXcP7To9Xzr59KXeZiRf4vdQ=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "dcc36e45d054d7bb554c9cdab69093debd91a0b5",
"rev": "c9afaba3dfa4085dbd2ccb38dfade5141e33d9d4",
"type": "github"
},
"original": {
@ -19,11 +19,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1680942619,
"narHash": "sha256-kpCW1IegAZfEjCVJW7IPN/hEtRL/9dxaFFYiHS5qVAk=",
"lastModified": 1697915759,
"narHash": "sha256-WyMj5jGcecD+KC8gEs+wFth1J1wjisZf8kVZH13f1Zo=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "6f95dd4fd050daf017cae2dfeb1cea1ec0e4c1a1",
"rev": "51d906d2341c9e866e48c2efcaac0f2d70bfd43e",
"type": "github"
},
"original": {
@ -36,11 +36,11 @@
"nixpkgs-lib": {
"locked": {
"dir": "lib",
"lastModified": 1680213900,
"narHash": "sha256-cIDr5WZIj3EkKyCgj/6j3HBH4Jj1W296z7HTcWj1aMA=",
"lastModified": 1696019113,
"narHash": "sha256-X3+DKYWJm93DRSdC5M6K5hLqzSya9BjibtBsuARoPco=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e3652e0735fbec227f342712f180f4f21f0594f2",
"rev": "f5892ddac112a1e9b3612c39af1b72987ee5783a",
"type": "github"
},
"original": {
@ -54,7 +54,23 @@
"root": {
"inputs": {
"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";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.systems.url = "github:nix-systems/default";
outputs = inputs @ {
self,
flake-parts,
nixpkgs,
}:
outputs = inputs@{ self, flake-parts, 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;
systems = import inputs.systems;
perSystem = { config, pkgs, system, lib, ... }:
let
pkgs = nixpkgs.legacyPackages.${system};
########################################################################
@ -123,7 +109,8 @@
];
};
mkLatex = variant: edition: let
mkLatex = variant: edition:
let
maybeVariant = lib.optionalString (variant != null) "-${variant}";
maybeEdition = lib.optionalString (edition != null) "-${edition}";
variantStr =
@ -161,20 +148,29 @@
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;
});
editions = [ null "scala" "ocaml" "reason" ];
variants = [ null "print" ];
in rec {
formatter = pkgs.alejandra;
in
{
formatter = pkgs.nixpkgs-fmt;
packages = lib.listToAttrs (lib.concatMap (variant:
map (edition: rec {
name = value.packageName;
packages = lib.listToAttrs (lib.concatMap
(variant:
map
(edition: rec {
value = mkLatex variant edition;
name = value.packageName;
})
editions)
variants);