Compare commits

...

5 commits

Author SHA1 Message Date
github-actions[bot]
95281a7753 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=da956c8a979471282db6790f5fa5dcec320ec226&submodules=1' (2024-07-16)
• Updated input 'hyprland/hyprutils':
    'github:hyprwm/hyprutils/6174a2a25f4e216c0f1d0c4278adc23c476b1d09?narHash=sha256-Pxacc2uoxI00koXp5%2BCyNqHOTQlqNlK0rlRHDBHX4%2Bg%3D' (2024-07-09)
  → 'github:hyprwm/hyprutils/eb1ceff2b87f6820789249f63faa8e9dcb54d05f?narHash=sha256-qmC9jGfbE4%2BEIBbbSAkrfR/p49wShjpv4/KztgE/P54%3D' (2024-07-15)
• Updated input 'hyprland/nixpkgs':
    'github:NixOS/nixpkgs/feb2849fdeb70028c70d73b848214b00d324a497?narHash=sha256-ZgnNHuKV6h2%2BfQ5LuqnUaqZey1Lqqt5dTUAiAnqH0QQ%3D' (2024-07-09)
  → 'github:NixOS/nixpkgs/693bc46d169f5af9c992095736e82c3488bf7dbb?narHash=sha256-oedh2RwpjEa%2BTNxhg5Je9Ch6d3W1NKi7DbRO1ziHemA%3D' (2024-07-14)
• 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 19:29:26 +00:00
e7ec17916b
cli: consolidate and improve cli 2024-07-16 13:10:53 -05:00
6baa412e09
change name to update 2024-07-16 12:41:05 -05:00
9b78f204c8
quotes matter 2024-07-16 12:39:30 -05:00
52daf2551a
strip ansi 2024-07-16 12:21:27 -05:00
18 changed files with 361 additions and 160 deletions

View file

