nix machine / user configurations

feat(dusk@devel.mobi): init user for devbox [skip ci]

ptr.pet f2f4317d 14270326

verified
Changed files
+212 -109
hosts
wolumonde
modules
modules
users
+7 -3
commit.nu
··· 10 10 if $val == null { do $block } else { $val } 11 11 } 12 12 13 + def get-attr-keys [attr: string] { 14 + nix eval $attr --apply builtins.attrNames --json --quiet | from json 15 + } 13 16 14 17 def main [ 15 18 _msg?: string ··· 21 24 let msg: string = unwrap-or-else $_msg { input 'enter commit message: ' } 22 25 23 26 let types = ["feat" "build" "ci" "fix" "refactor" "chore" "style"] 24 - let hosts: list<string> = (nix eval ".#nixosConfigurations" --apply builtins.attrNames --json --quiet | from json) 25 - let scopes = $hosts ++ ["qol" "treewide" "deploy" "commit" "deps"] 27 + let hosts: list<string> = (get-attr-keys ".#nixosConfigurations") 28 + let users: list<string> = (get-attr-keys ".#homeConfigurations") 29 + let scopes = $hosts ++ $users ++ ["qol" "treewide" "deploy" "commit" "deps"] 26 30 27 31 let ty: string = unwrap-or-else $type { $types | input list 'choose type' --fuzzy } 28 32 let scp: string = unwrap-or-else $scope { $scopes | input list 'choose scope' --fuzzy } 29 33 let skipci = if not $skip_ci { "" } else { " [skip ci]" } 30 34 let commit_msg = $"($ty)\(($scp)\): ($msg)($skipci)" 31 35 git commit -m $commit_msg ...$rest 32 - } 36 + }
+36 -14
deploy.nu
··· 44 44 return {result: $result, elapsed: ($end - $start)} 45 45 } 46 46 47 - let ips = { 48 - wolumonde: "23.88.101.188", 47 + let hosts = { 48 + wolumonde: { 49 + type: "nixos", 50 + user: "root", 51 + addr: "23.88.101.188", 52 + }, 53 + "dusk@devel.mobi": { 54 + type: "home", 55 + user: "dusk", 56 + addr: "devel.mobi", 57 + }, 49 58 } 50 59 51 60 def deploy [hostname: string] { 52 61 log info $"start deploy host ($hostname)" 53 62 let hooktitle = $"/($hostname)/deploy" 63 + let hostcfg = $hosts | get $hostname 54 64 55 65 webhook $hooktitle $"=== deploy for ($hostname): started ===\n\n(sys disks | to text)\n\n(sys mem | to text)" 56 66 ··· 63 73 } 64 74 65 75 let result_dir = mktemp -d | path join "result" 66 - let build_cmd = {nh os build --no-nom -H $hostname -o $result_dir -- -L --show-trace} 76 + let build_cmd = { 77 + match $hostcfg.type { 78 + "nixos" => {nh os build --no-nom -H $hostname -o $result_dir -- -L --show-trace} 79 + "home" => {nh home build --no-nom -c $hostname -o $result_dir -- -L --show-trace} 80 + } 81 + } 67 82 if (run_step "build" $build_cmd) { 68 83 return 69 84 } 70 85 let result_link = readlink $result_dir 71 86 72 - # TODO: dont hardcode user 73 - let target = $"root@($ips | get $hostname)" 87 + let target = $"($hostcfg.user)@($hostcfg.addr)" 74 88 let copy_cmd = {nix copy --to $"ssh://($target)" $result_link} 75 89 if (run_step "copy to" $copy_cmd) { 76 90 return 77 91 } 78 92 79 - let activate_cmd = {ssh $target $"sudo '($result_link)/bin/switch-to-configuration' 'switch'"} 93 + let activate_cmd = { 94 + let cmd = match $hostcfg.type { 95 + "nixos" => $"sudo '($result_link)/bin/switch-to-configuration' 'switch'", 96 + "home" => $"($result_link)/activate", 97 + } 98 + ssh $target $cmd 99 + } 80 100 if (run_step "activate" $activate_cmd) { 81 101 return 82 102 } ··· 118 138 } 119 139 } 120 140 121 - def main [hostname: string = "wolumonde"] { 141 + def main [hostname: string = "wolumonde", --only-deploy (-d)] { 122 142 webhook "deploy" "=== started deploying all ===" 123 143 124 - ["blog" "limbusart" "nsid-tracker"] 125 - | each {|input| update-input $input} 144 + if $only_deploy == false { 145 + ["blog" "limbusart" "nsid-tracker"] 146 + | each {|input| update-input $input} 126 147 127 - try { 128 - log info "trying to update dns records" 129 - nix run ".#dns" -- push 130 - } catch { |err| 131 - webhook "dns" $"=== error pushing dns ===\n\n($err.msg | to text)" 1 148 + try { 149 + log info "trying to update dns records" 150 + nix run ".#dns" -- push 151 + } catch { |err| 152 + webhook "dns" $"=== error pushing dns ===\n\n($err.msg | to text)" 1 153 + } 132 154 } 133 155 134 156 deploy $hostname
+1 -1
flake.nix
··· 87 87 { 88 88 lib = tlib; 89 89 nixosConfigurations = import ./hosts { inherit lib tlib inputs; }; 90 - homeConfigurations = import ./users; 90 + homeConfigurations = import ./users { inherit lib tlib inputs; }; 91 91 92 92 packages = lib.mapAttrs (_: pkgs: pkgs._exported) allPkgs; 93 93 legacyPackages = allPkgs;
-1
hosts/wolumonde/modules/nushell.nix
··· 1 - ../../../modules/nushell/default.nix
-82
modules/nushell/default.nix
··· 1 - { lib, pkgs, ... }: 2 - { 3 - environment.shells = [ pkgs.nushell ]; 4 - users.users.root.shell = pkgs.nushell; 5 - 6 - home-manager.users.root = { 7 - programs.nushell = { 8 - enable = true; 9 - package = pkgs.nushell; 10 - shellAliases = { 11 - myip = lib.mkForce "echo"; 12 - }; 13 - extraEnv = '' 14 - source-env ${./prompt.nu} 15 - ''; 16 - extraConfig = '' 17 - let carapace_completer = {|spans: list<string>| 18 - carapace $spans.0 nushell ...$spans 19 - | from json 20 - | if ($in | default [] | where value == $"($spans | last)ERR" | is-empty) { $in } else { null } 21 - } 22 - $env.CARAPACE_BRIDGES = 'zsh,fish,bash,inshellisense' 23 - 24 - let fish_completer = {|spans| 25 - ${lib.getExe pkgs.fish} --command $'complete "--do-complete=($spans | str join " ")"' 26 - | $"value(char tab)description(char newline)" + $in 27 - | from tsv --flexible --no-infer 28 - } 29 - 30 - let zoxide_completer = {|spans| 31 - $spans | skip 1 | zoxide query -l ...$in | lines | where {|x| $x != $env.PWD} 32 - } 33 - 34 - let multiple_completers = {|spans| 35 - ## alias fixer start https://www.nushell.sh/cookbook/external_completers.html#alias-completions 36 - let expanded_alias = scope aliases 37 - | where name == $spans.0 38 - | get -i 0.expansion 39 - 40 - let spans = if $expanded_alias != null { 41 - $spans 42 - | skip 1 43 - | prepend ($expanded_alias | split row ' ' | take 1) 44 - } else { 45 - $spans 46 - } 47 - ## alias fixer end 48 - 49 - match $spans.0 { 50 - __zoxide_z | __zoxide_zi => $zoxide_completer 51 - _ => $carapace_completer 52 - } | do $in $spans 53 - } 54 - 55 - $env.config = { 56 - show_banner: false, 57 - completions: { 58 - case_sensitive: false # case-sensitive completions 59 - quick: true # set to false to prevent auto-selecting completions 60 - partial: true # set to false to prevent partial filling of the prompt 61 - algorithm: "fuzzy" # prefix or fuzzy 62 - external: { 63 - # set to false to prevent nushell looking into $env.PATH to find more suggestions 64 - enable: true 65 - # set to lower can improve completion performance at the cost of omitting some options 66 - max_results: 100 67 - completer: $multiple_completers 68 - } 69 - } 70 - } 71 - $env.PATH = ($env.PATH | 72 - split row (char esep) | 73 - append /usr/bin/env 74 - ) 75 - 76 - source ${./aliases.nu} 77 - ''; 78 - }; 79 - programs.carapace.enable = true; 80 - programs.carapace.enableNushellIntegration = true; 81 - }; 82 - }
+1
modules/nushell/prompt.nu
··· 2 2 higashi: {start: "0xEC5228", end: "0xEF9651"}, 3 3 wolumonde: {start: "0x603F26", end: "0x6C4E31"}, 4 4 chernobog: {start: "0xA94438", end: "0xD24545"}, 5 + "sd-148036": {start: "0x595CFF", end: "0xC6F8FF"}, 5 6 } 6 7 let user_colors = { 7 8 kirara: {start: "0xFF407D", end: "0xEE99C2"},
+23
users/default.nix
··· 1 + { 2 + inputs, 3 + lib, 4 + tlib, 5 + ... 6 + }: 7 + let 8 + mkHome = 9 + name: system: 10 + let 11 + pkgs = tlib.makePkgs system; 12 + in 13 + import "${inputs.home}/modules" { 14 + inherit pkgs; 15 + configuration = import (./. + "/${name}/default.nix"); 16 + extraSpecialArgs = {inherit tlib inputs;}; 17 + }; 18 + 19 + users = { 20 + "dusk@devel.mobi" = "x86_64-linux"; 21 + }; 22 + in 23 + lib.mapAttrs mkHome users
+63
users/dusk@devel.mobi/default.nix
··· 1 + { 2 + pkgs, 3 + lib, 4 + tlib, 5 + inputs, 6 + ... 7 + }: 8 + let 9 + l = lib // builtins; 10 + 11 + signKeyText = builtins.readFile ../../secrets/yusdacra.key.pub; 12 + personal = import ../../personal.nix; 13 + name = personal.name; 14 + email = personal.emails.primary; 15 + in 16 + { 17 + imports = 18 + let 19 + modulesToEnable = l.flatten [ 20 + [ 21 + "zoxide" 22 + "fzf" 23 + "direnv" 24 + "nushell" 25 + ] 26 + # dev stuff 27 + [ 28 + "helix" 29 + "git" 30 + "ssh" 31 + ] 32 + ]; 33 + in 34 + l.flatten [ 35 + ../../modules/persist/null.nix 36 + (tlib.prefixStrings "${inputs.self}/users/modules/" modulesToEnable) 37 + ]; 38 + 39 + home = { 40 + homeDirectory = "/home/dusk"; 41 + username = "dusk"; 42 + stateVersion = "25.11"; 43 + # file.".ssh/authorized_keys".text = '' 44 + # ${signKeyText} 45 + # ''; 46 + }; 47 + 48 + programs = { 49 + git = { 50 + userName = name; 51 + userEmail = email; 52 + extraConfig = { 53 + gpg.format = "ssh"; 54 + commit.gpgsign = true; 55 + user.signingkey = signKeyText; 56 + }; 57 + }; 58 + }; 59 + 60 + services.podman = { 61 + enable = true; 62 + }; 63 + }
+1 -6
users/modules/helix/default.nix
··· 1 1 { 2 - inputs, 3 - pkgs, 4 - ... 5 - }: 6 - { 7 - stylix.targets.helix.enable = false; 2 + # stylix.targets.helix.enable = false; 8 3 programs.helix = { 9 4 enable = true; 10 5 languages.language = [
+1
users/modules/nushell/aliases.nu
··· 1 + ../../../modules/nushell/aliases.nu
+75
users/modules/nushell/default.nix
··· 1 + {pkgs, lib, ...}: { 2 + programs.carapace.enable = true; 3 + programs.carapace.enableNushellIntegration = true; 4 + programs.nushell = { 5 + enable = true; 6 + shellAliases = { 7 + myip = lib.mkForce "echo"; 8 + }; 9 + extraEnv = '' 10 + source-env ${./prompt.nu} 11 + ''; 12 + extraConfig = '' 13 + let carapace_completer = {|spans: list<string>| 14 + carapace $spans.0 nushell ...$spans 15 + | from json 16 + | if ($in | default [] | where value == $"($spans | last)ERR" | is-empty) { $in } else { null } 17 + } 18 + $env.CARAPACE_BRIDGES = 'zsh,fish,bash,inshellisense' 19 + 20 + let fish_completer = {|spans| 21 + ${lib.getExe pkgs.fish} --command $'complete "--do-complete=($spans | str join " ")"' 22 + | $"value(char tab)description(char newline)" + $in 23 + | from tsv --flexible --no-infer 24 + } 25 + 26 + let zoxide_completer = {|spans| 27 + $spans | skip 1 | zoxide query -l ...$in | lines | where {|x| $x != $env.PWD} 28 + } 29 + 30 + let multiple_completers = {|spans| 31 + ## alias fixer start https://www.nushell.sh/cookbook/external_completers.html#alias-completions 32 + let expanded_alias = scope aliases 33 + | where name == $spans.0 34 + | get -i 0.expansion 35 + 36 + let spans = if $expanded_alias != null { 37 + $spans 38 + | skip 1 39 + | prepend ($expanded_alias | split row ' ' | take 1) 40 + } else { 41 + $spans 42 + } 43 + ## alias fixer end 44 + 45 + match $spans.0 { 46 + __zoxide_z | __zoxide_zi => $zoxide_completer 47 + _ => $carapace_completer 48 + } | do $in $spans 49 + } 50 + 51 + $env.config = { 52 + show_banner: false, 53 + completions: { 54 + case_sensitive: false # case-sensitive completions 55 + quick: true # set to false to prevent auto-selecting completions 56 + partial: true # set to false to prevent partial filling of the prompt 57 + algorithm: "fuzzy" # prefix or fuzzy 58 + external: { 59 + # set to false to prevent nushell looking into $env.PATH to find more suggestions 60 + enable: true 61 + # set to lower can improve completion performance at the cost of omitting some options 62 + max_results: 100 63 + completer: $multiple_completers 64 + } 65 + } 66 + } 67 + $env.PATH = ($env.PATH | 68 + split row (char esep) | 69 + append /usr/bin/env 70 + ) 71 + 72 + source ${./aliases.nu} 73 + ''; 74 + }; 75 + }
+1
users/modules/nushell/prompt.nu
··· 1 + ../../../modules/nushell/prompt.nu
-2
users/modules/ssh/default.nix
··· 1 - { nixosConfig, ... }: 2 1 { 3 2 programs.ssh = { 4 3 enable = true; 5 4 compression = true; 6 5 hashKnownHosts = true; 7 6 addKeysToAgent = "yes"; 8 - package = nixosConfig.programs.ssh.package; 9 7 # Only needed for darcs hub 10 8 # extraConfig = '' 11 9 # Host hub.darcs.net
+3
users/root/default.nix
··· 1 1 { ... }: 2 2 { 3 3 users.users.root.initialHashedPassword = "$6$XLWo1sPpgp63Zm$XHBbULH9q1gb/.yalPPU/I7EgTcW80bM.moCjIe/qGyOwE47VcXNVbTHloBZdIWQq0MfIG0IxInAu59.oJyos/"; 4 + home-manager.users.root = { 5 + imports = [../modules/nushell]; 6 + }; 4 7 }