feat(legacy): +writeDash +helpers

This commit is contained in:
2025-11-03 18:51:38 +00:00
parent ad00891e6b
commit 532f4b0901
12 changed files with 117 additions and 65 deletions

View File

@@ -1,8 +1,4 @@
{
system,
pkgs,
self
}:
{ system, pkgs, self, ... }:
(import ./dev { inherit self system pkgs; })
// {
c = import ./c.nix { inherit self system pkgs; };

View File

@@ -68,57 +68,15 @@
system,
pkgs,
}: {
packages.${system} = import ./package { inherit system self pkgs inputs; };
devShells.${system} = import ./devshell { inherit system self pkgs; };
legacyPackages.${system} = import ./legacy {
inherit system self;
pkgs = import nixpkgs { inherit system; };
};
nixosConfigurations = {
"devvm-manual|${system}" = import ./nixos/system/devvm-manual/default.nix
{ inherit flake self inputs system; };
"devvm-hemar|${system}" = import ./nixos/system/devvm-hemar/default.nix
{ inherit flake self inputs system; };
};
#nixosTests = let
# testLib = import (nixpkgs + "/nixos/lib/testing-python.nix") { inherit pkgs; };
#in {
# "hardware/lenovo-ideapad-15arh7" = testLib.makeTest {
# name = "hardware/lenovo-ideapad-15arh7";
# nodes.machine = { ... }: {
# imports = [ self.nixosModules.hectic ];
# services.hardware.lenovo-ideapad-15arh7.enable = true;
# };
# testScript = ''
# start_all()
# machine.wait_for_unit("my-service.service")
# machine.succeed("journalctl -u my-service -b | grep -qi hello")
# '';
# };
#};
checks = let
mkSys = system: opts:
(nixpkgs.lib.nixosSystem {
inherit system;
modules = [
self.nixosModules.hectic
{ hectic.hardware.lenovo-ideapad-15arh7 = opts; }
];
});
cases = {
#enable = { enable = true; };
#disabled = { enable = false; };
#customFoo = { enable = true; foo = "bar"; };
};
in nixpkgs.lib.mapAttrs
(name: opts: (mkSys system opts).config.system.build.toplevel) cases;
packages.${system} = import ./package { inherit flake self inputs pkgs system; };
devShells.${system} = import ./devshell { inherit flake self inputs pkgs system; };
legacyPackages.${system} = import ./legacy { inherit flake self inputs pkgs system; };
nixosConfigurations = { };
checks.${system} = import ./test { inherit flake self inputs pkgs system; };
}) // {
lib = self-lib;
overlays.default = import ./overlay { inherit flake self inputs nixpkgs; };
nixosModules = import ./nixos/module { inherit flake self inputs nixpkgs; };
templates = import ./template { inherit flake self inputs nixpkgs; };
overlays.default = import ./overlay { inherit flake self inputs; };
nixosModules = import ./nixos/module { inherit flake self inputs; };
templates = import ./template { inherit flake self inputs; };
};
}

View File

@@ -1,7 +1,8 @@
{ self, system, pkgs }:
{ pkgs, ... }:
let
writers = pkgs.callPackage ./writer { };
in {
helpers = pkgs.callPackage ./helper { };
# NOTE(yukkop): duplicate writers in root of legacyPackages and writers due nixpkgs legacyPackages consistency
writers = writers;
} // writers

View File

@@ -0,0 +1,3 @@
{ callPackage }: {
posix-shell = callPackage ./posix-shell {};
}

View File

