nixos/tools: start cleanup (#343075)

This commit is contained in:
K900 2024-09-20 10:08:12 +03:00 committed by GitHub
commit 685d691da1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 113 additions and 57 deletions

View File

@ -1,23 +0,0 @@
getVersion() {
local dir="$1"
rev=
gitDir="$dir/.git"
if [ -e "$gitDir" ]; then
if [ -z "$(type -P git)" ]; then
echo "warning: Git not found; cannot figure out revision of $dir" >&2
return
fi
cd "$dir"
rev=$(git --git-dir="$gitDir" rev-parse --short HEAD)
if git --git-dir="$gitDir" describe --always --dirty | grep -q dirty; then
rev+=M
fi
fi
}
if nixpkgs=$(nix-instantiate --find-file nixpkgs "$@"); then
getVersion $nixpkgs
if [ -n "$rev" ]; then
echo ".git.$rev"
fi
fi

View File

@ -17,26 +17,9 @@ let
'';
});
nixos-build-vms = makeProg {
name = "nixos-build-vms";
src = ./nixos-build-vms/nixos-build-vms.sh;
inherit (pkgs) runtimeShell;
manPage = ./manpages/nixos-build-vms.8;
};
nixos-install = makeProg {
name = "nixos-install";
src = ./nixos-install.sh;
inherit (pkgs) runtimeShell;
nix = config.nix.package.out;
path = makeBinPath [
pkgs.jq
nixos-enter
pkgs.util-linuxMinimal
];
manPage = ./manpages/nixos-install.8;
};
inherit (pkgs) nixos-build-vms;
nixos-install = pkgs.nixos-install.override { nix = config.nix.package; };
nixos-rebuild = pkgs.nixos-rebuild.override { nix = config.nix.package.out; };
nixos-generate-config = makeProg {
@ -69,16 +52,7 @@ let
manPage = ./manpages/nixos-version.8;
};
nixos-enter = makeProg {
name = "nixos-enter";
src = ./nixos-enter.sh;
inherit (pkgs) runtimeShell;
path = makeBinPath [
pkgs.util-linuxMinimal
];
manPage = ./manpages/nixos-enter.8;
};
inherit (pkgs) nixos-enter;
in
{

View File

@ -1,5 +1,6 @@
{ system ? builtins.currentSystem
, config ? {}
, nixpkgs
, networkExpr
}:
@ -9,9 +10,9 @@ let
imports = [ module ];
}) (import networkExpr);
pkgs = import ../../../../.. { inherit system config; };
pkgs = import nixpkgs { inherit system config; };
testing = import ../../../../lib/testing-python.nix {
testing = import "${pkgs.path}/nixos/lib/testing-python.nix" {
inherit system pkgs;
};

View File

@ -49,5 +49,6 @@ then
fi
# Build a network of VMs
nix-build '<nixpkgs/nixos/modules/installer/tools/nixos-build-vms/build-vms.nix>' \
--argstr networkExpr "$networkExpr" "${nixBuildArgs[@]}"
nix-build @buildVms@ \
--argstr networkExpr "$networkExpr" "${nixBuildArgs[@]}" \
--arg nixpkgs "<nixpkgs>"

View File

@ -0,0 +1,22 @@
{
substituteAll,
runtimeShell,
installShellFiles,
}:
substituteAll {
name = "nixos-build-vms";
src = ./nixos-build-vms.sh;
inherit runtimeShell;
buildVms = ./build-vms.nix;
dir = "bin";
isExecutable = true;
nativeBuildInputs = [ installShellFiles ];
postInstall = ''
installManPage ${./nixos-build-vms.8}
'';
meta.mainProgram = "nixos-build-vms";
}

View File

@ -0,0 +1,28 @@
{
lib,
substituteAll,
runtimeShell,
installShellFiles,
util-linuxMinimal,
}:
substituteAll {
name = "nixos-enter";
src = ./nixos-enter.sh;
inherit runtimeShell;
path = lib.makeBinPath [
util-linuxMinimal
];
dir = "bin";
isExecutable = true;
nativeBuildInputs = [ installShellFiles ];
postInstall = ''
installManPage ${./nixos-enter.8}
'';
meta.mainProgram = "nixos-enter";
}

View File

@ -0,0 +1,33 @@
{
lib,
substituteAll,
runtimeShell,
installShellFiles,
nix,
jq,
nixos-enter,
util-linuxMinimal,
}:
substituteAll {
name = "nixos-install";
src = ./nixos-install.sh;
inherit runtimeShell nix;
path = lib.makeBinPath [
jq
nixos-enter
util-linuxMinimal
];
dir = "bin";
isExecutable = true;
nativeBuildInputs = [ installShellFiles ];
postInstall = ''
installManPage ${./nixos-install.8}
'';
meta.mainProgram = "nixos-install";
}

View File

@ -548,6 +548,26 @@ getNixDrv() {
fi
}
getVersion() {
local dir="$1"
local rev=
local gitDir="$dir/.git"
if [ -e "$gitDir" ]; then
if [ -z "$(type -P git)" ]; then
echo "warning: Git not found; cannot figure out revision of $dir" >&2
return
fi
cd "$dir"
rev=$(git --git-dir="$gitDir" rev-parse --short HEAD)
if git --git-dir="$gitDir" describe --always --dirty | grep -q dirty; then
rev+=M
fi
fi
echo ".git.$rev"
}
if [[ -n $buildNix && -z $flake ]]; then
log "building Nix..."
getNixDrv
@ -569,7 +589,7 @@ fi
# nixos-version shows something useful).
if [[ -n $canRun && -z $flake ]]; then
if nixpkgs=$(runCmd nix-instantiate --find-file nixpkgs "${extraBuildFlags[@]}"); then
suffix=$(runCmd $SHELL "$nixpkgs/nixos/modules/installer/tools/get-version-suffix" "${extraBuildFlags[@]}" || true)
suffix=$(getVersion "$nixpkgs" || true)
if [ -n "$suffix" ]; then
echo -n "$suffix" > "$nixpkgs/.version-suffix" || true
fi