mirror of
https://github.com/nix-community/dream2nix.git
synced 2025-01-09 00:08:02 +03:00
pdm: refresh pdm.lock on 'nix run .#{package}.lock'
This commit is contained in:
parent
28f44827e4
commit
0fb528d452
@ -3,9 +3,8 @@
|
||||
|
||||
[metadata]
|
||||
groups = ["default", "dev"]
|
||||
cross_platform = true
|
||||
static_urls = false
|
||||
lock_version = "4.3"
|
||||
strategy = ["cross_platform"]
|
||||
lock_version = "4.4"
|
||||
content_hash = "sha256:6b124fd8499d7ddefb13cb60a64760b0601a8db060263247076bc4f4309cd6cd"
|
||||
|
||||
[[package]]
|
||||
|
@ -42,6 +42,7 @@ in {
|
||||
dream2nix.modules.dream2nix.buildPythonPackage
|
||||
../core/deps
|
||||
./interface.nix
|
||||
./lock.nix
|
||||
];
|
||||
name = pyproject.pyproject.project.name;
|
||||
version = lib.mkDefault (
|
||||
|
48
modules/dream2nix/WIP-python-pdm/lock.nix
Normal file
48
modules/dream2nix/WIP-python-pdm/lock.nix
Normal file
@ -0,0 +1,48 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
pdmConfig = config.deps.writeText "pdm-config.toml" ''
|
||||
check_update = false
|
||||
[python]
|
||||
use_venv = false
|
||||
'';
|
||||
|
||||
script = config.deps.writeScript "pdm-lock" ''
|
||||
#!${config.deps.bash}/bin/bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
export PATH="$PATH:${lib.makeBinPath [
|
||||
config.deps.coreutils
|
||||
config.deps.pdm
|
||||
config.deps.yq
|
||||
]}"
|
||||
export TMPDIR=$(${config.deps.coreutils}/bin/mktemp -d)
|
||||
trap "${config.deps.coreutils}/bin/chmod -R +w '$TMPDIR'; ${config.deps.coreutils}/bin/rm -rf '$TMPDIR'" EXIT
|
||||
|
||||
# vscode likes to set these for whatever reason and it crashes PDM
|
||||
unset _PYTHON_SYSCONFIGDATA_NAME _PYTHON_HOST_PLATFORM
|
||||
|
||||
pushd "$(${config.paths.findRoot})/${config.paths.package}"
|
||||
|
||||
echo ${config.deps.python3}/bin/python3 > .pdm-python
|
||||
pdm -c ${pdmConfig} lock --refresh
|
||||
|
||||
popd
|
||||
'';
|
||||
in {
|
||||
lock.extraScripts = [script];
|
||||
deps = {nixpkgs, ...}:
|
||||
lib.mapAttrs (_: lib.mkDefault) {
|
||||
inherit
|
||||
(nixpkgs)
|
||||
bash
|
||||
coreutils
|
||||
pdm
|
||||
writeScript
|
||||
writeText
|
||||
yq
|
||||
;
|
||||
};
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
data = l.fromJSON (l.readFile file);
|
||||
fileExists = l.pathExists file;
|
||||
|
||||
refresh =
|
||||
generatedRefreshScript =
|
||||
if cfg.fields == {}
|
||||
then removeLockFileScript
|
||||
else refresh';
|
||||
@ -196,7 +196,21 @@ in {
|
||||
];
|
||||
|
||||
config = {
|
||||
lock.refresh = refresh;
|
||||
lock.refresh = config.deps.writeScriptBin "refresh" ''
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
### Executing auto generated refresh script
|
||||
|
||||
currDir="$(realpath .)"
|
||||
${generatedRefreshScript}/bin/refresh
|
||||
cd "$currDir"
|
||||
|
||||
|
||||
### Executing custom scripts defined via lock.extraScrips
|
||||
|
||||
${lib.concatStringsSep "\n" (map toString cfg.extraScripts)}
|
||||
'';
|
||||
|
||||
lock.content = mkLazy loadedContent;
|
||||
|
||||
@ -204,7 +218,7 @@ in {
|
||||
|
||||
deps = {nixpkgs, ...}:
|
||||
l.mapAttrs (_: l.mkDefault) {
|
||||
inherit (nixpkgs) nix;
|
||||
inherit (nixpkgs) nix writeScriptBin;
|
||||
inherit (nixpkgs.writers) writePython3 writePython3Bin;
|
||||
};
|
||||
};
|
||||
|
@ -24,6 +24,16 @@ in {
|
||||
'';
|
||||
};
|
||||
|
||||
extraScripts = l.mkOption {
|
||||
type = t.listOf t.path;
|
||||
default = "";
|
||||
description = ''
|
||||
Extra shell scripts to execute when `nix run .#{package}.lock` is called.
|
||||
|
||||
This allows adding custom logic to the lock file generation.
|
||||
'';
|
||||
};
|
||||
|
||||
fields = l.mkOption {
|
||||
type = t.attrsOf (t.submodule [
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user