From 20e7547b0ceaa93f4db13d414ef96a6d108f4c86 Mon Sep 17 00:00:00 2001 From: reo101 Date: Wed, 26 Jul 2023 09:43:14 +0300 Subject: [PATCH] fix(shell)!: accept a `hostname` parameter Pass along device `hostname` into `home-manager` (and more) configs Used for the `rebuild` command since `nix-on-droid` uses the `default` system instead of the `$(hostname)` one (because that requires root to change on-device) --- .../aarch64-linux/cheetah/home.nix | 3 +- modules/home-manager/reo101-shell/default.nix | 33 ++++-- util/default.nix | 26 +++-- util/test.nix | 103 ------------------ 4 files changed, 45 insertions(+), 120 deletions(-) delete mode 100644 util/test.nix diff --git a/machines/nix-on-droid/aarch64-linux/cheetah/home.nix b/machines/nix-on-droid/aarch64-linux/cheetah/home.nix index 9df97eb..b08518e 100644 --- a/machines/nix-on-droid/aarch64-linux/cheetah/home.nix +++ b/machines/nix-on-droid/aarch64-linux/cheetah/home.nix @@ -1,4 +1,4 @@ -{ inputs, outputs, lib, pkgs, config, ... }: +{ inputs, outputs, hostname, lib, pkgs, config, ... }: { # Home Manager needs a bit of information about you and the @@ -102,6 +102,7 @@ reo101.shell = { enable = true; username = "reo101"; + inherit hostname; direnv = true; zoxide = true; }; diff --git a/modules/home-manager/reo101-shell/default.nix b/modules/home-manager/reo101-shell/default.nix index 62f48db..59c016d 100644 --- a/modules/home-manager/reo101-shell/default.nix +++ b/modules/home-manager/reo101-shell/default.nix @@ -16,10 +16,15 @@ in reo101.shell = { enable = mkEnableOption "reo101 zsh setup"; username = mkOption { - description = "Username to be used in prompt"; + description = "Username to be used (for prompt)"; type = types.str; default = "${config.home.username}"; }; + hostname = mkOption { + description = "Hostname to be used (for `rebuild`)"; + type = types.nullOr types.str; + default = null; + }; atuin = mkOption { description = "Integrate with atuin"; type = types.bool; @@ -36,7 +41,7 @@ in default = true; }; flakePath = mkOption { - description = "Flake path (used for `rebuild` command)"; + description = "Flake path (for `rebuild`)"; type = types.str; default = "${config.xdg.configHome}/rix101"; }; @@ -69,7 +74,7 @@ in ]; # Atuin - home.file."${config.xdg.configHome}/config.toml" = mkIf cfg.atuin { + home.file."${config.xdg.configHome}/atuin/config.toml" = mkIf cfg.atuin { text = import ./atuin.nix { keyPath = "${config.xdg.dataHome}/atuin/key"; }; @@ -88,7 +93,9 @@ in programs.starship = { enable = true; - settings = import ./starship.nix { username = cfg.username; }; + settings = import ./starship.nix { + inherit (cfg) username; + }; }; # Zsh @@ -116,17 +123,25 @@ in rebuild () { ${ let - inherit (lib.strings) hasInfix; + inherit (lib.strings) + hasInfix; + inherit (pkgs.hostPlatform) + isx86_64 isAarch64 + isLinux isDarwin; in - if hasInfix "nixos" pkgs.system then + if isx86_64 && isLinux then "sudo --validate && sudo nixos-rebuild" - else if hasInfix "darwin" pkgs.system then + else if isDarwin then "darwin-rebuild" - else if "aarch64-linux" == pkgs.system then + else if isAarch64 then "nix-on-droid" else "home-manager" - } --flake ${cfg.flakePath} ''$''\{1:-switch''\} |& nix run nixpkgs#nix-output-monitor + } --flake ${ + if cfg.hostname != null + then "${cfg.flakePath}#${cfg.hostname}" + else "${cfg.flakePath}" + } ''$''\{1:-switch''\} "''$''\{@:2''\}" |& nix run nixpkgs#nix-output-monitor } '' (optionalString cfg.atuin '' diff --git a/util/default.nix b/util/default.nix index 8f64cd6..4a5da06 100644 --- a/util/default.nix +++ b/util/default.nix @@ -3,8 +3,6 @@ let inherit (inputs) nixpkgs; inherit (nixpkgs) lib; - inherit (lib) mapAttrs; - inherit (lib.attrsets) filterAttrs; in rec { # Boolean helpers @@ -14,7 +12,7 @@ rec { # Directory walking helpers recurseDir = dir: - mapAttrs + lib.mapAttrs (file: type: if type == "directory" then recurseDir "${dir}/${file}" @@ -131,6 +129,7 @@ rec { sharedModules = builtins.attrValues homeManagerModules; extraSpecialArgs = { inherit inputs outputs; + inherit hostname; }; }; } @@ -163,13 +162,17 @@ rec { useGlobalPkgs = false; useUserPackages = true; sharedModules = builtins.attrValues homeManagerModules; - extraSpecialArgs = { inherit inputs outputs; }; + extraSpecialArgs = { + inherit inputs outputs; + inherit hostname; + }; }; } ] ++ (builtins.attrValues nixOnDroidModules); extraSpecialArgs = { inherit inputs outputs; + inherit hostname; # rootPath = ./.; }; @@ -190,12 +193,18 @@ rec { users (user: import (root + "/home/${user}.nix")); sharedModules = builtins.attrValues homeManagerModules; - extraSpecialArgs = { inherit inputs outputs; }; + extraSpecialArgs = { + inherit inputs outputs; + inherit hostname; + }; }; } ] ++ (builtins.attrValues nixDarwinModules); - inputs = { inherit inputs outputs nixpkgs; }; + inputs = { + inherit inputs outputs; + inherit nixpkgs; + }; }; mkHomeManagerHost = root: system: hostname: inputs.home-manager.lib.homeManagerConfiguration { @@ -205,7 +214,10 @@ rec { (root + "/home.nix") ] ++ (builtins.attrValues homeManagerModules); - extraSpecialArgs = { inherit inputs outputs; }; + extraSpecialArgs = { + inherit inputs outputs; + inherit hostname; + }; }; createConfigurations = diff --git a/util/test.nix b/util/test.nix deleted file mode 100644 index 55638b1..0000000 --- a/util/test.nix +++ /dev/null @@ -1,103 +0,0 @@ -# { lib, stdenv, darwin, fetchFromGitHub, rustPlatform, openssl, pkg-config, libxkbcommon }: - -# # rustPlatform.buildRustPackage rec { -# rec { -# pname = "vim-fmi-cli"; -# version = "0.2.0"; -# -# src = fetchFromGitHub { -# owner = "AndrewRadev"; -# repo = pname; -# rev = "v${version}"; -# sha256 = "sha256-RAlvDiNvDVRNtex0aD8WESc4R/lskjda;sldfjmAr7FjWtgzHWa4ZSI="; -# }; -# } - -# { -# a = ''''\'''${a}''\'''; -# -# src = fetchFromGitHub { -# owner = "g15ecb"; -# repo = "promela-mode"; -# rev = "53863e62cfedcd0466e1e19b1ca7b5786cb7a576"; -# # hash = "sha256-pOVIOj5XnZcNVFNyjMV7Iv0X+R+W+mQfT1o5nay2Kww="; -# }; -# } - -# let -# a = "v${b}.${c}.${d}"; -# b = "2"; -# c = "3"; -# d = "6"; -# rev = a; -# in -# rec { -# src = fetchTest { -# inherit a b c rev; -# }; -# rev = "aloda"; -# alo = da; -# } - -let - # kek - type = "256"; -in -let -in -rec { - pname = "vim-fmi-cli"; - version = "0.2.0"; - sha = "RAlvDiNvDVRNtex0aD8WESc4R/mAr7FjWtgzHWa4ZSI="; - sha256 = "sha${type}-${sha}"; - - kek = let - in rec {}; - - src = fetchFromGitHub { - owner = "AndrewRadev"; - repo = pname; - rev = "v${version}"; - inherit sha256; - }; -} - -# let -# bb = "2"; -# b = bb; -# in -# let -# # ... -# in -# fetchTest { -# a = "1"; -# inherit b; -# c = "3"; -# rev = "456"; -# } - -# let -# f = "2"; -# s = "3"; -# t = "4"; -# a = "1"; -# c = "2"; -# v = "${f}.${s}.${t}"; -# kek = rec { -# x = "5"; -# y = x; -# }; -# aloda = fetchTest rec { -# c = b; -# a = "2"; -# b = a; -# rev = "v${c}"; -# }; -# in -# fetchTest { -# inherit a c; -# m = a; -# b = "b"; -# aloda = "${a}b${c}d"; -# rev = "v${v}"; -# }