NixLabConnectionconnecting
ProjectsProject
web /

dreamstop.openfp.net

publicguest

dreamstop.openfp.net, the website and user manual of dreamstop, a language for continuous disambiguation

git clone git@nixlab.openfp.net:web/dreamstop.openfp.net.git
ec1e4025b5ba84b97bf40e4cd47100dc56fbd29e/horizon-local.nix
# This file is copied by horizon-config beside the set it generates. Do not edit.
#
# The Nix behind a set's local packages, imported by the set's overlay or
# package-set file: the source each one is built from, and the check that
# its pkgs/*.nix was generated from the .cabal its directory now holds.
# `generated` names the files the generator writes beside this one.
{ pkgs, generated }:
let
  inherit (pkgs) lib;

  # The directory holding the config and everything generated from it.
  root = toString ./.;

  # The generator's outputs and the flake's wiring are rewritten whenever
  # the set is regenerated and are never a package's source; building them
  # in would rebuild every local package on every regeneration.
  outputs = map (name: "${root}/${name}") (generated ++ [ "nix" "flake.nix" "flake.lock" ]);

  # What cabal, stack, GHC environment files and git keep at the top of a
  # package's directory. None is tracked, so a git flake never carries one,
  # but a path: flake or a working tree does.
  untracked = name:
    lib.elem name [ "dist-newstyle" "dist" ".stack-work" ".git" ]
    || lib.hasPrefix ".ghc.environment." name;

  # A local package's directory less the excluded entries. The default
  # name, "source", makes it the very store path of the directory's own
  # flake source when nothing is excluded.
  source = dir:
    lib.cleanSourceWith {
      src = dir;
      filter = path: _type:
        !(lib.elem path outputs || (dirOf path == toString dir && untracked (baseNameOf path)));
    };

  relative = path: lib.removePrefix "${root}/" (toString path);

  # Pure evaluation of the check's derivation fails, naming both files,
  # once the .cabal hashes to something other than what the file was
  # generated from.
  fresh = file: { pname, passthru, ... }:
    pkgs.runCommand "${pname}-fresh" { } (
      if builtins.hashFile "sha256" passthru.cabalFile == passthru.cabalSha256
      then "touch $out"
      else throw "${relative passthru.cabalFile} has changed since ${relative file} was generated from it; regenerate the set with horizon-config"
    );
in
{
  # A local package's generated file, called in the set: built from its
  # directory less the excluded entries, with `fresh`, the check that the
  # file is current, for a flake to expose.
  callPackage = scope: file: args:
    pkgs.haskell.lib.compose.overrideCabal
      (old: {
        src = source old.src;
        passthru = old.passthru // { fresh = fresh file old; };
      })
      (scope.callPackage file args);
}