Compare commits

..

1 commit

Author SHA1 Message Date
github-actions[bot]
b832fffc38 flake.lock: Update
Flake lock file updates:

• Updated input 'hyprland':
    'git+https://github.com/hyprwm/Hyprland/?ref=refs/heads/main&rev=bc6b0880dda2607a80f000c134f573c970452a0f&submodules=1' (2024-07-13)
  → 'git+https://github.com/hyprwm/Hyprland/?ref=refs/heads/main&rev=bd526822deb9ed47c0b51b534817aa8541fff07b&submodules=1' (2024-07-15)
• Updated input 'lix':
    'a8f443d960.tar.gz?narHash=sha256-YZ7043PFS6LalHAyGeO7qRLeZIevwjHRbbMkpixjwhM%3D' (2024-07-12)
  → 'd094dd0396.tar.gz?narHash=sha256-xeE9I/oGt%2BIz7AwnadBlzSJRk8I5y1XKYt2ifV/2eo0%3D' (2024-07-16)
• Updated input 'nixos-wsl':
    'github:nix-community/NixOS-WSL/371b5076d718f7f637d3959d0203061f06af1263?narHash=sha256-U3IqoGmIzBKEJ0ihRQ10GRRtdoDBI6Oxl6aiGbUA59A%3D' (2024-07-12)
  → 'github:nix-community/NixOS-WSL/f6db2d325bdf57d39a3ae43376bdf2a020a6aad2?narHash=sha256-wuHiinPG5CzCUBr9I51g%2BIRhP/69Y9gRVh%2BQnEtFnyI%3D' (2024-07-15)
• Updated input 'nixos-wsl/nixpkgs':
    'github:NixOS/nixpkgs/49ee0e94463abada1de470c9c07bfc12b36dcf40?narHash=sha256-WrDV0FPMVd2Sq9hkR5LNHudS3OSMmUrs90JUTN%2BMXpA%3D' (2024-07-06)
  → 'github:NixOS/nixpkgs/f12ee5f64c6a09995e71c9626d88c4efa983b488?narHash=sha256-FZ5dnrvKkln9ESdoTR8R7GKW9rNpXNZrxGsOXsbsTpE%3D' (2024-07-12)
• Updated input 'nixpkgs':
    'github:nixos/nixpkgs/b729601a9e6c459fd8884dea513af143111bed54?narHash=sha256-1Al1qDC8Q/s4viPq4ln8jfHWZxYl%2BNb49dNFISFpqBY%3D' (2024-07-13)
  → 'github:nixos/nixpkgs/b2c1f10bfbb3f617ea8e8669ac13f3f56ceb2ea2?narHash=sha256-USDsS90/88RJibP3gEcH1AaVt%2BJpnX4XCUD9bAJP5I4%3D' (2024-07-15)
• Updated input 'nixpkgs-wayland':
    'github:nix-community/nixpkgs-wayland/09a28c6e377ae40c67d79f0a98c5bff3c59457b8?narHash=sha256-7tz2witA6mIxX3250WyhD8rvXQxlSzQFEDdVLYvzEU8%3D' (2024-07-14)
  → 'github:nix-community/nixpkgs-wayland/7421424feb2e68a173f6fd218bbf71eb352404e5?narHash=sha256-9%2Bv7DYzlQn0djo2j11Ges0uj5WzWajpob/Y3WcsEFks%3D' (2024-07-15)
• Updated input 'nixpkgs-wayland/lib-aggregate':
    'github:nix-community/lib-aggregate/5865544e7c012ecaa952f5c6cf5878c1676b52b4?narHash=sha256-cyl6Cxqo4bNmwLXi8/qIc3U1vRJ9VyIBUL/j3is4x58%3D' (2024-07-07)
  → 'github:nix-community/lib-aggregate/6e56a6fd1d993eb02c991d449819f01340888e02?narHash=sha256-ggCV3etL7W1X9kxhLPZP35%2BBBh1LgQybene%2BL/aeQaQ%3D' (2024-07-14)