@@ -0,0 +1,54 @@
NC='\033[0m'
# Regular text colors
BLACK='\033[30m'
RED='\033[31m'
GREEN='\033[32m'
YELLOW='\033[33m'
BLUE='\033[34m'
MAGENTA='\033[35m'
CYAN='\033[36m'
WHITE='\033[37m'
# Bright text colors
BBLACK='\033[90m'
BRED='\033[91m'
BGREEN='\033[92m'
BYELLOW='\033[93m'
BBLUE='\033[94m'
BMAGENTA='\033[95m'
BCYAN='\033[96m'
BWHITE='\033[97m'
# Background colors
BG_BLACK='\033[40m'
BG_RED='\033[41m'
BG_GREEN='\033[42m'
BG_YELLOW='\033[43m'
BG_BLUE='\033[44m'
BG_MAGENTA='\033[45m'
BG_CYAN='\033[46m'
BG_WHITE='\033[47m'
# Bright background colors
BG_BBLACK='\033[100m'
BG_BRED='\033[101m'
BG_BGREEN='\033[102m'
BG_BYELLOW='\033[103m'
BG_BBLUE='\033[104m'
BG_BMAGENTA='\033[105m'
BG_BCYAN='\033[106m'
BG_BWHITE='\033[107m'
# Text effects
RESET='\033[0m'
BOLD='\033[1m'
DIM='\033[2m'
ITALIC='\033[3m'
UNDERLINE='\033[4m'
BLINK='\033[5m'
INVERSE='\033[7m'
HIDDEN='\033[8m'
STRIKE='\033[9m'
: "$NC" "$BLACK" "$RED" "$GREEN" "$YELLOW" "$BLUE" "$MAGENTA" "$CYAN" "$WHITE" "$BBLACK" "$BRED" "$BGREEN" "$BYELLOW" "$BBLUE" "$BMAGENTA" "$BCYAN" "$BWHITE" "$BG_BLACK" "$BG_RED" "$BG_GREEN" "$BG_YELLOW" "$BG_BLUE" "$BG_MAGENTA" "$BG_CYAN" "$BG_WHITE" "$BG_BBLACK" "$BG_BRED" "$BG_BGREEN" "$BG_BYELLOW" "$BG_BBLUE" "$BG_BMAGENTA" "$BG_BCYAN" "$BG_BWHITE" "$RESET" "$BOLD" "$DIM" "$ITALIC" "$UNDERLINE" "$BLINK" "$INVERSE" "$HIDDEN" "$STRIKE"

View File

@@ -0,0 +1,15 @@
{ dash, hectic }: let
shell = "${dash}/bin/dash";
bashOptions = [
"errexit"
"nounset"
];
in {
log = hectic.writeDash "log.sh" ''
${builtins.readFile ./colors.sh}
${builtins.readFile ./log.sh}
'';
colors = hectic.writeDash "colors.sh" ''
${builtins.readFile ./colors.sh}
'';
}

View File

@@ -0,0 +1,21 @@
#!/bin/dash
log() {
level="${1:?}"; shift
case "$level" in
trace) color="$MAGENTA" ;;
debug) color="$BLUE" ;;
info) color="$GREEN" ;;
notice) color="$CYAN" ;;
warn) color="$YELLOW" ;;
error) color="$RED" ;;
*) color="$WHITE" ;;
esac
# shellcheck disable=SC1003
fmt="$(printf "%s" "${1:?}" | sed 's/\\033\[0m/''\'"$color"'/g')"
shift
printf "%b\n" "$color$fmt$NC" "$@" >&2
}

View File

@@ -1,7 +1,6 @@
{
callPackage
}: rec {
{ callPackage }: rec {
writeShellApplication = callPackage ./writeShellApplication.nix {};
writeDash = callPackage ./writeDash.nix {};
writeC = callPackage ./writeC.nix {};
writeCBin = name: writeC "/bin/${name}";
writeMinCBin = name: includes: body: writeMinC "/bin/${name}" includes body;

View File

@@ -0,0 +1,5 @@
{ dash, lib, writers }: name: argsOrScript:
if lib.isAttrs argsOrScript && !lib.isDerivation argsOrScript then
writers.makeScriptWriter (argsOrScript // { interpreter = "${lib.getExe dash}"; }) name
else
writers.makeScriptWriter { interpreter = "${lib.getExe dash}"; } name argsOrScript

View File

@@ -2,10 +2,9 @@
flake,
self,
inputs,
nixpkgs,
}:
with builtins;
with nixpkgs.lib;
with inputs.nixpkgs.lib;
with self.lib;
let
# Combine hectic modules into one

View File

@@ -1,5 +1,5 @@
{ inputs, self, nixpkgs, ... }: let
lib = nixpkgs.lib;
{ inputs, self, ... }: let
lib = inputs.nixpkgs.lib;
in final: prev: (
let
packages = self.packages.${prev.system};

View File

@@ -1,4 +1,4 @@
{ self, system, pkgs, inputs }: let
{ self, system, pkgs, inputs, ... }: let
rust = {
nativeBuildInputs = [
pkgs.pkgsBuildHost.rust-bin.stable."1.81.0".default
@@ -243,6 +243,7 @@ in {
shellplot = pkgs.callPackage ./shellplot {};
sops = pkgs.callPackage ./sops.nix {};
onlinepubs2man = pkgs.callPackage ./onlinepubs2man {};
migrator = pkgs.callPackage ./migratior {};
pg-17-ext-http = buildHttpExt pkgs "17";
pg-17-ext-smtp-client = buildSmtpExt pkgs "17";
pg-17-ext-plhaskell = buildPlHaskellExt pkgs "17";