@ -1,4 +1,4 @@
name: Build NixOS (Nightly) name: Flake Update / Build
on: on:
workflow_dispatch: workflow_dispatch:
@ -101,8 +101,11 @@ jobs:
- run: | - run: |
echo "# System Diff" >> $GITHUB_STEP_SUMMARY echo "# System Diff" >> $GITHUB_STEP_SUMMARY
# TODO: deal with store diff-closures ansi outputs... diff=$(nix store diff-closures ./current ./updated)
nix store diff-closures ./current ./updated | tee -a $GITHUB_STEP_SUMMARY summary.md echo "$diff"
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,15 +52,14 @@ 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:
@ -84,3 +83,4 @@ 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": 1720896272, "lastModified": 1721157817,
"narHash": "sha256-zo1lDMsxjEyko/P+KfCLNYZrCAWQOrX90/J31nqzpy4=", "narHash": "sha256-G93msn9eSKDjkWJlualhXvrOsEL6gQN3hjDEll+H8VE=",
"ref": "refs/heads/main", "ref": "refs/heads/main",
"rev": "bc6b0880dda2607a80f000c134f573c970452a0f", "rev": "da956c8a979471282db6790f5fa5dcec320ec226",
"revCount": 4925, "revCount": 4928,
"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": 1720545076, "lastModified": 1721071737,
"narHash": "sha256-Pxacc2uoxI00koXp5+CyNqHOTQlqNlK0rlRHDBHX4+g=", "narHash": "sha256-qmC9jGfbE4+EIBbbSAkrfR/p49wShjpv4/KztgE/P54=",
"owner": "hyprwm", "owner": "hyprwm",
"repo": "hyprutils", "repo": "hyprutils",
"rev": "6174a2a25f4e216c0f1d0c4278adc23c476b1d09", "rev": "eb1ceff2b87f6820789249f63faa8e9dcb54d05f",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -482,11 +482,11 @@
"nixpkgs-lib": "nixpkgs-lib" "nixpkgs-lib": "nixpkgs-lib"
}, },
"locked": { "locked": {
"lastModified": 1720354218, "lastModified": 1720958877,
"narHash": "sha256-cyl6Cxqo4bNmwLXi8/qIc3U1vRJ9VyIBUL/j3is4x58=", "narHash": "sha256-ggCV3etL7W1X9kxhLPZP35+BBh1LgQybene+L/aeQaQ=",
"owner": "nix-community", "owner": "nix-community",
"repo": "lib-aggregate", "repo": "lib-aggregate",
"rev": "5865544e7c012ecaa952f5c6cf5878c1676b52b4", "rev": "6e56a6fd1d993eb02c991d449819f01340888e02",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -498,11 +498,11 @@
"lix": { "lix": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1720825173, "lastModified": 1721094616,
"narHash": "sha256-YZ7043PFS6LalHAyGeO7qRLeZIevwjHRbbMkpixjwhM=", "narHash": "sha256-xeE9I/oGt+Iz7AwnadBlzSJRk8I5y1XKYt2ifV/2eo0=",
"rev": "a8f443d96011c11ad726c2a28a37752bd56c12cc", "rev": "d094dd0396a9ec0b4ce725412cc73c6d9af31021",
"type": "tarball", "type": "tarball",
"url": "https://git.lix.systems/api/v1/repos/lix-project/lix/archive/a8f443d96011c11ad726c2a28a37752bd56c12cc.tar.gz" "url": "https://git.lix.systems/api/v1/repos/lix-project/lix/archive/d094dd0396a9ec0b4ce725412cc73c6d9af31021.tar.gz"
}, },
"original": { "original": {
"type": "tarball", "type": "tarball",
@ -627,11 +627,11 @@
"nixpkgs": "nixpkgs_4" "nixpkgs": "nixpkgs_4"
}, },
"locked": { "locked": {
"lastModified": 1720787015, "lastModified": 1721037029,
"narHash": "sha256-U3IqoGmIzBKEJ0ihRQ10GRRtdoDBI6Oxl6aiGbUA59A=", "narHash": "sha256-wuHiinPG5CzCUBr9I51g+IRhP/69Y9gRVh+QnEtFnyI=",
"owner": "nix-community", "owner": "nix-community",
"repo": "NixOS-WSL", "repo": "NixOS-WSL",
"rev": "371b5076d718f7f637d3959d0203061f06af1263", "rev": "f6db2d325bdf57d39a3ae43376bdf2a020a6aad2",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -658,11 +658,11 @@
}, },
"nixpkgs-lib": { "nixpkgs-lib": {
"locked": { "locked": {
"lastModified": 1720313561, "lastModified": 1720918433,
"narHash": "sha256-arht1SYnZ5hJl1COIuqbdRi8ibpnNtc9zUZLmU9xqTs=", "narHash": "sha256-z3Lp++7k4l/3K4A+7v3cuHBNcm/vntGXgxElLH+INa4=",
"owner": "nix-community", "owner": "nix-community",
"repo": "nixpkgs.lib", "repo": "nixpkgs.lib",
"rev": "770d42db0b8203bdd84ddbd707a49fe0a3638863", "rev": "3b0b1763c0f0931deaa2980b7b146f8ae7a6a952",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -679,11 +679,11 @@
"nixpkgs": "nixpkgs_7" "nixpkgs": "nixpkgs_7"
}, },
"locked": { "locked": {
"lastModified": 1720932034, "lastModified": 1721048083,
"narHash": "sha256-7tz2witA6mIxX3250WyhD8rvXQxlSzQFEDdVLYvzEU8=", "narHash": "sha256-9+v7DYzlQn0djo2j11Ges0uj5WzWajpob/Y3WcsEFks=",
"owner": "nix-community", "owner": "nix-community",
"repo": "nixpkgs-wayland", "repo": "nixpkgs-wayland",
"rev": "09a28c6e377ae40c67d79f0a98c5bff3c59457b8", "rev": "7421424feb2e68a173f6fd218bbf71eb352404e5",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -694,11 +694,11 @@
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1720542800, "lastModified": 1720957393,
"narHash": "sha256-ZgnNHuKV6h2+fQ5LuqnUaqZey1Lqqt5dTUAiAnqH0QQ=", "narHash": "sha256-oedh2RwpjEa+TNxhg5Je9Ch6d3W1NKi7DbRO1ziHemA=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "feb2849fdeb70028c70d73b848214b00d324a497", "rev": "693bc46d169f5af9c992095736e82c3488bf7dbb",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -726,11 +726,11 @@
}, },
"nixpkgs_4": { "nixpkgs_4": {
"locked": { "locked": {
"lastModified": 1720244366, "lastModified": 1720823163,
"narHash": "sha256-WrDV0FPMVd2Sq9hkR5LNHudS3OSMmUrs90JUTN+MXpA=", "narHash": "sha256-FZ5dnrvKkln9ESdoTR8R7GKW9rNpXNZrxGsOXsbsTpE=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "49ee0e94463abada1de470c9c07bfc12b36dcf40", "rev": "f12ee5f64c6a09995e71c9626d88c4efa983b488",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -742,11 +742,11 @@
}, },
"nixpkgs_5": { "nixpkgs_5": {
"locked": { "locked": {
"lastModified": 1720875497, "lastModified": 1721080040,
"narHash": "sha256-1Al1qDC8Q/s4viPq4ln8jfHWZxYl+Nb49dNFISFpqBY=", "narHash": "sha256-USDsS90/88RJibP3gEcH1AaVt+JpnX4XCUD9bAJP5I4=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "b729601a9e6c459fd8884dea513af143111bed54", "rev": "b2c1f10bfbb3f617ea8e8669ac13f3f56ceb2ea2",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -774,11 +774,11 @@
}, },
"nixpkgs_7": { "nixpkgs_7": {
"locked": { "locked": {
"lastModified": 1720768451, "lastModified": 1720957393,
"narHash": "sha256-EYekUHJE2gxeo2pM/zM9Wlqw1Uw2XTJXOSAO79ksc4Y=", "narHash": "sha256-oedh2RwpjEa+TNxhg5Je9Ch6d3W1NKi7DbRO1ziHemA=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "7e7c39ea35c5cdd002cd4588b03a3fb9ece6fad9", "rev": "693bc46d169f5af9c992095736e82c3488bf7dbb",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -851,11 +851,11 @@
"rust-overlay": "rust-overlay" "rust-overlay": "rust-overlay"
}, },
"locked": { "locked": {
"lastModified": 1720924256, "lastModified": 1721081452,
"narHash": "sha256-P9yElKsIEk6rp2AK3wf2vQQIlPh+BQQkvE+9BKg5BWs=", "narHash": "sha256-vtpHbfU7BMrHj6Dn/azl7vFwhpIj7+OW9MacF9ac3BI=",
"owner": "roc-lang", "owner": "roc-lang",
"repo": "roc", "repo": "roc",
"rev": "0284248320e1a72bb5823bd7005c6521c1c70857", "rev": "5cf4a4af1f01c7cab4cd21ad0974967bb2a3b9ca",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -1,19 +0,0 @@
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,12 +10,11 @@ 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(nom, minimal, args...) oizys.NixBuild(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,11 +10,10 @@ 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(nom, args...) oizys.Checks(args...)
}, },
} }
func init() { func init() {
rootCmd.AddCommand(checksCmd) rootCmd.AddCommand(checksCmd)
checksCmd.Flags().BoolVar(&nom, "nom", false, "display result with nom")
} }

38
pkgs/oizys/cmd/os.go Normal file
View file

@ -0,0 +1,38 @@
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,7 +33,6 @@ 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

View file

@ -1,19 +0,0 @@
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,8 +1,13 @@
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"
) )
@ -10,14 +15,25 @@ 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) {
oizys.GitPull() run := github.GetLastUpdateRun()
oizys.NixosRebuild("switch", args...) if preview {
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 boot bool var preview bool
func init() { func init() {
rootCmd.AddCommand(updateCmd) rootCmd.AddCommand(updateCmd)
updateCmd.Flags().BoolVarP(&boot, "boot", "b", false, "run nixos-rebuild boot") updateCmd.Flags().BoolVar(&preview, "preview", false, "confirm nix store diff")
} }

View file

@ -3,19 +3,17 @@
installShellFiles, installShellFiles,
buildGoModule, buildGoModule,
makeWrapper, makeWrapper,
gh,
nix-output-monitor,
... ...
}: }:
let let
inherit (lib) cleanSource makeBinPath; inherit (lib) cleanSource;
in in
buildGoModule { buildGoModule {
pname = "oizys"; pname = "oizys";
version = "unstable"; version = "unstable";
src = cleanSource ./.; src = cleanSource ./.;
vendorHash = "sha256-/JVXhXrU2np/ty7AGFy+LPZCo1NaLYl9NAyD9+FJYBI="; vendorHash = "sha256-+4OtpcKHfomBAXRrJOvkhQdCSwU0W6+5OJuS4o12r5E=";
nativeBuildInputs = [ nativeBuildInputs = [
installShellFiles installShellFiles
@ -27,13 +25,4 @@ 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,6 +6,7 @@ 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
@ -16,6 +17,7 @@ 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,6 +17,13 @@ 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=
@ -60,6 +67,7 @@ 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,18 +1,24 @@
package oizys package git
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...)
@ -21,8 +27,22 @@ func (g *GitRepo) git(rest ...string) *exec.Cmd {
return cmd return cmd
} }
func GitPull(workDir string) { func (g *GitRepo) Fetch() {
g := GitRepo{workDir} err := g.git("fetch").Run()
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)
@ -33,8 +53,11 @@ func GitPull(workDir string) {
ui.ShowFailedOutput(cmdOutput) ui.ShowFailedOutput(cmdOutput)
os.Exit(1) os.Exit(1)
} }
}
cmdOutput, err = g.git("pull").CombinedOutput() func (g *GitRepo) Pull() {
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

@ -0,0 +1,154 @@
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,6 +5,8 @@ import (
"errors" "errors"
"fmt" "fmt"
"io/fs" "io/fs"
"oizys/internal/git"
"oizys/internal/ui"
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
@ -13,7 +15,6 @@ 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
@ -24,10 +25,13 @@ 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
@ -52,21 +56,29 @@ 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 return o
} }
func GithubToken() string {
return o.githubToken
}
func SetFlake(path string) { func SetFlake(path string) {
// Check path exists // Check path exists
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
} }
} }
} }
@ -127,33 +139,6 @@ 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
@ -260,14 +245,8 @@ func NixosRebuild(subcmd string, rest ...string) {
e.ExitWithCommand(cmd) e.ExitWithCommand(cmd)
} }
func NixBuild(nom bool, minimal bool, rest ...string) { func NixBuild(minimal bool, rest ...string) {
var cmdName string cmd := exec.Command("nix", "build")
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")
} }
@ -318,10 +297,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(nom bool, rest ...string) { func Checks(rest ...string) {
checks := o.getChecks() checks := o.getChecks()
for _, check := range checks { for _, check := range checks {
NixBuild(nom, false, o.checkPath(check)) NixBuild(false, o.checkPath(check))
} }
} }
@ -338,8 +317,17 @@ func CacheBuild(rest ...string) {
} }
func CI(rest ...string) { func CI(rest ...string) {
args := []string{"workflow", "run", "build.yml", "-F", fmt.Sprintf("hosts=%s", o.host)} args := []string{
"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,8 +7,9 @@ import (
"os/exec" "os/exec"
"strings" "strings"
"github.com/charmbracelet/log"
e "oizys/internal/exec" e "oizys/internal/exec"
"github.com/charmbracelet/log"
) )
var ignoredMap = stringSliceToMap( var ignoredMap = stringSliceToMap(
@ -16,16 +17,12 @@ var ignoredMap = stringSliceToMap(
// nix // nix
"ld-library-path", "builder.pl", "profile", "system-path", "ld-library-path", "builder.pl", "profile", "system-path",
// nixos // nixos
"nixos-install",
"nixos-version",
"nixos-manual-html",
"nixos-configuration-reference-manpage",
"nixos-rebuild",
"nixos-help", "nixos-help",
"nixos-generate-config", "nixos-install", "nixos-version",
"nixos-enter", "nixos-manual-html", "nixos-rebuild",
"nixos-container", "nixos-configuration-reference-manpage",
"nixos-build-vms", "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,6 +1,7 @@
package ui package ui
import ( import (
"bufio"
"fmt" "fmt"
"os" "os"
"sort" "sort"
@ -101,3 +102,26 @@ 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
}
}
}