• Updated input 'nixpkgs-wayland/lib-aggregate/nixpkgs-lib':
    'github:nix-community/nixpkgs.lib/770d42db0b8203bdd84ddbd707a49fe0a3638863?narHash=sha256-arht1SYnZ5hJl1COIuqbdRi8ibpnNtc9zUZLmU9xqTs%3D' (2024-07-07)
  → 'github:nix-community/nixpkgs.lib/3b0b1763c0f0931deaa2980b7b146f8ae7a6a952?narHash=sha256-z3Lp%2B%2B7k4l/3K4A%2B7v3cuHBNcm/vntGXgxElLH%2BINa4%3D' (2024-07-14)
• Updated input 'nixpkgs-wayland/nixpkgs':
    'github:nixos/nixpkgs/7e7c39ea35c5cdd002cd4588b03a3fb9ece6fad9?narHash=sha256-EYekUHJE2gxeo2pM/zM9Wlqw1Uw2XTJXOSAO79ksc4Y%3D' (2024-07-12)
  → 'github:nixos/nixpkgs/693bc46d169f5af9c992095736e82c3488bf7dbb?narHash=sha256-oedh2RwpjEa%2BTNxhg5Je9Ch6d3W1NKi7DbRO1ziHemA%3D' (2024-07-14)
• Updated input 'roc':
    'github:roc-lang/roc/0284248320e1a72bb5823bd7005c6521c1c70857?narHash=sha256-P9yElKsIEk6rp2AK3wf2vQQIlPh%2BBQQkvE%2B9BKg5BWs%3D' (2024-07-14)
  → 'github:roc-lang/roc/5cf4a4af1f01c7cab4cd21ad0974967bb2a3b9ca?narHash=sha256-vtpHbfU7BMrHj6Dn/azl7vFwhpIj7%2BOW9MacF9ac3BI%3D' (2024-07-15)
2024-07-16 16:08:32 +00:00
18 changed files with 132 additions and 333 deletions

View file

@ -1,4 +1,4 @@
name: Flake Update / Build name: Build NixOS (Nightly)
on: on:
workflow_dispatch: workflow_dispatch:
@ -101,11 +101,8 @@ jobs:
- run: | - run: |
echo "# System Diff" >> $GITHUB_STEP_SUMMARY echo "# System Diff" >> $GITHUB_STEP_SUMMARY
diff=$(nix store diff-closures ./current ./updated) # TODO: deal with store diff-closures ansi outputs...
echo "$diff" nix store diff-closures ./current ./updated | tee -a $GITHUB_STEP_SUMMARY summary.md
echo "$diff" >> summary.md
echo "$diff" | sed 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g' >> $GITHUB_STEP_SUMMARY
- run: df -h - run: df -h
- uses: actions/upload-artifact@v4 - uses: actions/upload-artifact@v4

View file

