nix-tools: use replaceVarsWith

This commit is contained in:
WeetHet 2025-05-01 18:23:29 +03:00
parent 4515dacafb
commit a6d73d0904
2 changed files with 41 additions and 28 deletions

6
flake.lock generated
View file

@ -2,11 +2,11 @@
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1736241350,
"narHash": "sha256-CHd7yhaDigUuJyDeX0SADbTM9FXfiWaeNyY34FL1wQU=",
"lastModified": 1746061036,
"narHash": "sha256-OxYwCGJf9VJ2KnUO+w/hVJVTjOgscdDg/lPv8Eus07Y=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "8c9fd3e564728e90829ee7dbac6edc972971cd0f",
"rev": "3afd19146cac33ed242fc0fc87481c67c758a59e",
"type": "github"
},
"original": {

View file

@ -2,7 +2,7 @@
, coreutils
, jq
, git
, substituteAll
, replaceVarsWith
, stdenv
, profile ? "/nix/var/nix/profiles/system"
, # This should be kept in sync with the default
@ -31,40 +31,53 @@
let
extraPath = lib.makeBinPath [ coreutils jq git nixPackage ];
writeProgram = name: env: src:
substituteAll ({
inherit name src;
dir = "bin";
isExecutable = true;
meta.mainProgram = name;
} // env);
writeProgram =
attrs:
replaceVarsWith (
attrs
// {
dir = "bin";
isExecutable = true;
meta.mainProgram = attrs.name;
}
);
path = "${extraPath}:${systemPath}";
in
{
darwin-option = writeProgram "darwin-option"
{
darwin-option = writeProgram {
name = "darwin-option";
src = ./darwin-option.sh;
replacements = {
inherit path nixPath;
inherit (stdenv) shell;
}
./darwin-option.sh;
};
};
darwin-rebuild = writeProgram "darwin-rebuild"
{
darwin-rebuild = writeProgram {
name = "darwin-rebuild";
src = ./darwin-rebuild.sh;
replacements = {
inherit path nixPath profile;
inherit (stdenv) shell;
postInstall = ''
mkdir -p $out/share/zsh/site-functions
cp ${./darwin-rebuild.zsh-completions} $out/share/zsh/site-functions/_darwin-rebuild
'';
}
./darwin-rebuild.sh;
};
darwin-version = writeProgram "darwin-version"
{
postInstall = ''
mkdir -p $out/share/zsh/site-functions
cp ${./darwin-rebuild.zsh-completions} $out/share/zsh/site-functions/_darwin-rebuild
'';
};
darwin-version = writeProgram {
name = "darwin-version";
src = ./darwin-version.sh;
replacements = {
inherit (stdenv) shell;
path = lib.makeBinPath [ jq ];
}
./darwin-version.sh;
};
};
}