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,
lib,
config,
...
}:
{
environment.systemPackages =
[
# 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
pkgs.gitMinimal
];
# newer version of nix do have `libgit2`
pkgs.gitMinimal;
}

View File

@@ -9,7 +9,7 @@ import sys
import timeit
import weakref
from collections.abc import Iterator
from contextlib import contextmanager
from contextlib import ExitStack, contextmanager
from enum import Enum
from pathlib import Path
from typing import IO, Any
@@ -86,6 +86,23 @@ def terminate_process_group(process: subprocess.Popen) -> Iterator[None]:
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:
"""
This class is used to store the time taken by each command
@@ -146,8 +163,8 @@ def run(
logger.debug(f"$: {shlex.join(cmd)} \nCaller: {get_caller()}")
start = timeit.default_timer()
# Start the subprocess
with (
with ExitStack() as stack:
process = stack.enter_context(
subprocess.Popen(
cmd,
cwd=str(cwd),
@@ -155,11 +172,15 @@ def run(
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
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)
if input:

View File

@@ -1,4 +1,4 @@
{ inputs, lib, ... }:
{ inputs, ... }:
{
imports = [
@@ -22,8 +22,7 @@
perSystem =
{ config, pkgs, ... }:
{
packages =
{
packages = {
tea-create-pr = pkgs.callPackage ./tea-create-pr { formatter = config.treefmt.build.wrapper; };
zerotier-members = pkgs.callPackage ./zerotier-members { };
zt-tcp-relay = pkgs.callPackage ./zt-tcp-relay { };
@@ -33,9 +32,6 @@
editor = pkgs.callPackage ./editor/clan-edit-codium.nix { };
classgen = pkgs.callPackage ./classgen { };
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";
};
}