@ -52,14 +52,15 @@ Usage:
oizys [command] oizys [command]
Available Commands: Available Commands:
boot nixos rebuild boot
build nix build build nix build
cache build and push to cachix cache build and push to cachix
checks nix build checks checks nix build checks
ci offload build to GHA ci offload build to GHA
dry poor man's nix flake check dry poor man's nix flake check
help Help about any command help Help about any command
os nixos-rebuild wrapper
output show nixosConfiguration attr output show nixosConfiguration attr
switch nixos rebuild switch
update update and run nixos rebuild update update and run nixos rebuild
Flags: Flags:
@ -83,4 +84,3 @@ Oizys was birthed by the goddess Nyx/Nix and embodies suffering and misery. Whic
> I don't use home-manager to manager my shell/user configs. You can find those in my separate `chezmoi`-managed [`dotfiles`](https://git.dayl.in/daylin/dotfiles) repository. > I don't use home-manager to manager my shell/user configs. You can find those in my separate `chezmoi`-managed [`dotfiles`](https://git.dayl.in/daylin/dotfiles) repository.

View file

@ -305,11 +305,11 @@
"xdph": "xdph" "xdph": "xdph"
}, },
"locked": { "locked": {
"lastModified": 1721157817, "lastModified": 1721044084,
"narHash": "sha256-G93msn9eSKDjkWJlualhXvrOsEL6gQN3hjDEll+H8VE=", "narHash": "sha256-vO6wBIaInnyIQqmsKc28AsFSWeCFgnFilNhv2zoN/tU=",
"ref": "refs/heads/main", "ref": "refs/heads/main",
"rev": "da956c8a979471282db6790f5fa5dcec320ec226", "rev": "bd526822deb9ed47c0b51b534817aa8541fff07b",
"revCount": 4928, "revCount": 4927,
"submodules": true, "submodules": true,
"type": "git", "type": "git",
"url": "https://github.com/hyprwm/Hyprland/" "url": "https://github.com/hyprwm/Hyprland/"
@ -426,11 +426,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1721071737, "lastModified": 1720545076,
"narHash": "sha256-qmC9jGfbE4+EIBbbSAkrfR/p49wShjpv4/KztgE/P54=", "narHash": "sha256-Pxacc2uoxI00koXp5+CyNqHOTQlqNlK0rlRHDBHX4+g=",
"owner": "hyprwm", "owner": "hyprwm",
"repo": "hyprutils", "repo": "hyprutils",
"rev": "eb1ceff2b87f6820789249f63faa8e9dcb54d05f", "rev": "6174a2a25f4e216c0f1d0c4278adc23c476b1d09",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -694,11 +694,11 @@
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1720957393, "lastModified": 1720542800,
"narHash": "sha256-oedh2RwpjEa+TNxhg5Je9Ch6d3W1NKi7DbRO1ziHemA=", "narHash": "sha256-ZgnNHuKV6h2+fQ5LuqnUaqZey1Lqqt5dTUAiAnqH0QQ=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "693bc46d169f5af9c992095736e82c3488bf7dbb", "rev": "feb2849fdeb70028c70d73b848214b00d324a497",
"type": "github" "type": "github"
}, },
"original": { "original": {

19
pkgs/oizys/cmd/boot.go Normal file
View file

@ -0,0 +1,19 @@
package cmd
import (
"oizys/internal/oizys"
"github.com/spf13/cobra"
)
var bootCmd = &cobra.Command{
Use: "boot",
Short: "nixos rebuild boot",
Run: func(cmd *cobra.Command, args []string) {
oizys.NixosRebuild("boot", args...)
},
}
func init() {
rootCmd.AddCommand(bootCmd)
}

View file

@ -10,11 +10,12 @@ var buildCmd = &cobra.Command{
Use: "build", Use: "build",
Short: "nix build", Short: "nix build",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
oizys.NixBuild(minimal, args...) oizys.NixBuild(nom, minimal, args...)
}, },
} }
func init() { func init() {
rootCmd.AddCommand(buildCmd) rootCmd.AddCommand(buildCmd)
buildCmd.Flags().BoolVar(&nom, "nom", false, "display result with nom")
buildCmd.Flags().BoolVar(&minimal, "minimal", false, "use system dry-run to make build args") buildCmd.Flags().BoolVar(&minimal, "minimal", false, "use system dry-run to make build args")
} }

View file

@ -10,10 +10,11 @@ var checksCmd = &cobra.Command{
Use: "checks", Use: "checks",
Short: "nix build checks", Short: "nix build checks",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
oizys.Checks(args...) oizys.Checks(nom, args...)
}, },
} }
func init() { func init() {
rootCmd.AddCommand(checksCmd) rootCmd.AddCommand(checksCmd)
checksCmd.Flags().BoolVar(&nom, "nom", false, "display result with nom")
} }

View file

