mirror of
https://github.com/daylinmorgan/oizys.git
synced 2024-12-25 20:50:44 -06:00
Compare commits
4 commits
7cc6a8d1fd
...
1077cace3d
Author | SHA1 | Date | |
---|---|---|---|
1077cace3d | |||
720d12d455 | |||
aebda80ff2 | |||
2c88677922 |
6 changed files with 183 additions and 50 deletions
2
.github/actions/clean-disk/action.yml
vendored
2
.github/actions/clean-disk/action.yml
vendored
|
@ -5,7 +5,7 @@ inputs:
|
|||
purge-packages:
|
||||
description: whether to remove apt packages
|
||||
required: false
|
||||
default: 'true'
|
||||
default: 'false'
|
||||
apt-manifest-url:
|
||||
description: url to apt-package manifest (default ubuntu-22.04.4)
|
||||
required: false
|
||||
|
|
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
|
@ -54,7 +54,7 @@ jobs:
|
|||
for host in ${{ inputs.hosts }}; do
|
||||
nix run . \
|
||||
-- \
|
||||
build --system-path \
|
||||
build --minimal \
|
||||
--host "$host" \
|
||||
--flake . \
|
||||
--verbose \
|
||||
|
|
56
flake.lock
56
flake.lock
|
@ -305,11 +305,11 @@
|
|||
"xdph": "xdph"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1719150233,
|
||||
"narHash": "sha256-HOt6FGQdTRIitp5agm3tnZ/4OYM6RG6KOm3UGMntlrY=",
|
||||
"lastModified": 1719164993,
|
||||
"narHash": "sha256-FABhTnL6CBNrvsHVrEXWYoH+zrNfA4yPmgorQupUSZo=",
|
||||
"ref": "refs/heads/main",
|
||||
"rev": "e09addf8dede9a8e7f2dd0e5bb414d3a0d5dc471",
|
||||
"revCount": 4878,
|
||||
"rev": "8a68199a0ceb2894a5d9cc300961c38123ac0312",
|
||||
"revCount": 4879,
|
||||
"submodules": true,
|
||||
"type": "git",
|
||||
"url": "https://github.com/hyprwm/Hyprland/"
|
||||
|
@ -538,11 +538,11 @@
|
|||
"treefmt-nix": "treefmt-nix"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1719073535,
|
||||
"narHash": "sha256-G3LQrKVR5J31hpM8iFMHPchj7HRu0hcLarqLAyRALsI=",
|
||||
"lastModified": 1719227224,
|
||||
"narHash": "sha256-zvi2YfvlOLtui2JFhPs2qybpnJR3/2luMfp8t/eMh54=",
|
||||
"owner": "nix-community",
|
||||
"repo": "nix-eval-jobs",
|
||||
"rev": "630134d3ee9f33caef30b658537463053e9cfde2",
|
||||
"rev": "32071eb9635dbe0e1e8fc750ea1aac6808272018",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -625,11 +625,11 @@
|
|||
"nixpkgs": "nixpkgs_4"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1718710563,
|
||||
"narHash": "sha256-O4rrM0Bkh3IRe8D600iniQ52QTmlnuTSp2KyXV7C2jE=",
|
||||
"lastModified": 1719220171,
|
||||
"narHash": "sha256-xywM6JoGT8AwfoOFJBTv8GRlvNu8LYqqqMS/OQ6uCgE=",
|
||||
"owner": "nix-community",
|
||||
"repo": "NixOS-WSL",
|
||||
"rev": "2fb93bea657ad99a7005ef601c67cb2820560a41",
|
||||
"rev": "269411cfed6aab694e46f719277c972de96177bb",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -677,11 +677,11 @@
|
|||
"nixpkgs": "nixpkgs_7"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1719149508,
|
||||
"narHash": "sha256-Hg8vaExQUf4Lu9CGi1A6Bp3w33Rw4GRna4OQupSPdHs=",
|
||||
"lastModified": 1719246077,
|
||||
"narHash": "sha256-ZE+7chVVT/WQ9pfu8qfnR+Y3++LZQ3wUpj5pe1F4rv4=",
|
||||
"owner": "nix-community",
|
||||
"repo": "nixpkgs-wayland",
|
||||
"rev": "2306a407a29c9358b63723746eeb849215cb6cb6",
|
||||
"rev": "2bdc10495e152111b53643745450116ffae5b0aa",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -724,11 +724,11 @@
|
|||
},
|
||||
"nixpkgs_4": {
|
||||
"locked": {
|
||||
"lastModified": 1718437845,
|
||||
"narHash": "sha256-ZT7Oc1g4I4pHVGGjQFnewFVDRLH5cIZhEzODLz9YXeY=",
|
||||
"lastModified": 1718835956,
|
||||
"narHash": "sha256-wM9v2yIxClRYsGHut5vHICZTK7xdrUGfrLkXvSuv6s4=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "752c634c09ceb50c45e751f8791cb45cb3d46c9e",
|
||||
"rev": "dd457de7e08c6d06789b1f5b88fc9327f4d96309",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -849,11 +849,11 @@
|
|||
"rust-overlay": "rust-overlay"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1719110062,
|
||||
"narHash": "sha256-G+CRYQHhSP49ZG0mrYdDziFFtBxpNVk7BwI/k14kK8U=",
|
||||
"lastModified": 1719241025,
|
||||
"narHash": "sha256-EV39oqCYrE1JXZTCSG20AULpOFqpmuHyGy1u5Nhg6Io=",
|
||||
"owner": "roc-lang",
|
||||
"repo": "roc",
|
||||
"rev": "794c20956de5f22019fe1bf1cad6bf7b738add52",
|
||||
"rev": "d47a073634e79d2db69a67fd08a12b714d46b514",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -908,11 +908,11 @@
|
|||
},
|
||||
"stable": {
|
||||
"locked": {
|
||||
"lastModified": 1718811006,
|
||||
"narHash": "sha256-0Y8IrGhRmBmT7HHXlxxepg2t8j1X90++qRN3lukGaIk=",
|
||||
"lastModified": 1719122173,
|
||||
"narHash": "sha256-aEMsNUtqSPwn6l+LIZ/rX++nCgun3E9M3uSZs6Rwb7w=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "03d771e513ce90147b65fe922d87d3a0356fc125",
|
||||
"rev": "906320ae02f769d13a646eb3605a9821df0d6ea2",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -1147,11 +1147,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1719105765,
|
||||
"narHash": "sha256-tzjig1Sw3DsdoDIgPu8UFiPwK9HwUWuTghHT3xF8XN0=",
|
||||
"lastModified": 1719192015,
|
||||
"narHash": "sha256-6hrQt6y+P0qV/VkJQ4n4bZSaZLJNYXrKecS6B1xb9Wk=",
|
||||
"owner": "Cloudef",
|
||||
"repo": "zig2nix",
|
||||
"rev": "32560c3060464003e122a732d563f4018e860f27",
|
||||
"rev": "048bebf58984486cf45c5e4119f4b149f27d7f1f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -1171,11 +1171,11 @@
|
|||
"zig-overlay": "zig-overlay"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1719052215,
|
||||
"narHash": "sha256-kWL4LzPps7U/s5n+mQwA80IdRK0gMFhwyGN7Lvx/DyE=",
|
||||
"lastModified": 1719164948,
|
||||
"narHash": "sha256-pXgziR7uWaDY18yCEXltcOExgdcHPReH0r/vmphnMoE=",
|
||||
"owner": "zigtools",
|
||||
"repo": "zls",
|
||||
"rev": "2e5a2a5959c0ba645fd6bfbf93dc467c32458465",
|
||||
"rev": "9a37d38c2444e39a988f3970b04baae6b5aee61b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
@ -22,12 +22,15 @@
|
|||
}
|
||||
];
|
||||
|
||||
hardware.opengl = enabled // {
|
||||
driSupport = true;
|
||||
driSupport32Bit = true;
|
||||
extraPackages = with pkgs; [ libGL ];
|
||||
setLdLibraryPath = true;
|
||||
};
|
||||
# deprecated?
|
||||
# hardware.opengl = enabled // {
|
||||
# driSupport = true;
|
||||
# driSupport32Bit = true;
|
||||
# extraPackages = with pkgs; [ libGL ];
|
||||
# setLdLibraryPath = true;
|
||||
# };
|
||||
|
||||
|
||||
# Load nvidia driver for Xorg and Wayland
|
||||
services.xserver.videoDrivers = [ "nvidia" ];
|
||||
|
||||
|
|
|
@ -8,12 +8,15 @@ var buildCmd = &cobra.Command{
|
|||
Use: "build",
|
||||
Short: "nix build",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
oizys.NixBuild(nom, args...)
|
||||
oizys.NixBuild(nom, minimal, args...)
|
||||
},
|
||||
}
|
||||
|
||||
var minimal bool
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(buildCmd)
|
||||
buildCmd.Flags().BoolVar(&nom, "nom", false, "display result with nom")
|
||||
buildCmd.Flags().BoolVar(&systemPath, "system-path", false, "build system path derivation")
|
||||
// buildCmd.Flags().BoolVar(&systemPath, "system-path", false, "build system path derivation")
|
||||
buildCmd.Flags().BoolVar(&minimal, "minimal", false, "use system dry-run to make build args")
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"io/fs"
|
||||
"os"
|
||||
"os/exec"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -70,13 +71,11 @@ func parseSystemPath(derivation map[string]Derivation) (string, error) {
|
|||
func (o *Oizys) getSystemPath() string {
|
||||
cmd := exec.Command("nix", "derivation", "show", o.nixosConfigAttr())
|
||||
logCmd(cmd)
|
||||
// TODO: add spinner?
|
||||
// cmd.Stderr = os.Stderr
|
||||
s := nixSpinner(o.host)
|
||||
out, err := cmd.Output()
|
||||
s.Stop()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatal("failed to evalute nixosConfiguration for system-path.drv", "err", err)
|
||||
}
|
||||
|
||||
var derivation map[string]Derivation
|
||||
|
@ -128,8 +127,8 @@ func (o *Oizys) Set(
|
|||
func terminalSize() (int, int) {
|
||||
fd := os.Stdout.Fd()
|
||||
if !term.IsTerminal(int(fd)) {
|
||||
log.Error("failed to get terminal size")
|
||||
return 80, 0
|
||||
log.Error("failed to get terminal size")
|
||||
return 80, 0
|
||||
// log.Fatal("failed to get terminal size")
|
||||
}
|
||||
w, h, err := term.GetSize(int(fd))
|
||||
|
@ -272,6 +271,30 @@ func parseDryRun(buf string) (*packages, *packages) {
|
|||
parsePackages(parts[1], "packages to fetch")
|
||||
}
|
||||
|
||||
// TODO: Refactor this and above
|
||||
func parseDryRun2(buf string) ([]string, []string) {
|
||||
lines := strings.Split(strings.TrimSpace(buf), "\n")
|
||||
var parts [2][]string
|
||||
i := 0
|
||||
for _, line := range lines {
|
||||
if strings.Contains(line, "fetch") && strings.HasSuffix(line, ":") {
|
||||
i++
|
||||
}
|
||||
if i == 2 {
|
||||
log.Fatal("failed to parse output", "output", buf)
|
||||
}
|
||||
if strings.HasPrefix(line, " ") {
|
||||
parts[i] = append(parts[i], strings.TrimSpace(line))
|
||||
}
|
||||
}
|
||||
|
||||
if len(parts[0])+len(parts[1]) == 0 {
|
||||
log.Info("no changes...")
|
||||
os.Exit(0)
|
||||
}
|
||||
return parts[0], parts[1]
|
||||
}
|
||||
|
||||
func showDryRunResult(nixOutput string, verbose bool) {
|
||||
toBuild, toFetch := parseDryRun(nixOutput)
|
||||
toBuild.show(verbose)
|
||||
|
@ -318,7 +341,7 @@ func runCommand(cmd *exec.Cmd) {
|
|||
}
|
||||
}
|
||||
|
||||
func (o *Oizys) NixBuild(nom bool, rest ...string) {
|
||||
func (o *Oizys) NixBuild(nom bool, minimal bool, rest ...string) {
|
||||
var cmdName string
|
||||
if nom {
|
||||
cmdName = "nom"
|
||||
|
@ -326,19 +349,123 @@ func (o *Oizys) NixBuild(nom bool, rest ...string) {
|
|||
cmdName = "nix"
|
||||
}
|
||||
cmd := exec.Command(cmdName, "build")
|
||||
if o.systemPath {
|
||||
cmd.Args = append(cmd.Args, fmt.Sprintf("%s^*", o.getSystemPath()))
|
||||
}
|
||||
|
||||
cmd.Args = append(cmd.Args, rest...)
|
||||
if o.resetCache {
|
||||
cmd.Args = append(cmd.Args, "--narinfo-cache-positive-ttl", "0")
|
||||
}
|
||||
if o.inCI {
|
||||
o.ciPreBuild(cmd)
|
||||
// if o.inCI {
|
||||
// o.ciPreBuild(cmd)
|
||||
// }
|
||||
if minimal {
|
||||
log.Debug("populating args with derivations not already built")
|
||||
drvs := o.systemPathDrvsToBuild()
|
||||
if len(drvs) == 0 {
|
||||
log.Info("nothing to build. exiting...")
|
||||
os.Exit(0)
|
||||
}
|
||||
cmd.Args = append(cmd.Args, drvs...)
|
||||
}
|
||||
|
||||
runCommand(cmd)
|
||||
}
|
||||
|
||||
var ignoredMap = stringSliceToMap(
|
||||
[]string{
|
||||
"builder.pl",
|
||||
"profile",
|
||||
"system-path",
|
||||
|
||||
"nixos-install",
|
||||
"nixos-version",
|
||||
"nixos-manual-html",
|
||||
"nixos-configuration-reference-manpage",
|
||||
"nixos-rebuild",
|
||||
"nixos-help",
|
||||
"nixos-generate-config",
|
||||
|
||||
"nixos-wsl-version",
|
||||
"nixos-wsl-welcome-message",
|
||||
"nixos-wsl-welcome",
|
||||
|
||||
// trivial packages
|
||||
"restic-gdrive",
|
||||
"gitea",
|
||||
"lock",
|
||||
},
|
||||
)
|
||||
|
||||
func drvIsIgnored(drv string) bool {
|
||||
s := strings.SplitN(strings.Replace(drv, ".drv", "", 1), "-", 2)
|
||||
_, ok := ignoredMap[s[len(s)-1]]
|
||||
return ok
|
||||
}
|
||||
|
||||
func stringSliceToMap(slice []string) map[string]struct{} {
|
||||
hashMap := make(map[string]struct{}, len(slice))
|
||||
for _, s := range slice {
|
||||
hashMap[s] = struct{}{}
|
||||
}
|
||||
return hashMap
|
||||
}
|
||||
|
||||
func drvsToInputs(derivation map[string]Derivation) []string {
|
||||
var drvs []string
|
||||
for _, drv := range derivation {
|
||||
for name := range drv.InputDrvs {
|
||||
drvs = append(drvs, name)
|
||||
}
|
||||
}
|
||||
return drvs
|
||||
}
|
||||
|
||||
// v2
|
||||
func (o *Oizys) systemPathDrvsToBuild() []string {
|
||||
log.Debug("getting system-path build-only deps")
|
||||
systemPathDrv := fmt.Sprintf("%s^*", o.getSystemPath())
|
||||
derivationCmd := exec.Command("nix", "derivation", "show", systemPathDrv)
|
||||
logCmd(derivationCmd)
|
||||
output, err := derivationCmd.Output()
|
||||
if err != nil {
|
||||
log.Fatal("failed to evaluate", "drv", systemPathDrv)
|
||||
}
|
||||
|
||||
// TODO: abstract this?
|
||||
var derivation map[string]Derivation
|
||||
if err := json.Unmarshal(output, &derivation); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
systemPathInputDrvs := stringSliceToMap(drvsToInputs(derivation))
|
||||
|
||||
// get to build packages for full system
|
||||
systemCmd := exec.Command("nix", "build", o.nixosConfigAttr(), "--dry-run")
|
||||
logCmd(systemCmd)
|
||||
result, err := systemCmd.CombinedOutput()
|
||||
if err != nil {
|
||||
log.Fatal("failed to dry-run build full system", "err", err)
|
||||
}
|
||||
toBuild, _ := parseDryRun2(string(result))
|
||||
|
||||
var toActuallyBuild []string
|
||||
for _, drv := range toBuild {
|
||||
_, ok := systemPathInputDrvs[drv]
|
||||
if ok && !drvIsIgnored(drv) {
|
||||
toActuallyBuild = append(toActuallyBuild, drv)
|
||||
}
|
||||
}
|
||||
|
||||
drvs := make([]string, len(toActuallyBuild))
|
||||
for i, pkg := range toActuallyBuild {
|
||||
drvs[i] = fmt.Sprintf("%s^*", strings.TrimSpace(pkg))
|
||||
}
|
||||
return drvs
|
||||
}
|
||||
|
||||
func contains(s []string, search string) bool {
|
||||
i := sort.SearchStrings(s, search)
|
||||
return i < len(s) && s[i] == search
|
||||
}
|
||||
|
||||
func (o *Oizys) writeToGithubStepSummary(txt string) {
|
||||
f, err := os.OpenFile(o.githubSummary, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
|
@ -389,7 +516,7 @@ func (o *Oizys) checkPath(name string) string {
|
|||
func (o *Oizys) Checks(nom bool, rest ...string) {
|
||||
checks := o.getChecks()
|
||||
for _, check := range checks {
|
||||
o.NixBuild(nom, o.checkPath(check))
|
||||
o.NixBuild(nom, false, o.checkPath(check))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue