Files
adp-nix-utils/flake.nix
T
didier amyot 6240fd4b14 Added possibility to use specific python in writePythonApplication.
This feature can be useful to add script dependant dependencies
using pkgs.python3.withPackages.
2023-05-17 07:42:40 -04:00

44 lines
1.4 KiB
Nix

{
description = "A Collection Of Nix Utilities";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system;};
in
{
writePythonApplication = {name, contentFile, extraRuntimeInputs ? [], python ? null}:
let
python-to-use = python == null then pkgs.python311 else python;
wrappedScript = pkgs.writeText "wrappedScript" (builtins.readFile contentFile);
in
pkgs.writeShellApplication {
name = name;
runtimeInputs = [
wrappedScript
if python-to-use] ++ extraRuntimeInputs;
text = ''
exec ${python-to-use}/bin/python ${wrappedScript} "$@"
'';
};
writeBabashkaApplication = {name, contentFile, extraRuntimeInputs ? []}: let
wrappedScript = pkgs.writeText "wrappedScript" (builtins.readFile contentFile);
in
pkgs.writeShellApplication {
name = name;
runtimeInputs = [
wrappedScript
pkgs.babashka] ++ extraRuntimeInputs;
text = ''
exec ${pkgs.babashka}/bin/bb ${wrappedScript} "$@"
'';
};
});
}