flake.nix refactor

This commit is contained in:
rhiannon morris 2025-04-02 18:41:55 +02:00
parent 1750b315b4
commit e616d19a15

View file

@ -1,47 +1,46 @@
{ description = "niss's silly extra packages";
outputs = all@{ self, nixpkgs, ... }:
outputs = all@{ self, nixpkgs }:
let
inherit (nixpkgs.lib) genAttrs optionalAttrs systems;
inherit (nixpkgs.lib) genAttrs optionalAttrs systems defaultTo;
forAllSystems = genAttrs systems.flakeExposed;
getCallPackage = system: nixpkgs.legacyPackages.${system}.callPackage;
ifLinux64 = system: attrs: optionalAttrs (system == "x86_64-linux") attrs;
linuxPackageNames = [
"multi-ghc"
"basilisk" "isabelle"
packagesInDir = dir: names: pkgs:
let inherit (pkgs) callPackage; in
genAttrs names (pkg: callPackage ./${dir}/${pkg}.nix {});
linuxPackages = packagesInDir "apps" [
"multi-ghc" "basilisk" "isabelle"
"firefox-esr-alias" "inkscape-xwayland"
];
fontNames = [
fonts = packagesInDir "fonts" [
"constructium" "fairfax-hd" "kreative-square" "muller"
"pragmatapro" "teranoptia"
];
linuxAppNames = [
"basilisk" "isabelle" "firefox-esr-alias" "inkscape-xwayland"
makeApp = name: exe:
{ type = "app"; program = "${pkgs.${name}}/bin/${defaultTo name exe}"; };
linuxApps = pkgs: [
(makeApp "basilisk" null)
(makeApp "isabelle" null)
(makeApp "firefox-esr-alias" "firefox-esr")
(makeApp "inkscape-xwayland" "inkscape")
];
linuxAppExes = {
firefox-esr-alias = "firefox-esr";
inkscape-xwayland = "inkscape";
};
packagesInDir = names: dir: call:
genAttrs names (pkg: call ./${dir}/${pkg}.nix {});
linuxOnly = packagesInDir linuxPackageNames "apps";
fonts = packagesInDir fontNames "fonts";
all = system: call: ifLinux64 system (linuxOnly call) // fonts call;
ifLinux64 = f: pkgs: optionalAttrs (pkgs.system == "x86_64-linux") (f pkgs);
makeApp = pkgs: name: {
type = "app";
program = "${pkgs.${name}}/bin/${linuxAppExes.${name} or name}";
};
mkPackages = pkgs:
ifLinux64 linuxPackages pkgs // fonts pkgs;
linuxApps = call: genAttrs linuxAppNames (makeApp (linuxOnly call));
mkApps = pkgs: ifLinux64 linuxApps pkgs;
in {
packages = forAllSystems (s: all s (getCallPackage s));
apps = forAllSystems (s: ifLinux64 s (linuxApps (getCallPackage s)));
overlays = forAllSystems (s: final: prev: all s final.callPackage);
packages = forAllSystems (sys: mkPackages nixpkgs.legacyPackages.${sys});
apps = forAllSystems (sys: mkApps nixpkgs.legacyPackages.${sys});
overlays = forAllSystems (sys: final: prev: mkApps final);
};
}