add autocommit tooling, update commits
This commit is contained in:
parent
7a99665915
commit
d68648a43c
7 changed files with 288 additions and 24 deletions
|
@ -3,7 +3,7 @@
|
||||||
(url "https://git.savannah.gnu.org/git/guix.git")
|
(url "https://git.savannah.gnu.org/git/guix.git")
|
||||||
(branch "master")
|
(branch "master")
|
||||||
(commit
|
(commit
|
||||||
"d97a67d41de142c0fbdba55e96bfc147482bfae2")
|
"c56505e399834a3f68cf2b6715b42f12ceea217a")
|
||||||
(introduction
|
(introduction
|
||||||
(make-channel-introduction
|
(make-channel-introduction
|
||||||
"9edb3f66fd807b096b48283debdcddccfea34bad"
|
"9edb3f66fd807b096b48283debdcddccfea34bad"
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
(url "https://g.freya.cat/freya/sakura")
|
(url "https://g.freya.cat/freya/sakura")
|
||||||
(branch "main")
|
(branch "main")
|
||||||
(commit
|
(commit
|
||||||
"e6d80dd95a7fcd205265094c0047d0c2cfd09e15")
|
"8b7a2148c891bb4b3324d6bd5df95982236c1039")
|
||||||
(introduction
|
(introduction
|
||||||
(make-channel-introduction
|
(make-channel-introduction
|
||||||
"8fb2f9c2fa414754c41c1c73665e3e73e12693ab"
|
"8fb2f9c2fa414754c41c1c73665e3e73e12693ab"
|
||||||
|
|
|
@ -15,7 +15,7 @@ then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PATH=$PATH:$HOME/.cargo/bin
|
PATH=$PATH:$HOME/.cargo/bin
|
||||||
PATH=$PATH:/var/lib/flatpak/exports/bin
|
PATH=$PATH:$HOME/.config/guix/scripts
|
||||||
DOCKER_HOME="$HOME/.docker"
|
DOCKER_HOME="$HOME/.docker"
|
||||||
|
|
||||||
# vim mode >:)
|
# vim mode >:)
|
||||||
|
@ -30,19 +30,12 @@ else
|
||||||
export PS1="$$USER: "
|
export PS1="$$USER: "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# reconfigure aliases
|
|
||||||
alias reconfigure-system="sudo -E guix system -L $HOME/.config/guix/modules reconfigure $HOME/.config/guix/systems/$(hostname).scm"
|
|
||||||
alias reconfigure-user="guix home -L $HOME/.config/guix/modules reconfigure $HOME/.config/guix/home/home.scm"
|
|
||||||
alias reconfigure-nix="home-manager switch"
|
|
||||||
|
|
||||||
# aliases
|
# aliases
|
||||||
alias neo="pfetch"
|
|
||||||
alias rf="rm -fr" # remove le french hon hon hon
|
alias rf="rm -fr" # remove le french hon hon hon
|
||||||
alias ls="ls --color=auto"
|
alias ls="ls --color=auto"
|
||||||
alias ip="ip --color=auto"
|
alias ip="ip --color=auto"
|
||||||
alias grep="grep --color=auto"
|
alias grep="grep --color=auto"
|
||||||
alias diff="diff --color=auto"
|
alias diff="diff --color=auto"
|
||||||
alias ccat="highlight --out-format=ansi"
|
|
||||||
alias vim="nvim"
|
alias vim="nvim"
|
||||||
alias ssh='TERM=xterm-256color ssh' # xterm-kitty bad
|
alias ssh='TERM=xterm-256color ssh' # xterm-kitty bad
|
||||||
|
|
||||||
|
@ -87,8 +80,4 @@ bindkey "^F" ranger
|
||||||
export GPG_TTY=$(tty)
|
export GPG_TTY=$(tty)
|
||||||
|
|
||||||
# ricing
|
# ricing
|
||||||
export PF_CUSTOM_LOGOS="/home/freya/.config/zsh/pfetch_logos"
|
|
||||||
|
|
||||||
pfetch
|
pfetch
|
||||||
|
|
||||||
PWD="$HOME"
|
|
||||||
|
|
|
@ -22,17 +22,17 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1732025103,
|
"lastModified": 1733484277,
|
||||||
"narHash": "sha256-qjEI64RKvDxRyEarY0jTzrZMa8ebezh2DEZmJJrpVdo=",
|
"narHash": "sha256-i5ay20XsvpW91N4URET/nOc0VQWOAd4c4vbqYtcH8Rc=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "home-manager",
|
"repo": "home-manager",
|
||||||
"rev": "a46e702093a5c46e192243edbd977d5749e7f294",
|
"rev": "d00c6f6d0ad16d598bf7e2956f52c1d9d5de3c3a",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "home-manager",
|
"repo": "home-manager",
|
||||||
"rev": "a46e702093a5c46e192243edbd977d5749e7f294",
|
"rev": "d00c6f6d0ad16d598bf7e2956f52c1d9d5de3c3a",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -60,17 +60,17 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1732014248,
|
"lastModified": 1733212471,
|
||||||
"narHash": "sha256-y/MEyuJ5oBWrWAic/14LaIr/u5E0wRVzyYsouYY3W6w=",
|
"narHash": "sha256-M1+uCoV5igihRfcUKrr1riygbe73/dzNnzPsmaLCmpo=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "23e89b7da85c3640bbc2173fe04f4bd114342367",
|
"rev": "55d15ad12a74eb7d4646254e13638ad0c4128776",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "23e89b7da85c3640bbc2173fe04f4bd114342367",
|
"rev": "55d15ad12a74eb7d4646254e13638ad0c4128776",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
# nixpkgs
|
# nixpkgs
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/23e89b7da85c3640bbc2173fe04f4bd114342367";
|
nixpkgs.url = "github:nixos/nixpkgs/55d15ad12a74eb7d4646254e13638ad0c4128776";
|
||||||
|
|
||||||
# home manager
|
# home manager
|
||||||
home-manager.url = "github:nix-community/home-manager/a46e702093a5c46e192243edbd977d5749e7f294";
|
home-manager.url = "github:nix-community/home-manager/d00c6f6d0ad16d598bf7e2956f52c1d9d5de3c3a";
|
||||||
home-manager.inputs.nixpkgs.follows = "nixpkgs";
|
home-manager.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
|
||||||
# nixgl
|
# nixgl
|
||||||
|
|
3
scripts/reconfigure-system
Executable file
3
scripts/reconfigure-system
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
repo="$HOME/.config/guix"
|
||||||
|
sudo -E guix system -L "$repo/modules" reconfigure "$repo/systems/$(hostname).scm"
|
4
scripts/reconfigure-user
Executable file
4
scripts/reconfigure-user
Executable file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/sh
|
||||||
|
repo="$HOME/.config/guix"
|
||||||
|
guix home -L "$repo/modules" reconfigure "$repo/home/home.scm"
|
||||||
|
home-manager switch
|
268
scripts/update-commits
Executable file
268
scripts/update-commits
Executable file
|
@ -0,0 +1,268 @@
|
||||||
|
#!/run/current-system/profile/bin/guile -s
|
||||||
|
!#
|
||||||
|
|
||||||
|
(use-modules (guix)
|
||||||
|
(guix channels)
|
||||||
|
(guix import json)
|
||||||
|
(guix git)
|
||||||
|
(ice-9 popen)
|
||||||
|
(ice-9 textual-ports)
|
||||||
|
(ice-9 pretty-print)
|
||||||
|
(srfi srfi-1)) ;; alist
|
||||||
|
|
||||||
|
;;
|
||||||
|
;; config
|
||||||
|
;;
|
||||||
|
|
||||||
|
(define %dotfiles-dir
|
||||||
|
(string-append
|
||||||
|
(getenv "HOME")
|
||||||
|
"/.config/guix"))
|
||||||
|
|
||||||
|
(define %guix-channels-file
|
||||||
|
(string-append %dotfiles-dir "/channels.scm"))
|
||||||
|
|
||||||
|
(define %nix-flake-file
|
||||||
|
(string-append %dotfiles-dir "/home/nix/flake.nix"))
|
||||||
|
|
||||||
|
(define %guix-cuirass-servers
|
||||||
|
(list "https://cuirass.nonguix.org"
|
||||||
|
"https://cuirass.freya.cat"))
|
||||||
|
|
||||||
|
;;
|
||||||
|
;; io functions
|
||||||
|
;;
|
||||||
|
|
||||||
|
(define (invoke . args)
|
||||||
|
(let* ((command (string-join args " "))
|
||||||
|
(err-cons (pipe))
|
||||||
|
(port (with-error-to-port (cdr err-cons)
|
||||||
|
(lambda _ (open-input-pipe command))))
|
||||||
|
(_ (setvbuf (car err-cons) 'block
|
||||||
|
(* 1024 16))) ; 16kib buffer
|
||||||
|
(result (get-string-all port)))
|
||||||
|
(close-port (cdr err-cons))
|
||||||
|
result))
|
||||||
|
|
||||||
|
(define (read-file path)
|
||||||
|
(call-with-input-file path get-string-all))
|
||||||
|
|
||||||
|
(define (write-file path contents)
|
||||||
|
(call-with-output-file path (lambda (port)
|
||||||
|
(put-string port contents))))
|
||||||
|
|
||||||
|
;;
|
||||||
|
;; git functions
|
||||||
|
;;
|
||||||
|
|
||||||
|
(define (git-checkout git-url)
|
||||||
|
;; create or update a local bare git checkout from <git-url>
|
||||||
|
;; - clones checkout if it doesnt exist
|
||||||
|
;; - fetches newset commits
|
||||||
|
(let* ((home (getenv "HOME"))
|
||||||
|
(name (string-append
|
||||||
|
(string-replace-substring
|
||||||
|
(last (string-split git-url #\/))
|
||||||
|
".git"
|
||||||
|
"")
|
||||||
|
".git"))
|
||||||
|
(dir (string-append home
|
||||||
|
"/.cache/checkouts/"
|
||||||
|
name)))
|
||||||
|
(if (not (access? dir F_OK))
|
||||||
|
(begin
|
||||||
|
(format #t "checking out ~a...\n" name)
|
||||||
|
(invoke "mkdir" "-p" dir)
|
||||||
|
(invoke "git" "clone" "--bare" git-url dir)))
|
||||||
|
(invoke "git" "-C" dir "fetch")
|
||||||
|
dir))
|
||||||
|
|
||||||
|
(define (git-latest-commit git-url)
|
||||||
|
(car (string-split
|
||||||
|
(invoke "git" "ls-remote" git-url "HEAD")
|
||||||
|
#\tab)))
|
||||||
|
|
||||||
|
(define (commit-timestamp git-url commit)
|
||||||
|
; get the unix timestamp of a <commit> in git repo <git-url>
|
||||||
|
(let* ((dir (git-checkout git-url))
|
||||||
|
(timestamp
|
||||||
|
(invoke "git" "-C" dir "show" "--quiet" "--format=%at" commit)))
|
||||||
|
(string->number (string-trim-both timestamp #\newline))))
|
||||||
|
|
||||||
|
;;
|
||||||
|
;; core functions
|
||||||
|
;;
|
||||||
|
|
||||||
|
(define (merge-commits local-commits remote-commits)
|
||||||
|
;; create a zipped pair of each <loacl> and <remote> commits
|
||||||
|
;; - ignores the commit if the remote its older than the local commit
|
||||||
|
;;
|
||||||
|
;; local commit format:
|
||||||
|
;; ('id "git-url" "commit")
|
||||||
|
;;
|
||||||
|
;; remote commit format:
|
||||||
|
;; ('id . "commit")
|
||||||
|
;;
|
||||||
|
;; return format:
|
||||||
|
;; ('id "local-commit" "newest-commit") ;; neweset commit is commit with
|
||||||
|
;; ;; newer timestamp
|
||||||
|
(fold (lambda (local-repo commits)
|
||||||
|
(let* ((repo-id (car local-repo))
|
||||||
|
(git-url (cadr local-repo))
|
||||||
|
; local
|
||||||
|
(local-commit (caddr local-repo))
|
||||||
|
(local-timestamp (commit-timestamp git-url local-commit))
|
||||||
|
; remote
|
||||||
|
(remote-commit (assoc-ref remote-commits repo-id))
|
||||||
|
(remote-timestamp (if (string? remote-commit)
|
||||||
|
(commit-timestamp git-url remote-commit)))
|
||||||
|
; newest
|
||||||
|
(newest-commit (if (and (number? remote-timestamp)
|
||||||
|
(> remote-timestamp local-timestamp))
|
||||||
|
remote-commit))
|
||||||
|
; result
|
||||||
|
(result (if (string? newest-commit)
|
||||||
|
(cons (list repo-id local-commit newest-commit)
|
||||||
|
commits)
|
||||||
|
commits)))
|
||||||
|
result))
|
||||||
|
'()
|
||||||
|
local-commits))
|
||||||
|
|
||||||
|
(define (update-file local-commits remote-commits path)
|
||||||
|
(let* ((contents (read-file path))
|
||||||
|
(commits (merge-commits local-commits remote-commits))
|
||||||
|
(result (fold (lambda (pair contents)
|
||||||
|
(let ((repo-id (car pair))
|
||||||
|
(local-commit (cadr pair))
|
||||||
|
(remote-commit (caddr pair)))
|
||||||
|
(format #t "~s\t~a -> ~a\n"
|
||||||
|
repo-id
|
||||||
|
(string-take local-commit 7)
|
||||||
|
(string-take remote-commit 7))
|
||||||
|
(string-replace-substring contents
|
||||||
|
local-commit
|
||||||
|
remote-commit)))
|
||||||
|
(read-file path)
|
||||||
|
commits)))
|
||||||
|
(write-file path result)))
|
||||||
|
|
||||||
|
;;
|
||||||
|
;; guix functions
|
||||||
|
;;
|
||||||
|
|
||||||
|
(define (cuirass-latest-evaluation cuirass-url)
|
||||||
|
(json-fetch
|
||||||
|
(string-append
|
||||||
|
cuirass-url
|
||||||
|
"/api/evaluations?nr=1")))
|
||||||
|
|
||||||
|
(define (guix-local-commits channels)
|
||||||
|
(map (lambda (channel)
|
||||||
|
(list (channel-name channel)
|
||||||
|
(channel-url channel)
|
||||||
|
(channel-commit channel)))
|
||||||
|
channels))
|
||||||
|
|
||||||
|
(define (cuirass-commits cuirass-servers)
|
||||||
|
(fold (lambda (cuirass-url env)
|
||||||
|
(let* ((evaluation (cuirass-latest-evaluation cuirass-url))
|
||||||
|
(checkouts (vector->list
|
||||||
|
(assoc-ref
|
||||||
|
(car (vector->list evaluation))
|
||||||
|
"checkouts"))))
|
||||||
|
(fold (lambda (checkout env)
|
||||||
|
(let* ((channel (string->symbol
|
||||||
|
(assoc-ref checkout "channel")))
|
||||||
|
(commit (assoc-ref checkout "commit")))
|
||||||
|
(if (assoc-ref env channel)
|
||||||
|
;; channel already set, skip
|
||||||
|
env
|
||||||
|
;; add commit to env
|
||||||
|
(assoc-set! env channel commit))))
|
||||||
|
env
|
||||||
|
checkouts)))
|
||||||
|
'()
|
||||||
|
cuirass-servers))
|
||||||
|
|
||||||
|
;;
|
||||||
|
;; nix functions
|
||||||
|
;;
|
||||||
|
|
||||||
|
(define (nix-local-commits flake-file)
|
||||||
|
(let ((lines (filter
|
||||||
|
(lambda (line)
|
||||||
|
(string-contains line "github:"))
|
||||||
|
(string-split (read-file flake-file)
|
||||||
|
#\newline))))
|
||||||
|
(map
|
||||||
|
;; valid line, parse out repo-id, git-url, and commit
|
||||||
|
(lambda (line)
|
||||||
|
(let* ((trimmed (substring line
|
||||||
|
(+ (string-index line #\:) 1)
|
||||||
|
(string-rindex line #\")))
|
||||||
|
(pair (string-split trimmed #\/))
|
||||||
|
(repo-id (string->symbol (cadr pair)))
|
||||||
|
(git-url (string-append "https://github.com/"
|
||||||
|
(car pair) "/"
|
||||||
|
(cadr pair) ".git"))
|
||||||
|
(commit (caddr pair)))
|
||||||
|
(list repo-id git-url commit)))
|
||||||
|
lines)))
|
||||||
|
|
||||||
|
(define (nix-nixpkgs-commit)
|
||||||
|
(let ((json (json-fetch
|
||||||
|
(string-append
|
||||||
|
"https://raw.githubusercontent.com/"
|
||||||
|
"nix-community/home-manager"
|
||||||
|
"/refs/heads/master/flake.lock")
|
||||||
|
#:timeout 1)))
|
||||||
|
(fold
|
||||||
|
(lambda (key json)
|
||||||
|
(assoc-ref json key))
|
||||||
|
json
|
||||||
|
(list "nodes"
|
||||||
|
"nixpkgs"
|
||||||
|
"locked"
|
||||||
|
"rev"))))
|
||||||
|
|
||||||
|
(define (nix-remote-commits local-commits)
|
||||||
|
(fold (lambda (pair env)
|
||||||
|
(let* ((repo-id (car pair))
|
||||||
|
(git-url (cadr pair))
|
||||||
|
(commit (if (eq? repo-id 'nixpkgs)
|
||||||
|
(nix-nixpkgs-commit)
|
||||||
|
(git-latest-commit git-url))))
|
||||||
|
(assoc-set! env repo-id commit)))
|
||||||
|
'()
|
||||||
|
local-commits))
|
||||||
|
|
||||||
|
;;
|
||||||
|
;; update
|
||||||
|
;;
|
||||||
|
|
||||||
|
(define %guix-local-commits
|
||||||
|
(guix-local-commits
|
||||||
|
(load %guix-channels-file)))
|
||||||
|
|
||||||
|
(define %guix-remote-commits
|
||||||
|
(cuirass-commits %guix-cuirass-servers))
|
||||||
|
|
||||||
|
(define %nix-local-commits
|
||||||
|
(nix-local-commits %nix-flake-file))
|
||||||
|
|
||||||
|
(define %nix-remote-commits
|
||||||
|
(nix-remote-commits %nix-local-commits))
|
||||||
|
|
||||||
|
(update-file
|
||||||
|
%guix-local-commits
|
||||||
|
%guix-remote-commits
|
||||||
|
%guix-channels-file)
|
||||||
|
|
||||||
|
(update-file
|
||||||
|
%nix-local-commits
|
||||||
|
%nix-remote-commits
|
||||||
|
%nix-flake-file)
|
||||||
|
|
||||||
|
(system* "guix" "pull" "-C" %guix-channels-file)
|
||||||
|
(system* "nix" "flake" "lock" (dirname %nix-flake-file))
|
Loading…
Reference in a new issue