Skip to content

Commit

Permalink
nixos/tools: start cleanup (#343075)
Browse files Browse the repository at this point in the history
  • Loading branch information
K900 authored Sep 20, 2024
2 parents e433609 + 51b4762 commit 685d691
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 57 deletions.
23 changes: 0 additions & 23 deletions nixos/modules/installer/tools/get-version-suffix

This file was deleted.

32 changes: 3 additions & 29 deletions nixos/modules/installer/tools/tools.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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

{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ system ? builtins.currentSystem
, config ? {}
, nixpkgs
, networkExpr
}:

Expand All @@ -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;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>"
22 changes: 22 additions & 0 deletions pkgs/by-name/ni/nixos-build-vms/package.nix
Original file line number Diff line number Diff line change
@@ -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";
}
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions pkgs/by-name/ni/nixos-enter/package.nix
Original file line number Diff line number Diff line change
@@ -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";
}
33 changes: 33 additions & 0 deletions pkgs/by-name/ni/nixos-install/package.nix
Original file line number Diff line number Diff line change
@@ -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";
}
22 changes: 21 additions & 1 deletion pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 685d691

Please sign in to comment.