From 93560cdd74a4f3966c2164442d252c8d3a4ecd08 Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Sat, 1 Jul 2023 00:20:03 +0200 Subject: [PATCH] global stylix and proper oh-my-posh --- README.md | 1 - flake.nix | 8 +- images/remote-install/README.md | 23 +++-- images/translate-setup/README.md | 1 - images/windows-rescue/README.md | 14 +-- nixos/components/gui/home-manager/i3.nix | 2 + nixos/components/gui/style.nix | 32 +++---- nixos/components/terminal/default.nix | 2 +- .../default.nix} | 3 +- .../terminal/oh-my-posh/gruvbox.json | 65 ++++++++++++++ nixos/machines/chungus/configuration.nix | 6 ++ nixos/modules/programs/browser.nix | 2 + nixos/pkgs/q/README.md | 3 +- scripts/UHKConfiguration.json | 2 +- scripts/json2nix.py | 87 +++++++++++++++++++ terranix/gitlab/README.md | 6 +- terranix/graylog/MyDashboards.json | 2 +- terranix/space-left/README.md | 27 +++--- terranix/tinc-test/README.md | 1 - terranix/workadventure-jitsi-setup/README.md | 27 +++--- treefmt.toml | 12 ++- 21 files changed, 240 insertions(+), 86 deletions(-) rename nixos/components/terminal/{oh-my-posh.nix => oh-my-posh/default.nix} (81%) create mode 100644 nixos/components/terminal/oh-my-posh/gruvbox.json create mode 100644 scripts/json2nix.py diff --git a/README.md b/README.md index d7e59d1..e891715 100644 --- a/README.md +++ b/README.md @@ -33,4 +33,3 @@ My overlay is in here. ### assets assets, like scripts which I dont want to write in nix-lang. - diff --git a/flake.nix b/flake.nix index e595878..81b0ddb 100644 --- a/flake.nix +++ b/flake.nix @@ -221,15 +221,16 @@ homeManagerModules = { config, ... }: { imports = [ home-manager.nixosModules.home-manager - # stylix.nixosModules.stylix + stylix.nixosModules.stylix ]; + stylix.image = ./nixos/assets/wallpaper.png; + home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; home-manager.users.root = { home.stateVersion = "22.11"; imports = [ home-manager-utils.hmModule - #stylix.homeManagerModules.stylix ]; }; home-manager.users.mainUser = { @@ -237,7 +238,6 @@ imports = [ doom-emacs-nix.hmModule home-manager-utils.hmModule - stylix.homeManagerModules.stylix ]; }; }; @@ -295,7 +295,7 @@ modules = [ #retiolum.nixosModules.retiolum #private_assets.nixosModules.jobrad - #homeManagerModules + homeManagerModules ]; }; diff --git a/images/remote-install/README.md b/images/remote-install/README.md index bfb51d1..db3a772 100644 --- a/images/remote-install/README.md +++ b/images/remote-install/README.md @@ -1,19 +1,18 @@ # remote installation iso -* `./config.nix` : to generate the installation image -* `./remote-service.nix` : tor configuration you have to start on your machine. - +- `./config.nix` : to generate the installation image +- `./remote-service.nix` : tor configuration you have to start on your machine. ## Steps -* import `./remote-service.nix` in your `/etc/nixos/configuration.nix` -* `nixos-rebuild switch` -* run `remote-install-get-hiddenReceiver` and enter the result in `./config.nix` as `hiddenReceiver` -* set the public key in `./config.nix` -* run `nixos-generate -f install-iso -c ./config.nix` -* prepare the usb stick : `sudo if= of=/dev/ bs=4096` -* boot the usb-stick at the new machine -* run `remote-install-start-service` -* after some time you will see a you can use to login to the new machine. +- import `./remote-service.nix` in your `/etc/nixos/configuration.nix` +- `nixos-rebuild switch` +- run `remote-install-get-hiddenReceiver` and enter the result in `./config.nix` as `hiddenReceiver` +- set the public key in `./config.nix` +- run `nixos-generate -f install-iso -c ./config.nix` +- prepare the usb stick : `sudo if= of=/dev/ bs=4096` +- boot the usb-stick at the new machine +- run `remote-install-start-service` +- after some time you will see a you can use to login to the new machine. Now you can do the normal installations procedure. diff --git a/images/translate-setup/README.md b/images/translate-setup/README.md index d90ff40..57943f2 100644 --- a/images/translate-setup/README.md +++ b/images/translate-setup/README.md @@ -32,4 +32,3 @@ nix-shell -I nixpkgs=channel:nixos-unstable -p nixos-generators iptables -F # kill firewall python -m http.server 80 # nix-shell -p python3Full ``` - diff --git a/images/windows-rescue/README.md b/images/windows-rescue/README.md index d4ad9d1..f55aec0 100644 --- a/images/windows-rescue/README.md +++ b/images/windows-rescue/README.md @@ -2,12 +2,12 @@ ## reset password -* use `sfdisk -l` to list partitions -* find the partition which holds `Windows/System32/config` -* mount it `mkdir -p /media/sda2; mount /dev/sda2 /media/sda2` -* `cd /media/sda2/Windows/System32/config` -* list SAM database `chntpw -l SAM` -* edit SAM database `chntpw -i SAM` -* reboot +- use `sfdisk -l` to list partitions +- find the partition which holds `Windows/System32/config` +- mount it `mkdir -p /media/sda2; mount /dev/sda2 /media/sda2` +- `cd /media/sda2/Windows/System32/config` +- list SAM database `chntpw -l SAM` +- edit SAM database `chntpw -i SAM` +- reboot more details [here](https://opensource.com/article/18/3/how-reset-windows-password-linux). diff --git a/nixos/components/gui/home-manager/i3.nix b/nixos/components/gui/home-manager/i3.nix index 3a15fde..ea9a478 100644 --- a/nixos/components/gui/home-manager/i3.nix +++ b/nixos/components/gui/home-manager/i3.nix @@ -29,6 +29,8 @@ in enable = true; bars = { my = { + icons = "awesome5"; + theme = "gruvbox-light"; # https://github.com/greshake/i3status-rust/blob/v0.22.0/doc/blocks.md blocks = [ { diff --git a/nixos/components/gui/style.nix b/nixos/components/gui/style.nix index 9b1c31c..e28b0f9 100644 --- a/nixos/components/gui/style.nix +++ b/nixos/components/gui/style.nix @@ -8,33 +8,21 @@ with lib; config = mkIf (config.components.gui.style.enable) { - home-manager.users.mainUser = { + stylix.base16Scheme = "${pkgs.base16-schemes}/share/themes/gruvbox-light-medium.yaml"; - stylix.image = ../../assets/wallpaper.png; - - stylix.base16Scheme = "${pkgs.base16-schemes}/share/themes/gruvbox-light-medium.yaml"; - - programs.i3status-rust.bars.my = { - icons = "awesome5"; - theme = "gruvbox-light"; + stylix.fonts = { + serif = config.stylix.fonts.monospace; + sansSerif = config.stylix.fonts.monospace; + monospace = { + package = pkgs.jetbrains-mono; + name = "JetBrains Mono"; }; - - stylix.fonts = { - serif = config.home-manager.users.mainUser.stylix.fonts.monospace; - sansSerif = config.home-manager.users.mainUser.stylix.fonts.monospace; - monospace = { - package = pkgs.jetbrains-mono; - name = "JetBrains Mono"; - }; - emoji = { - package = pkgs.noto-fonts-emoji; - name = "Noto Color Emoji"; - }; + emoji = { + package = pkgs.noto-fonts-emoji; + name = "Noto Color Emoji"; }; - }; - fonts.fonts = with pkgs; [ corefonts diff --git a/nixos/components/terminal/default.nix b/nixos/components/terminal/default.nix index ee2fcf1..1832d9f 100644 --- a/nixos/components/terminal/default.nix +++ b/nixos/components/terminal/default.nix @@ -12,7 +12,7 @@ with lib; ./direnv.nix ./git.nix ./hoard.nix - ./oh-my-posh.nix + ./oh-my-posh ./remote-install.nix ./wtf.nix ./zsh.nix diff --git a/nixos/components/terminal/oh-my-posh.nix b/nixos/components/terminal/oh-my-posh/default.nix similarity index 81% rename from nixos/components/terminal/oh-my-posh.nix rename to nixos/components/terminal/oh-my-posh/default.nix index fb4820d..ac4ba9a 100644 --- a/nixos/components/terminal/oh-my-posh.nix +++ b/nixos/components/terminal/oh-my-posh/default.nix @@ -13,7 +13,8 @@ with lib; poshConfig = { programs.oh-my-posh = { enable = true; - useTheme = "gruvbox"; + # useTheme = "gruvbox"; + settings = builtins.fromJSON (builtins.readFile ./gruvbox.json); }; }; in diff --git a/nixos/components/terminal/oh-my-posh/gruvbox.json b/nixos/components/terminal/oh-my-posh/gruvbox.json new file mode 100644 index 0000000..82da3ee --- /dev/null +++ b/nixos/components/terminal/oh-my-posh/gruvbox.json @@ -0,0 +1,65 @@ +{ + "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json", + "blocks": [ + { + "alignment": "left", + "segments": [ + { + "background": "#3A3A3A", + "foreground": "#ffffff", + "style": "powerline", + "template": "{{ if .WSL }}WSL at{{ end }} {{.Icon}} ", + "type": "os" + }, + { + "background": "#fbf1c7", + "background_templates": ["{{ if .Root }}#af3a03{{ end }}"], + "foreground": "#282828", + "foreground_templates": ["{{ if .Root }}#fbf1c7{{ end }}"], + "powerline_symbol": "\ue0b0", + "style": "powerline", + "template": " {{ if .SSHSession }} {{ end }}{{ .HostName }} ", + "type": "session" + }, + { + "background": "#458588", + "foreground": "#282828", + "powerline_symbol": "\ue0b0", + "properties": { + "style": "full" + }, + "style": "powerline", + "template": " {{ .Path }} ", + "type": "path" + }, + { + "background": "#98971A", + "background_templates": [ + "{{ if or (.Working.Changed) (.Staging.Changed) }}#FF9248{{ end }}", + "{{ if and (gt .Ahead 0) (gt .Behind 0) }}#ff4500{{ end }}", + "{{ if gt .Ahead 0 }}#B388FF{{ end }}", + "{{ if gt .Behind 0 }}#B388FF{{ end }}" + ], + "foreground": "#282828", + "leading_diamond": "\ue0b6", + "powerline_symbol": "\ue0b0", + "properties": { + "branch_max_length": 25, + "fetch_stash_count": true, + "fetch_status": true, + "branch_icon": "\uE0A0 ", + "branch_identical_icon": "\u25CF" + }, + "style": "powerline", + "template": " {{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }} \uf044 {{ .Working.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Staging.Changed }} \uf046 {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0 }} \ueb4b {{ .StashCount }}{{ end }} ", + "trailing_diamond": "\ue0b4", + "type": "git" + } + ], + "type": "prompt" + } + ], + "console_title_template": "{{ .Folder }}", + "final_space": true, + "version": 2 +} diff --git a/nixos/machines/chungus/configuration.nix b/nixos/machines/chungus/configuration.nix index 0cd7ed9..04da82e 100644 --- a/nixos/machines/chungus/configuration.nix +++ b/nixos/machines/chungus/configuration.nix @@ -2,6 +2,8 @@ imports = [ + ../../components + ./hardware-configuration.nix ../../system/server ./disko-config.nix @@ -48,6 +50,10 @@ ]; + components.terminal.enable = true; + components.mainUser.enable = true; + components.gui.enable = false; + components.network.enable = true; components.network.wifi.enable = false; diff --git a/nixos/modules/programs/browser.nix b/nixos/modules/programs/browser.nix index 8331dd4..2f9dc13 100644 --- a/nixos/modules/programs/browser.nix +++ b/nixos/modules/programs/browser.nix @@ -170,7 +170,9 @@ in options.programs.custom.browser = { enable = mkEnableOption "enable browsers"; + # todo : it's not a list configList = mkOption { + default = { }; type = with types; attrsOf (submodule ({ name, ... }: { options = { diff --git a/nixos/pkgs/q/README.md b/nixos/pkgs/q/README.md index 1ebfe75..250e01d 100644 --- a/nixos/pkgs/q/README.md +++ b/nixos/pkgs/q/README.md @@ -1,6 +1,5 @@ - # how to build and test ``` -nix-build -E 'with import { overlays = [ (import "${}/pkgs" )];} ; callPackage ./default.nix {}'; +nix-build -E 'with import { overlays = [ (import "${}/pkgs" )];} ; callPackage ./default.nix {}'; ``` diff --git a/scripts/UHKConfiguration.json b/scripts/UHKConfiguration.json index 98b587e..62cdeac 100644 --- a/scripts/UHKConfiguration.json +++ b/scripts/UHKConfiguration.json @@ -3225,4 +3225,4 @@ } ], "macros": [] -} \ No newline at end of file +} diff --git a/scripts/json2nix.py b/scripts/json2nix.py new file mode 100644 index 0000000..be2608a --- /dev/null +++ b/scripts/json2nix.py @@ -0,0 +1,87 @@ +""" +Converts JSON objects into nix (hackishly). +https://gist.github.com/Scoder12/0538252ed4b82d65e59115075369d34d +""" + +import sys +import json + + +INDENT = " " * 2 + + +def strip_comments(t): + # fixme: doesn't work if JSON strings contain // + return "\n".join(l.partition("//")[0] for l in t.split("\n")) + + +def indent(s): + return "\n".join(INDENT + i for i in s.split("\n")) + + +def nix_stringify(s): + # fixme: this doesn't handle string interpolation and possibly has more bugs + return json.dumps(s) + + +def sanitize_key(s): + if s and s.isalnum() and not s[0].isdigit(): + return s + return nix_stringify(s) + + +def flatten_obj_item(k, v): + keys = [k] + val = v + while isinstance(val, dict) and len(val) == 1: + k = next(iter(val.keys())) + keys.append(k) + val = val[k] + return keys, val + + +def fmt_object(obj, flatten): + fields = [] + for k, v in obj.items(): + if flatten: + keys, val = flatten_obj_item(k, v) + formatted_key = ".".join(sanitize_key(i) for i in keys) + else: + formatted_key = sanitize_key(k) + val = v + fields.append(f"{formatted_key} = {fmt_any(val, flatten)};") + + return "{\n" + indent("\n".join(fields)) + "\n}" + + +def fmt_array(o, flatten): + body = indent("\n".join(fmt_any(i, flatten) for i in o)) + return f"[\n{body}\n]" + + +def fmt_any(o, flatten): + if isinstance(o, str) or isinstance(o, bool) or isinstance(o, int): + return json.dumps(o) + if isinstance(o, list): + return fmt_array(o, flatten) + if isinstance(o, dict): + return fmt_object(o, flatten) + raise TypeError(f"Unknown type {type(o)!r}") + + +def main(): + flatten = "--flatten" in sys.argv + args = [a for a in sys.argv[1:] if not a.startswith("--")] + + if len(args) < 1: + print(f"Usage: {sys.argv[0]} [--flatten] ", file=sys.stderr) + sys.exit(1) + + with open(args[0], "r") as f: + data = json.loads(strip_comments(f.read())) + + print(fmt_any(data, flatten=flatten)) + + +if __name__ == "__main__": + main() diff --git a/terranix/gitlab/README.md b/terranix/gitlab/README.md index f4dbbfc..c4f2abe 100644 --- a/terranix/gitlab/README.md +++ b/terranix/gitlab/README.md @@ -2,6 +2,6 @@ This example shows how you could use terranix as flake. -* `nix run` run `nix run ".#apply"` -* `nix run ".#apply"` run `terraform apply` -* `nix run ".#destroy"` run `terraform destroy` +- `nix run` run `nix run ".#apply"` +- `nix run ".#apply"` run `terraform apply` +- `nix run ".#destroy"` run `terraform destroy` diff --git a/terranix/graylog/MyDashboards.json b/terranix/graylog/MyDashboards.json index 5df9da1..e4ea79a 100644 --- a/terranix/graylog/MyDashboards.json +++ b/terranix/graylog/MyDashboards.json @@ -671,4 +671,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/terranix/space-left/README.md b/terranix/space-left/README.md index 953fcbf..9a50870 100644 --- a/terranix/space-left/README.md +++ b/terranix/space-left/README.md @@ -2,9 +2,9 @@ This setup shows: -* how to use a terranix module -* how to use 3rd party provision software after terraform. -* how to run terranix and terraform +- how to use a terranix module +- how to use 3rd party provision software after terraform. +- how to run terranix and terraform Setup containing opinionated modules to deploy [NixOS servers](https://nixos.org/) @@ -15,7 +15,7 @@ using with my [plops](https://github.com/mrVanDalo/plops) provisioning tool for NixOS, -which is an overlay on +which is an overlay on [krops](https://cgit.krebsco.de/krops/about/). After server creation, @@ -34,22 +34,21 @@ here (e.g. NixOps, Ansible, ... ) ## What you need -* a setup [passwordstore](https://www.passwordstore.org/). -* a [hcloud token](https://docs.hetzner.cloud/#overview-getting-started) +- a setup [passwordstore](https://www.passwordstore.org/). +- a [hcloud token](https://docs.hetzner.cloud/#overview-getting-started) stored under `development/hetzner.com/api-token` ## Steps -* `terraform-prepare`: to create ssh keys. -* `terraform-build`: to run terranix and terraform do create server. -* `terraform-destroy`: to delete server (don't forget that step, or else it gets costly) -* `terraform-cleanup`: to delete ssh keys and terraform data. - +- `terraform-prepare`: to create ssh keys. +- `terraform-build`: to run terranix and terraform do create server. +- `terraform-destroy`: to delete server (don't forget that step, or else it gets costly) +- `terraform-cleanup`: to delete ssh keys and terraform data. ## DNS define domains with your nameserver and update `jitsi.nix` and `workadventure.nix`. -* `meet.${domain}` to given ip4 address -* `party.${domain}` to given ip4 address -* `*.party.${domain}` to given ip4 address +- `meet.${domain}` to given ip4 address +- `party.${domain}` to given ip4 address +- `*.party.${domain}` to given ip4 address diff --git a/terranix/tinc-test/README.md b/terranix/tinc-test/README.md index 4e800d9..074f2fd 100644 --- a/terranix/tinc-test/README.md +++ b/terranix/tinc-test/README.md @@ -1,4 +1,3 @@ - A setup to test tinc on a hetzner box # steps diff --git a/terranix/workadventure-jitsi-setup/README.md b/terranix/workadventure-jitsi-setup/README.md index 953fcbf..9a50870 100644 --- a/terranix/workadventure-jitsi-setup/README.md +++ b/terranix/workadventure-jitsi-setup/README.md @@ -2,9 +2,9 @@ This setup shows: -* how to use a terranix module -* how to use 3rd party provision software after terraform. -* how to run terranix and terraform +- how to use a terranix module +- how to use 3rd party provision software after terraform. +- how to run terranix and terraform Setup containing opinionated modules to deploy [NixOS servers](https://nixos.org/) @@ -15,7 +15,7 @@ using with my [plops](https://github.com/mrVanDalo/plops) provisioning tool for NixOS, -which is an overlay on +which is an overlay on [krops](https://cgit.krebsco.de/krops/about/). After server creation, @@ -34,22 +34,21 @@ here (e.g. NixOps, Ansible, ... ) ## What you need -* a setup [passwordstore](https://www.passwordstore.org/). -* a [hcloud token](https://docs.hetzner.cloud/#overview-getting-started) +- a setup [passwordstore](https://www.passwordstore.org/). +- a [hcloud token](https://docs.hetzner.cloud/#overview-getting-started) stored under `development/hetzner.com/api-token` ## Steps -* `terraform-prepare`: to create ssh keys. -* `terraform-build`: to run terranix and terraform do create server. -* `terraform-destroy`: to delete server (don't forget that step, or else it gets costly) -* `terraform-cleanup`: to delete ssh keys and terraform data. - +- `terraform-prepare`: to create ssh keys. +- `terraform-build`: to run terranix and terraform do create server. +- `terraform-destroy`: to delete server (don't forget that step, or else it gets costly) +- `terraform-cleanup`: to delete ssh keys and terraform data. ## DNS define domains with your nameserver and update `jitsi.nix` and `workadventure.nix`. -* `meet.${domain}` to given ip4 address -* `party.${domain}` to given ip4 address -* `*.party.${domain}` to given ip4 address +- `meet.${domain}` to given ip4 address +- `party.${domain}` to given ip4 address +- `*.party.${domain}` to given ip4 address diff --git a/treefmt.toml b/treefmt.toml index 409607d..f6bb1e0 100644 --- a/treefmt.toml +++ b/treefmt.toml @@ -22,4 +22,14 @@ excludes = ["./scripts/hetzner-dedicated-wipe-and-install-nixos.sh"] [formatter.python] command = "black" -includes = ["*.py"] \ No newline at end of file +includes = ["*.py"] + +[formatter.media] +command = "prettier" +options = ["--write"] +includes = [ + "*.json", + "*.md", + "*.yaml", + "*.yml", +] \ No newline at end of file