mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-09-11 14:35:30 +03:00
Add replaceRootSources app
This commit is contained in:
parent
ea3bb39310
commit
10b79208b9
@ -32,6 +32,8 @@
|
||||
|
||||
writeFlakeD2N = callPackageDream ./writeFlakeD2N {};
|
||||
|
||||
replaceRootSources = callPackageDream ./replaceRootSources {};
|
||||
|
||||
flakeApps =
|
||||
b.mapAttrs (
|
||||
appName: app: {
|
||||
|
13
src/apps/replaceRootSources/default.nix
Normal file
13
src/apps/replaceRootSources/default.nix
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
# from nixpkgs
|
||||
python3,
|
||||
writeScriptBin,
|
||||
...
|
||||
}: let
|
||||
cliPython = python3.withPackages (ps: []);
|
||||
in
|
||||
writeScriptBin
|
||||
"replaceRootSources"
|
||||
''
|
||||
${cliPython}/bin/python ${./replaceRootSources.py} "$@"
|
||||
''
|
41
src/apps/replaceRootSources/replaceRootSources.py
Normal file
41
src/apps/replaceRootSources/replaceRootSources.py
Normal file
@ -0,0 +1,41 @@
|
||||
import sys
|
||||
import json
|
||||
|
||||
def replace_root_sources(lock, newSource):
|
||||
|
||||
packages = lock['_generic']['packages']
|
||||
sources = lock['sources']
|
||||
|
||||
for name, version in packages.items():
|
||||
|
||||
original = sources[name][version]
|
||||
|
||||
fixed = newSource
|
||||
|
||||
if 'dir' in original:
|
||||
fixed['dir'] = original['dir']
|
||||
elif 'relPath' in original:
|
||||
fixed['dir'] = original['relPath']
|
||||
|
||||
sources[name][version] = fixed
|
||||
|
||||
lock['sources'] = sources
|
||||
|
||||
return lock
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
lockFile = sys.argv[1]
|
||||
newSourceFile = sys.argv[2]
|
||||
|
||||
with open(lockFile, "r") as f:
|
||||
lock = json.load(f)
|
||||
|
||||
with open(newSourceFile, "r") as f:
|
||||
newSource = json.load(f)
|
||||
|
||||
fixed = replace_root_sources(lock, newSource)
|
||||
|
||||
with open(lockFile, "w") as f:
|
||||
json.dump(fixed, f, indent=2, sort_keys=True)
|
Loading…
Reference in New Issue
Block a user