dream2nix/modules/flake-parts/writers.nix

43 lines
1.4 KiB
Nix
Raw Normal View History

2023-07-26 16:44:53 +03:00
{flake-parts-lib, ...}: {
2023-07-21 15:35:43 +03:00
options.perSystem = flake-parts-lib.mkPerSystemOption ({
2023-02-25 15:04:00 +03:00
config,
lib,
pkgs,
...
2023-05-02 15:05:57 +03:00
}: let
writers = pkgs.callPackage ../../pkgs/writers {};
in {
options.writers = {
writePureShellScript = lib.mkOption {
2023-07-21 15:35:43 +03:00
type = lib.types.functionTo (lib.types.functionTo lib.types.package);
description = ''
Create a script that runs in a `pure` environment, in the sense that:
2023-07-26 17:13:19 +03:00
- the behavior is similar to `nix-shell --pure`
2023-07-21 15:35:43 +03:00
- `PATH` only contains exactly the packages passed via the `PATH` arg
- `NIX_PATH` is set to the path of the current `pkgs`
- `TMPDIR` is set up and cleaned up even if the script fails
- out, if set, is kept as-is
- all environment variables are unset, except:
2023-07-26 17:13:19 +03:00
- the ones listed in `keepVars` below
- ones listed via the `KEEP_VARS` variable
2023-07-21 15:35:43 +03:00
'';
};
writePureShellScriptBin = lib.mkOption {
2023-07-21 15:35:43 +03:00
type = lib.types.functionTo (lib.types.functionTo (lib.types.functionTo lib.types.package));
description = ''
Creates a script in a `bin/` directory in the output; suitable for use with `lib.makeBinPath`, etc.
See {option}`writers.writePureShellScript`
'';
};
};
2023-05-02 15:05:57 +03:00
config.writers = {
inherit
(writers)
writePureShellScript
writePureShellScriptBin
;
};
2023-07-21 15:35:43 +03:00
});
}