@ -1,38 +0,0 @@
package cmd
import (
"fmt"
"oizys/internal/oizys"
"slices"
"strings"
"github.com/spf13/cobra"
)
var validArgs = []string{
"switch", "boot", "test", "build", "dry-build", "dry-activate", "edit", "repl",
"build-vm", "build-vm-with-bootloader",
"list-generations",
}
var osCmd = &cobra.Command{
Use: "os [subcmd]",
Short: "nixos-rebuild wrapper",
Args: func(cmd *cobra.Command, args []string) error {
if err := cobra.MinimumNArgs(1)(cmd, args); err != nil {
return err
}
// Run the custom validation logic
if slices.Contains(validArgs, args[0]) {
return nil
}
return fmt.Errorf("unexpected arg: %s\nexpected one of:\n %s", args[0], strings.Join(validArgs, ", "))
},
Run: func(cmd *cobra.Command, args []string) {
subcmd := args[0]
oizys.NixosRebuild(subcmd, args[1:]...)
},
}
func init() {
rootCmd.AddCommand(osCmd)
}

View file

@ -33,6 +33,7 @@ var (
host string host string
debug bool debug bool
verbose bool verbose bool
nom bool
systemPath bool systemPath bool
resetCache bool resetCache bool
minimal bool minimal bool

19
pkgs/oizys/cmd/switch.go Normal file
View file

@ -0,0 +1,19 @@
package cmd
import (
"oizys/internal/oizys"
"github.com/spf13/cobra"
)
var switchCmd = &cobra.Command{
Use: "switch",
Short: "nixos rebuild switch",
Run: func(cmd *cobra.Command, args []string) {
oizys.NixosRebuild("switch", args...)
},
}
func init() {
rootCmd.AddCommand(switchCmd)
}

View file

@ -1,13 +1,8 @@
package cmd package cmd
import ( import (
"fmt"
"oizys/internal/github"
"oizys/internal/oizys" "oizys/internal/oizys"
"oizys/internal/ui"
"os"
"github.com/charmbracelet/log"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -15,25 +10,14 @@ var updateCmd = &cobra.Command{
Use: "update", Use: "update",
Short: "update and run nixos rebuild", Short: "update and run nixos rebuild",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
run := github.GetLastUpdateRun() oizys.GitPull()
if preview { oizys.NixosRebuild("switch", args...)
md, err := github.GetUpateSummary(run.GetID())
if err != nil {
log.Fatal(err)
}
fmt.Println(md)
if !ui.Confirm("proceed with system update?") {
os.Exit(0)
}
}
oizys.UpdateRepo()
oizys.NixosRebuild("switch")
}, },
} }
var preview bool var boot bool
func init() { func init() {
rootCmd.AddCommand(updateCmd) rootCmd.AddCommand(updateCmd)
updateCmd.Flags().BoolVar(&preview, "preview", false, "confirm nix store diff") updateCmd.Flags().BoolVarP(&boot, "boot", "b", false, "run nixos-rebuild boot")
} }

View file

