Idris2/nix/lib.nix
zseri 6fbba94c21 Nix: make nixpkgs options overridable
This allows for cross-flake testing of content-addressible nix derivations without
affecting other users of the flake (which would be the cases if CA-drvs would be
hard-coded upstream) and without losing the ability to quickly update to the latest
idris2 version (which would happen if a fork of the repo would be used).

See also: https://discourse.nixos.org/t/content-addressed-nix-call-for-testers/12881

The flake can still be used as usual, but it will gain an output `overrideOptions`, which can be used like e.g.
```nix
let
  idrisx = idris.overrideOptions {
    config.contentAddressedByDefault = true;
  };
in { ... }
```
2021-06-30 15:33:37 +01:00

13 lines
602 B
Nix

rec {
# source: https://nixos.org/guides/nix-pills/override-design-pattern.html
# but with the ability to change the name of the override method
makeOverridable = kind: f:
let inner = oldArgs: (f oldArgs) // { ${kind} = newArgs: inner (oldArgs // newArgs); };
in inner;
# create a flake with overridable options. useful because we can't pass
# fine-grained overrides to flakes otherwise, we can only change inputs
# (therefore, this can't change inputs per default, and that should also be unnecessary)
mkOvrOptsFlake = flakefn: makeOverridable "overrideOptions" flakefn { };
}