Merge pull request 'Add nixos-facter, vars fixes and remove git from base system' (#2292) from vars into main

This commit is contained in:
clan-bot
2024-10-29 13:00:38 +00:00
4 changed files with 69 additions and 105 deletions

View File

@@ -1,13 +1,23 @@
{ pkgs, ... }:
{ {
environment.systemPackages = [ pkgs,
# essential debugging tools for networked services lib,
pkgs.dnsutils config,
pkgs.tcpdump ...
pkgs.curl }:
pkgs.jq {
pkgs.htop environment.systemPackages =
# needed to deploy via `clan machines update` if the flake has a git input [
pkgs.gitMinimal # essential debugging tools for networked services
]; pkgs.dnsutils
pkgs.tcpdump
pkgs.curl
pkgs.jq
pkgs.htop
pkgs.nixos-facter # for `clan machines update-hardware-config --backend nixos-facter`
]
++ lib.optional (lib.versionAtLeast config.nix.package.version "2.24")
# needed to deploy via `clan machines update` if the flake has a git input
# newer version of nix do have `libgit2`
pkgs.gitMinimal;
} }

View File

@@ -9,7 +9,7 @@ import sys
import timeit import timeit
import weakref import weakref
from collections.abc import Iterator from collections.abc import Iterator
from contextlib import contextmanager from contextlib import ExitStack, contextmanager
from enum import Enum from enum import Enum
from pathlib import Path from pathlib import Path
from typing import IO, Any from typing import IO, Any
@@ -86,6 +86,23 @@ def terminate_process_group(process: subprocess.Popen) -> Iterator[None]:
pass pass
@contextmanager
def terminate_process(process: subprocess.Popen) -> Iterator[None]:
try:
yield
finally:
try:
process.terminate()
try:
with contextlib.suppress(subprocess.TimeoutExpired):
# give the process time to terminate
process.wait(3)
finally:
process.kill()
except ProcessLookupError:
pass
class TimeTable: class TimeTable:
""" """
This class is used to store the time taken by each command This class is used to store the time taken by each command
@@ -146,20 +163,24 @@ def run(
logger.debug(f"$: {shlex.join(cmd)} \nCaller: {get_caller()}") logger.debug(f"$: {shlex.join(cmd)} \nCaller: {get_caller()}")
start = timeit.default_timer() start = timeit.default_timer()
# Start the subprocess with ExitStack() as stack:
with ( process = stack.enter_context(
subprocess.Popen( subprocess.Popen(
cmd, cmd,
cwd=str(cwd), cwd=str(cwd),
env=env, env=env,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
start_new_session=not needs_user_terminal, start_new_session=not needs_user_terminal,
) as process, )
terminate_process_group(process) )
if not needs_user_terminal
else contextlib.suppress(), # NOQA: B022 if needs_user_terminal:
): # we didn't allocat a new session, so we can't terminate the process group
stack.enter_context(terminate_process(process))
else:
stack.enter_context(terminate_process_group(process))
stdout_buf, stderr_buf = handle_output(process, log) stdout_buf, stderr_buf = handle_output(process, log)
if input: if input:

View File

@@ -1,4 +1,4 @@
{ inputs, lib, ... }: { inputs, ... }:
{ {
imports = [ imports = [
@@ -22,20 +22,16 @@
perSystem = perSystem =
{ config, pkgs, ... }: { config, pkgs, ... }:
{ {
packages = packages = {
{ tea-create-pr = pkgs.callPackage ./tea-create-pr { formatter = config.treefmt.build.wrapper; };
tea-create-pr = pkgs.callPackage ./tea-create-pr { formatter = config.treefmt.build.wrapper; }; zerotier-members = pkgs.callPackage ./zerotier-members { };
zerotier-members = pkgs.callPackage ./zerotier-members { }; zt-tcp-relay = pkgs.callPackage ./zt-tcp-relay { };
zt-tcp-relay = pkgs.callPackage ./zt-tcp-relay { }; moonlight-sunshine-accept = pkgs.callPackage ./moonlight-sunshine-accept { };
moonlight-sunshine-accept = pkgs.callPackage ./moonlight-sunshine-accept { }; merge-after-ci = pkgs.callPackage ./merge-after-ci { inherit (config.packages) tea-create-pr; };
merge-after-ci = pkgs.callPackage ./merge-after-ci { inherit (config.packages) tea-create-pr; }; pending-reviews = pkgs.callPackage ./pending-reviews { };
pending-reviews = pkgs.callPackage ./pending-reviews { }; editor = pkgs.callPackage ./editor/clan-edit-codium.nix { };
editor = pkgs.callPackage ./editor/clan-edit-codium.nix { }; classgen = pkgs.callPackage ./classgen { };
classgen = pkgs.callPackage ./classgen { }; zerotierone = pkgs.callPackage ./zerotierone { };
zerotierone = pkgs.callPackage ./zerotierone { }; };
}
// lib.optionalAttrs pkgs.stdenv.isLinux {
nixos-facter = pkgs.callPackage ./nixos-facter { };
};
}; };
} }

View File

@@ -1,63 +0,0 @@
{
buildGoModule,
hwinfo,
libusb1,
util-linux,
pciutils,
pkg-config,
lib,
fetchFromGitHub,
stdenv,
}:
let
hwinfo' = hwinfo.overrideAttrs {
src = fetchFromGitHub {
owner = "numtide";
repo = "hwinfo";
rev = "6944732764aecd701f807cd746ff605d2b749549";
hash = "sha256-onJQPVp12hJig56KoXTvps7DzO/7/VBbD5auzxMLNTY=";
};
};
in
buildGoModule rec {
pname = "nixos-facter";
version = "0-unstable-2024-08-26";
src = fetchFromGitHub {
owner = "numtide";
repo = "nixos-facter";
rev = "30a01d3771d4d3d7f44e3f33d589f2c389ebcc63";
hash = "sha256-mbfYJbrqCASsNW6mMtyf4aIpzME9jgaNToWyI0OlPt8=";
};
vendorHash = "sha256-8yQO7topYvXL6bP0oSVN1rApiPjse4Q2bjFNM5jVl8c=";
buildInputs = [
libusb1
hwinfo'
];
nativeBuildInputs = [ pkg-config ];
runtimeInputs = [
libusb1
util-linux
pciutils
];
ldflags = [
"-s"
"-w"
"-X github.com/numtide/nixos-facter/pkg/build.Name=nixos-facter"
"-X github.com/numtide/nixos-facter/pkg/build.Version=v${version}"
"-X github.com/numtide/nixos-facter/pkg/build.System=${stdenv.hostPlatform.system}"
];
meta = with lib; {
description = "nixos-facter: declarative nixos-generate-config";
homepage = "https://github.com/numtide/nixos-facter";
license = licenses.mit;
platforms = platforms.linux;
mainProgram = "nixos-facter";
};
}