@ -3,17 +3,19 @@
installShellFiles, installShellFiles,
buildGoModule, buildGoModule,
makeWrapper, makeWrapper,
gh,
nix-output-monitor,
... ...
}: }:
let let
inherit (lib) cleanSource; inherit (lib) cleanSource makeBinPath;
in in
buildGoModule { buildGoModule {
pname = "oizys"; pname = "oizys";
version = "unstable"; version = "unstable";
src = cleanSource ./.; src = cleanSource ./.;
vendorHash = "sha256-+4OtpcKHfomBAXRrJOvkhQdCSwU0W6+5OJuS4o12r5E="; vendorHash = "sha256-/JVXhXrU2np/ty7AGFy+LPZCo1NaLYl9NAyD9+FJYBI=";
nativeBuildInputs = [ nativeBuildInputs = [
installShellFiles installShellFiles
@ -25,4 +27,13 @@ buildGoModule {
--zsh <(OIZYS_SKIP_CHECK=true $out/bin/oizys completion zsh) --zsh <(OIZYS_SKIP_CHECK=true $out/bin/oizys completion zsh)
''; '';
postFixup = ''
wrapProgram $out/bin/oizys \
--prefix PATH ':' ${
makeBinPath [
gh
nix-output-monitor
]
}
'';
} }

View file

@ -6,7 +6,6 @@ require (
github.com/briandowns/spinner v1.23.0 github.com/briandowns/spinner v1.23.0
github.com/charmbracelet/lipgloss v0.11.0 github.com/charmbracelet/lipgloss v0.11.0
github.com/charmbracelet/log v0.4.0 github.com/charmbracelet/log v0.4.0
github.com/google/go-github/v63 v63.0.0
github.com/ivanpirog/coloredcobra v1.0.1 github.com/ivanpirog/coloredcobra v1.0.1
github.com/spf13/cobra v1.8.0 github.com/spf13/cobra v1.8.0
golang.org/x/term v0.21.0 golang.org/x/term v0.21.0
@ -17,7 +16,6 @@ require (
github.com/charmbracelet/x/ansi v0.1.2 // indirect github.com/charmbracelet/x/ansi v0.1.2 // indirect
github.com/fatih/color v1.17.0 // indirect github.com/fatih/color v1.17.0 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-colorable v0.1.13 // indirect

View file

@ -17,13 +17,6 @@ github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github/v63 v63.0.0 h1:13xwK/wk9alSokujB9lJkuzdmQuVn2QCPeck76wR3nE=
github.com/google/go-github/v63 v63.0.0/go.mod h1:IqbcrgUmIcEaioWrGYei/09o+ge5vhffGOcxrO0AfmA=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
@ -67,7 +60,6 @@ golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA=
golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

View file

@ -1,24 +1,18 @@
package git package oizys
import ( import (
"fmt" "fmt"
"oizys/internal/ui"
"os" "os"
"os/exec" "os/exec"
"github.com/charmbracelet/log" "github.com/charmbracelet/log"
"oizys/internal/ui"
) )
type GitRepo struct { type GitRepo struct {
path string path string
} }
func NewRepo(path string) *GitRepo {
repo := new(GitRepo)
repo.path = path
return repo
}
func (g *GitRepo) git(rest ...string) *exec.Cmd { func (g *GitRepo) git(rest ...string) *exec.Cmd {
args := []string{"-C", g.path} args := []string{"-C", g.path}
args = append(args, rest...) args = append(args, rest...)
@ -27,22 +21,8 @@ func (g *GitRepo) git(rest ...string) *exec.Cmd {
return cmd return cmd
} }
func (g *GitRepo) Fetch() { func GitPull(workDir string) {
err := g.git("fetch").Run() g := GitRepo{workDir}
if err != nil {
log.Fatal(err)
}
}
func (g *GitRepo) Rebase(ref string) {
g.Status()
err := g.git("rebase", ref).Run()
if err != nil {
log.Fatal(err)
}
}
func (g *GitRepo) Status() {
cmdOutput, err := g.git("status", "--porcelain").Output() cmdOutput, err := g.git("status", "--porcelain").Output()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@ -53,11 +33,8 @@ func (g *GitRepo) Status() {
ui.ShowFailedOutput(cmdOutput) ui.ShowFailedOutput(cmdOutput)
os.Exit(1) os.Exit(1)
} }
}
func (g *GitRepo) Pull() { cmdOutput, err = g.git("pull").CombinedOutput()
g.Status()
cmdOutput, err := g.git("pull").CombinedOutput()
if err != nil { if err != nil {
ui.ShowFailedOutput(cmdOutput) ui.ShowFailedOutput(cmdOutput)
log.Fatal(err) log.Fatal(err)

View file

@ -1,154 +0,0 @@
package github
import (
"archive/zip"
"bytes"
"context"
"fmt"
"io"
"net/http"
"net/url"
"oizys/internal/oizys"
"github.com/charmbracelet/log"
"github.com/google/go-github/v63/github"
)
var client *github.Client
func init() {
client = github.NewClient(nil).WithAuthToken(oizys.GithubToken())
}
func ListWorkflows() {
workflowRuns, resp, err := client.Actions.ListWorkflowRunsByFileName(
context.Background(),
"daylinmorgan",
"oizys",
"update.yml",
nil,
)
if err != nil {
log.Fatal("Failed to get a list of workflows", "err", err, "resp", resp)
}
for _, w := range workflowRuns.WorkflowRuns {
fmt.Println(w.GetID())
fmt.Println(w.GetConclusion())
}
}
func ListUpdateRuns() (*github.WorkflowRuns, *github.Response) {
workflowRuns, resp, err := client.Actions.ListWorkflowRunsByFileName(
context.Background(),
"daylinmorgan",
"oizys",
"update.yml",
nil,
)
if err != nil {
log.Fatal("failed to get last update run", "resp", resp, "err", err)
}
return workflowRuns, resp
}
func GetArtifacts(runID int64) (*github.ArtifactList, *github.Response) {
artifactList, resp, err := client.Actions.ListWorkflowRunArtifacts(context.Background(), "daylinmorgan", "oizys", runID, nil)
if err != nil {
log.Fatal("failed to get artifacts for run", "id", runID, "err", err)
}
return artifactList, resp
}
func GetUpdateSummaryArtifact(runID int64) *github.Artifact {
artifactList, _ := GetArtifacts(runID)
for _, artifact := range artifactList.Artifacts {
if artifact.GetName() == "summary" {
return artifact
}
}
log.Fatal("failed to find summary for run", "id", runID)
return nil
}
func GetUpdateSummaryUrl(runID int64) *url.URL {
artifact := GetUpdateSummaryArtifact(runID)
url, resp, err := client.Actions.DownloadArtifact(context.Background(), "daylinmorgan", "oizys", artifact.GetID(), 4)
if err != nil {
log.Fatal("failed to get update summary URL", "artifact", artifact.GetID(), "resp", resp)
}
return url
}
func GetUpdateSummaryFromUrl(url *url.URL) []byte {
log.Debug(url.String())
res, err := http.Get(url.String())
if err != nil {
log.Fatal("failed to get update summary zip", "err", err)
}
body, err := io.ReadAll(res.Body)
res.Body.Close()
if res.StatusCode > 299 {
log.Fatalf("Response failed with status code: %d and\nbody: %s\n", res.StatusCode, body)
}
if err != nil {
log.Fatal(err)
}
return body
}
func GetLastUpdateRun() *github.WorkflowRun {
workflowRuns, _ := ListUpdateRuns()
run := workflowRuns.WorkflowRuns[0]
if run.GetConclusion() == "failure" {
log.Fatal("Most recent run was not successful", "runId", run.GetID(), "conclusion", run.GetConclusion())
}
if run.GetStatus() == "in_progress" {
log.Fatalf("Most recent run is not finished\nview workflow run at: %s", run.GetHTMLURL())
}
return run
}
func GetUpateSummary(runID int64) (string, error) {
url := GetUpdateSummaryUrl(runID)
bytes := GetUpdateSummaryFromUrl(url)
md, err := ReadMarkdownFromZip(bytes, "summary.md")
return md, err
}
func ReadMarkdownFromZip(zipData []byte, fileName string) (string, error) {
// Open the zip reader from the in-memory byte slice
reader, err := zip.NewReader(bytes.NewReader(zipData), int64(len(zipData)))
if err != nil {
return "", err
}
// Search for the target file
var markdownFile *zip.File
for _, f := range reader.File {
if f.Name == fileName {
markdownFile = f
break
}
}
if markdownFile == nil {
return "", fmt.Errorf("file %s not found in zip archive", fileName)
}
// Open the markdown file reader
fileReader, err := markdownFile.Open()
if err != nil {
return "", err
}
defer fileReader.Close()
// Read the markdown content
content, err := io.ReadAll(fileReader)
if err != nil {
return "", err
}
// Return the markdown content as string
return string(content), nil
}

View file

@ -5,8 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io/fs" "io/fs"
"oizys/internal/git"
"oizys/internal/ui"
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
@ -15,6 +13,7 @@ import (
"github.com/charmbracelet/log" "github.com/charmbracelet/log"
e "oizys/internal/exec" e "oizys/internal/exec"
"oizys/internal/ui"
) )
var o *Oizys var o *Oizys
@ -25,13 +24,10 @@ func init() {
// verbose vs debug? // verbose vs debug?
type Oizys struct { type Oizys struct {
repo *git.GitRepo
flake string flake string
host string host string
cache string cache string
githubSummary string githubSummary string
githubToken string
local bool
inCI bool inCI bool
verbose bool verbose bool
systemPath bool systemPath bool
@ -56,13 +52,8 @@ func New() *Oizys {
} }
o.githubSummary = os.Getenv("GITHUB_STEP_SUMMARY") o.githubSummary = os.Getenv("GITHUB_STEP_SUMMARY")
o.inCI = o.githubSummary != "" o.inCI = o.githubSummary != ""
o.githubToken = os.Getenv("GITHUB_TOKEN")
o.repo = git.NewRepo(o.flake)
return o
}
func GithubToken() string { return o
return o.githubToken
} }
func SetFlake(path string) { func SetFlake(path string) {
@ -70,15 +61,12 @@ func SetFlake(path string) {
if path != "" { if path != "" {
o.flake = path o.flake = path
} }
// check local path exists
// check if path is local and exists
if !strings.HasPrefix(o.flake, "github") && !strings.HasPrefix(o.flake, "git+") { if !strings.HasPrefix(o.flake, "github") && !strings.HasPrefix(o.flake, "git+") {
if _, ok := os.LookupEnv("OIZYS_SKIP_CHECK"); !ok { if _, ok := os.LookupEnv("OIZYS_SKIP_CHECK"); !ok {
if _, err := os.Stat(o.flake); errors.Is(err, fs.ErrNotExist) { if _, err := os.Stat(o.flake); errors.Is(err, fs.ErrNotExist) {
log.Warnf("path to flake %s does not exist, using remote as fallback", o.flake) log.Warnf("path to flake %s does not exist, using remote as fallback", o.flake)
o.flake = "github:daylinmorgan/oizys" o.flake = "github:daylinmorgan/oizys"
} else {
o.local = true
} }
} }
} }
@ -139,6 +127,33 @@ func Output() {
} }
} }
func git(rest ...string) *exec.Cmd {
args := []string{"-C", o.flake}
args = append(args, rest...)
cmd := exec.Command("git", args...)
e.LogCmd(cmd)
return cmd
}
func GitPull() {
cmdOutput, err := git("status", "--porcelain").Output()
if err != nil {
log.Fatal(err)
}
if len(cmdOutput) > 0 {
fmt.Println("unstaged commits, cowardly exiting...")
ui.ShowFailedOutput(cmdOutput)
os.Exit(1)
}
cmdOutput, err = git("pull").CombinedOutput()
if err != nil {
ui.ShowFailedOutput(cmdOutput)
log.Fatal(err)
}
}
func parseDryRun(buf string) (*ui.Packages, *ui.Packages) { func parseDryRun(buf string) (*ui.Packages, *ui.Packages) {
lines := strings.Split(strings.TrimSpace(buf), "\n") lines := strings.Split(strings.TrimSpace(buf), "\n")
var parts [2][]string var parts [2][]string
@ -245,8 +260,14 @@ func NixosRebuild(subcmd string, rest ...string) {
e.ExitWithCommand(cmd) e.ExitWithCommand(cmd)
} }
func NixBuild(minimal bool, rest ...string) { func NixBuild(nom bool, minimal bool, rest ...string) {
cmd := exec.Command("nix", "build") var cmdName string
if nom {
cmdName = "nom"
} else {
cmdName = "nix"
}
cmd := exec.Command(cmdName, "build")
if o.resetCache { if o.resetCache {
cmd.Args = append(cmd.Args, "--narinfo-cache-negative-ttl", "0") cmd.Args = append(cmd.Args, "--narinfo-cache-negative-ttl", "0")
} }
@ -297,10 +318,10 @@ func (o *Oizys) checkPath(name string) string {
return fmt.Sprintf("%s#checks.x86_64-linux.%s", o.flake, name) return fmt.Sprintf("%s#checks.x86_64-linux.%s", o.flake, name)
} }
func Checks(rest ...string) { func Checks(nom bool, rest ...string) {
checks := o.getChecks() checks := o.getChecks()
for _, check := range checks { for _, check := range checks {
NixBuild(false, o.checkPath(check)) NixBuild(nom, false, o.checkPath(check))
} }
} }
@ -317,17 +338,8 @@ func CacheBuild(rest ...string) {
} }
func CI(rest ...string) { func CI(rest ...string) {
args := []string{ args := []string{"workflow", "run", "build.yml", "-F", fmt.Sprintf("hosts=%s", o.host)}
"workflow", "run", "build.yml",
"-F", fmt.Sprintf("hosts=%s", o.host),
}
args = append(args, rest...) args = append(args, rest...)
cmd := exec.Command("gh", args...) cmd := exec.Command("gh", args...)
e.ExitWithCommand(cmd) e.ExitWithCommand(cmd)
} }
func UpdateRepo() {
log.Info("rebasing HEAD on origin/flake-lock")
o.repo.Fetch()
o.repo.Rebase("origin/flake-lock")
}

View file

@ -7,9 +7,8 @@ import (
"os/exec" "os/exec"
"strings" "strings"
e "oizys/internal/exec"
"github.com/charmbracelet/log" "github.com/charmbracelet/log"
e "oizys/internal/exec"
) )
var ignoredMap = stringSliceToMap( var ignoredMap = stringSliceToMap(
@ -17,12 +16,16 @@ var ignoredMap = stringSliceToMap(
// nix // nix
"ld-library-path", "builder.pl", "profile", "system-path", "ld-library-path", "builder.pl", "profile", "system-path",
// nixos // nixos
"nixos-help", "nixos-install",
"nixos-install", "nixos-version", "nixos-version",
"nixos-manual-html", "nixos-rebuild", "nixos-manual-html",
"nixos-configuration-reference-manpage", "nixos-configuration-reference-manpage",
"nixos-generate-config", "nixos-enter", "nixos-rebuild",
"nixos-container", "nixos-build-vms", "nixos-help",
"nixos-generate-config",
"nixos-enter",
"nixos-container",
"nixos-build-vms",
"nixos-wsl-version", "nixos-wsl-welcome-message", "nixos-wsl-welcome", "nixos-wsl-version", "nixos-wsl-welcome-message", "nixos-wsl-welcome",
// trivial packages // trivial packages
"restic-gdrive", "gitea", "lock", "code", "restic-gdrive", "gitea", "lock", "code",

View file

@ -1,7 +1,6 @@
package ui package ui
import ( import (
"bufio"
"fmt" "fmt"
"os" "os"
"sort" "sort"
@ -102,26 +101,3 @@ func (p *Packages) summary() {
Render(fmt.Sprint(len(p.names))), Render(fmt.Sprint(len(p.names))),
) )
} }
// Confirm asks the user for confirmation.
// valid inputs are: y/yes,n/no case insensitive.
func Confirm(s string) bool {
reader := bufio.NewReader(os.Stdin)
for {
fmt.Printf("%s [y/n]: ", s)
response, err := reader.ReadString('\n')
if err != nil {
log.Fatal(err)
}
response = strings.ToLower(strings.TrimSpace(response))
switch response {
case "y", "yes":
return true
case "n", "no":
return false
}
}
}