From f35481f6bf9bd9e54668ac10406958d2811e7a1b Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Sun, 28 Jan 2024 11:45:19 -0600 Subject: [PATCH] finish styx rename --- styx/default.nix | 11 ---- styx/lock.json | 1 - styx/styx.nim | 142 ----------------------------------------------- styx/styx.nimble | 14 ----- styx/styx.sh | 136 --------------------------------------------- todo.md | 4 +- 6 files changed, 2 insertions(+), 306 deletions(-) delete mode 100644 styx/default.nix delete mode 100644 styx/lock.json delete mode 100644 styx/styx.nim delete mode 100644 styx/styx.nimble delete mode 100755 styx/styx.sh diff --git a/styx/default.nix b/styx/default.nix deleted file mode 100644 index b4549b3..0000000 --- a/styx/default.nix +++ /dev/null @@ -1,11 +0,0 @@ -{ - lib, - buildNimPackage, - fetchFromGitHub, -}: -buildNimPackage (final: prev: { - pname = "styx"; - version = "2023.1001"; - src = ./.; - lockFile = ./lock.json; -}) diff --git a/styx/lock.json b/styx/lock.json deleted file mode 100644 index f2a5012..0000000 --- a/styx/lock.json +++ /dev/null @@ -1 +0,0 @@ -{"depends":[{"method":"fetchzip","packages":["cligen"],"path":"/nix/store/b5dgqx2wds42kw2241qv7rmdf29hwl20-source","ref":"1.6.18","rev":"c54e2f3ea09d405a0d1b9bd8e7c0472d657d1193","sha256":"0ms572f6563bc2cr65gnh943adld5xbd6jy2w7gwvybxpczkxlf3","srcDir":"","url":"https://github.com/c-blake/cligen/archive/c54e2f3ea09d405a0d1b9bd8e7c0472d657d1193.tar.gz"}]} diff --git a/styx/styx.nim b/styx/styx.nim deleted file mode 100644 index dd0d272..0000000 --- a/styx/styx.nim +++ /dev/null @@ -1,142 +0,0 @@ -import std/[logging, os, osproc, tables, times] -from std/nativesockets import getHostname - - -var logger = newConsoleLogger() -addHandler(logger) - -let summaryFilePath = getEnv("GITHUB_STEP_SUMMARY") - -proc writeToSummary(msg: string) = - let f = open(summaryFilePath, mode = fmAppend) - write(f,msg) - close(f) - -type - StyxContext = object - flake, host: string - cache = "daylin" - nom: bool = true - -proc newCtx(): StyxContext = - result = StyxContext() - result.flake = getEnv("FLAKE_PATH", getEnv("HOME") / "nixcfg") - result.host = getHostname() - -proc systemFlakePath(c: StyxContext): string = - c.flake & "#nixosConfigurations." & c.host & ".config.system.build.toplevel" - -proc execQuit(cmd: string) = - quit (execCmd cmd) - -proc build(c: StyxContext) = - ## build nixos - let - cmd = if c.nom: "nom" else: "nix" - execQuit cmd & " build " & c.systemFlakePath - -proc dry(c: StyxContext) = - ## poor man's nix flake check - execQuit "nix build " & c.systemFlakePath & " --dry-run" - -proc cache(c: StyxContext) = - ## build and upload to binary cache - let start = getTime() - let code = execCmd """ - cachix watch-exec """ & c.cache & """ \ - -- \ - nix build """ & c.systemFlakePath & """ \ - --print-build-logs \ - --accept-flake-config - """ - let duration = (getTime() - start) - if code != 0: - error "failed to build configuration for: ", c.host - - if summaryFilePath != "": - writeToSummary( - "Built host: " & c.host & " in " & $duration & " seconds" - ) - info "Built host: " & c.host & " in " & $duration & " seconds" - -proc touchPr(c: StyxContext) = - const cmds = ["git branch -D update_flake_lock_action", - "git fetch origin", - "git checkout update_flake_lock_action", - "git commit --amend --no-edit", - "git push origin update_flake_lock_action --force"] - for cmd in cmds: - let code = execCmd cmd - if code != 0: - error "command: ",cmd,"exited with code: ",$code - -proc nixosRebuild(c: StyxContext, cmd: string) = - execQuit "sudo nixos-rebuild " & cmd & " " & " --flake " & c.flake - -proc boot(c: StyxContext) = - ## nixos rebuild boot - nixosRebuild c, "build" - -proc switch(c: StyxContext) = - ## nixos rebuild switch - nixosRebuild c, "switch" - -proc runCmd(c: StyxContext, cmd: string) = - case cmd: - of "dry": dry c - of "switch": switch c - of "boot": boot c - of "cache": cache c - of "build": build c - of "touch-pr": touchPr c - else: - error "unknown command: ", cmd - quit 1 - - -const usage = """ -styx [opts] - commands: - dry poor man's nix flake check - boot nixos-rebuild boot - switch nixos-rebuild switch - cache build and push to cachix - build build system flake - touch-pr trigger Github Action Ci - - options: - --help > show this help - -h|--host > hostname (current host) - -f|--flake > path to flake ($FLAKE_PATH or $HOME/styx) - -c|--cache > name of cachix binary cache (daylin) -""" - -proc parseFlag(c: var StyxContext, key, val: string) = - case key: - of "help": - echo usage; quit 0 - of "h","host": - c.host = val - of "f","flake": - c.flake = val - of "no-nom": - c.nom = false - -when isMainModule: - import std/parseopt - var - c = newCtx() - cmd: string - for kind, key, val in getopt(): - case kind - of cmdArgument: - cmd = key - of cmdLongOption, cmdShortOption: - parseFlag c, key, val - of cmdEnd: - discard - if cmd == "": - echo "please specify a command, see below" - echo usage; quit 1 - info $c - runCmd c, cmd diff --git a/styx/styx.nimble b/styx/styx.nimble deleted file mode 100644 index decc7b9..0000000 --- a/styx/styx.nimble +++ /dev/null @@ -1,14 +0,0 @@ -# Package - -author = "Daylin Morgan" -version = "2023.1001" -description = "styx" -license = "MIT" -srcDir = "." -bin = @["styx"] - - -# Dependencies - -requires "nim >= 2.0.0" -requires "cligen" diff --git a/styx/styx.sh b/styx/styx.sh deleted file mode 100755 index 4da2aae..0000000 --- a/styx/styx.sh +++ /dev/null @@ -1,136 +0,0 @@ -#!/usr/bin/env bash - -set -e - -TERM=${TERM:-dumb} -HOSTNAME=${HOSTNAME:-$(hostname)} -FLAKE_PATH=${FLAKE_PATH:-$HOME/nixcfg} - -DIM="$(tput dim)" -BOLD="$(tput bold)" -RED="$(tput setaf 1)" -GREEN="$(tput setaf 2)" -YELLOW="$(tput setaf 3)" -CYAN="$(tput setaf 4)" -RESET="$(tput sgr0)" -PREFIX="${CYAN}styx${RESET}" - -log() { - printf "%s | %s\n" "$PREFIX" "$*" -} - -error() { - printf "%s | %s | %s\n" "$PREFIX" "${RED}error${RESET}" "$*" -} - -help() { - cat < [-h] - ${DIM}sister moon to nix on pluto - sister software to nix in this repo${RESET} - -${BOLD}commands${RESET}: -EOF - printf "${GREEN}%8s${RESET} | ${YELLOW}%s${RESET}\n" \ - fmt "format *.nix" \ - build "build and monitor with nom" \ - boot "evaluate flake for next boot" \ - switch "perform nixos rebuild" \ - store "run some store cleanup" \ - cache "nix build and push to daylin.cachix.org" - exit -} - -fmt() { - alejandra . "$@" -} - -boot() { - sudo nixos-rebuild boot --flake "$FLAKE_PATH" "$@" -} - -switch() { - sudo nixos-rebuild switch --flake "$FLAKE_PATH" "$@" -} - -store() { - nix store optimise "$@" -} - -build() { - nom build "$FLAKE_PATH#nixosConfigurations.${HOSTNAME}.config.system.build.toplevel" - case "$1" in - switch | boot | test ) sudo ./result/bin/switch-to-configuration "$1";; - esac -} - -dry() { - # poor mans nix flake check - nix build "$FLAKE_PATH#nixosConfigurations.${HOSTNAME}.config.system.build.toplevel" --dry-run -} - - -cache() { - start=$(date +%s) - - cachix watch-exec daylin \ - -- \ - nix build "$FLAKE_PATH#nixosConfigurations.${HOSTNAME}.config.system.build.toplevel" \ - --print-build-logs \ - --accept-flake-config - - end=$(date +%s) - runtime=$(date -d@$((end-start)) +'%M minutes, %S seconds') - - echo "Built host: ${HOSTNAME} in ${runtime} seconds" >> "$GITHUB_STEP_SUMMARY" -} - - -if [[ $# -eq 0 ]]; then - log no command specified see below for help - help -fi - -while [[ $# -gt 0 ]]; do - case $1 in - fmt | boot | switch | store | build | dry | cache) - cmd=$1 - shift - ;; - -f | --flake) - FLAKE_PATH="$2" - shift; shift; - ;; - -h | --host) - shift - HOSTNAME="$1" - shift; - ;; - --help) - help - ;; - --) - shift - break - ;; - -*,--*) - error "unknown flag: ${BOLD}$1${RESET}" - exit 1 - ;; - *) - error "unknown command: ${BOLD}$1${RESET}" - exit 1 - ;; - esac -done - -if [[ $# -gt 0 ]]; then - echo "forwarding args: ${BOLD}$*${RESET}" -fi - -if [[ -z ${cmd+x} ]]; then - error "please specify a command" - help -fi - -$cmd "$@" diff --git a/todo.md b/todo.md index a0373e2..ff56ca0 100644 --- a/todo.md +++ b/todo.md @@ -1,5 +1,5 @@ -# daylin's nixcfg todo's +# oizys todo's -- [ ] add a styx command to trigger build on flake.lock pr +