From 8ffe5ce23fa1548304a3fa25f2bd0e89837f5a0b Mon Sep 17 00:00:00 2001 From: Minijackson Date: Sun, 18 Apr 2021 16:58:23 +0200 Subject: revamp with nix flakes + desktop config --- common/commandline.nix | 116 +++++++++++++++++++-------------------- common/commandline/dircolors.nix | 7 ++- common/commandline/git.nix | 87 +++++++++++++++-------------- common/commandline/htop.nix | 2 + common/commandline/tmux.nix | 2 + common/commandline/zsh.nix | 21 +++++-- common/default.nix | 22 ++++++-- common/localization.nix | 11 ++++ common/nix.nix | 19 +++++++ common/ssh.nix | 15 +++++ common/theme.nix | 2 + common/tinc.nix | 45 +++++++++++---- common/vim.nix | 2 + 13 files changed, 226 insertions(+), 125 deletions(-) create mode 100644 common/localization.nix create mode 100644 common/nix.nix create mode 100644 common/ssh.nix (limited to 'common') diff --git a/common/commandline.nix b/common/commandline.nix index 36fae26..73dbb51 100644 --- a/common/commandline.nix +++ b/common/commandline.nix @@ -1,3 +1,5 @@ +inputs: + { config, pkgs, lib, ... }: with import ../lib/theme.nix { inherit lib; }; @@ -8,11 +10,11 @@ let in { imports = [ - ./commandline/dircolors.nix - ./commandline/git.nix - ./commandline/htop.nix - ./commandline/tmux.nix - ./commandline/zsh.nix + (import ./commandline/dircolors.nix inputs) + (import ./commandline/git.nix inputs) + (import ./commandline/htop.nix inputs) + (import ./commandline/tmux.nix inputs) + (import ./commandline/zsh.nix inputs) ]; environment.shellAliases = { @@ -24,8 +26,6 @@ in programs.bash = { enableCompletion = true; interactiveShellInit = '' - eval "$(${pkgs.starship}/bin/starship init bash)" - PATH="${pkgs.pazi}/bin:$PATH" eval "$(pazi init bash)" ''; @@ -42,67 +42,67 @@ in }; security.sudo.extraConfig = - let - lectureFile = builtins.toFile "sudoers.lecture" '' -  - ${dominantEscapeCode}"Bee" careful __ - ${dominantEscapeCode}with sudo! // \ - \\_/ // - '''-.._.-'''-.._.. -(||)(') - '''' + let + lectureFile = builtins.toFile "sudoers.lecture" '' +  + ${dominantEscapeCode}"Bee" careful __ + ${dominantEscapeCode}with sudo! // \ + \\_/ // + '''-.._.-'''-.._.. -(||)(') + '''' - ''; - in + ''; + in '' - Defaults lecture = always - Defaults lecture_file = "${lectureFile}" + Defaults lecture = always + Defaults lecture_file = "${lectureFile}" ''; - home-manager.users.minijackson = { ... }: - { - # TODO - xdg.configFile."starship.toml".text = '' - [directory] - fish_style_pwd_dir_length = 2 - style = "bold blue" - - [git_branch] - symbol = "branch " + home-manager.users.minijackson = { ... }: { + programs.bash.enable = true; - [git_status] - ahead = "^" - behind = "v" - deleted = "x" - - [jobs] - symbol = "+ " - - [package] - symbol = "version " - style = "bold green" - disabled = true - - [rust] - symbol = "rust " - style = "bold dimmed yellow" + programs.bat = { + enable = true; + config = { + theme = "TwoDark"; + }; + }; - [nix_shell] - style = "bold blue" + programs.pazi.enable = true; - [character] - symbol = ">" - ''; + programs.starship = { + enable = true; + enableZshIntegration = false; - programs.bat = { - enable = true; - config = { - theme = "TwoDark"; + settings = { + character.symbol = ">"; + directory = { + fish_style_pwd_dir_length = 2; + style = "bold blue"; + }; + git_branch.symbol = "branch "; + git_status = { + ahead = "^"; + behind = "v"; + deleted = "x"; + }; + jobs.symbol = "+ "; + nix_shell.style = "bold blue"; + package = { + disabled = true; + style = "bold green"; + symbol = "version "; + }; + rust = { + style = "bold dimmed yellow"; + symbol = "rust "; }; }; }; + }; - home-manager.users.root = { ... }: - { - programs.bat = config.home-manager.users.minijackson.programs.bat; - }; + home-manager.users.root = { ... }: { + programs.bash.enable = true; + programs.bat = lib.mkDefault config.home-manager.users.minijackson.programs.bat; + }; } diff --git a/common/commandline/dircolors.nix b/common/commandline/dircolors.nix index 7ef3a4d..f7bdae1 100644 --- a/common/commandline/dircolors.nix +++ b/common/commandline/dircolors.nix @@ -1,4 +1,6 @@ -{ config, ... }: +inputs: + +{ config, lib, ... }: { home-manager.users.minijackson = { ... }: @@ -69,6 +71,7 @@ home-manager.users.root = { ... }: { - programs.dircolors = config.home-manager.users.minijackson.programs.dircolors; + programs.dircolors = + lib.mkDefault config.home-manager.users.minijackson.programs.dircolors; }; } diff --git a/common/commandline/git.nix b/common/commandline/git.nix index 597ef64..e231356 100644 --- a/common/commandline/git.nix +++ b/common/commandline/git.nix @@ -1,58 +1,61 @@ -{ config, pkgs, ... }: +inputs: + +{ config, pkgs, lib, ... }: { # TODO: add signing - home-manager.users.minijackson = { ... }: - { + home-manager.users.minijackson = { ... }: { programs.git = { enable = true; package = pkgs.gitAndTools.gitFull; userEmail = "minijackson@riseup.net"; userName = "Minijackson"; - extraConfig = let - deltaCommand = "${pkgs.gitAndTools.delta}/bin/delta"; - in { - core = { - whitespace = "trailing-space,space-before-tab"; - pager = deltaCommand; - interactive.diffFilter = "${deltaCommand} --color-only"; - }; - merge = { tool = "nvimdiff"; }; - "mergetool \"nvimdiff\"" = { cmd = "nvim -d \"$LOCAL\" \"$MERGED\" \"$REMOTE\""; }; - - delta = with config.theme.colors; { - features = "line-numbers decorations"; - whitespace-error-style = "22 reverse"; - decorations = { - minus-style = "normal red"; - minus-non-emph-style = "normal red"; - minus-emph-style = "normal brightred"; - minus-empty-line-marker-style = "normal red"; - - plus-style = "reverse green"; - plus-non-emph-style = "reverse green"; - plus-emph-style = "reverse brightgreen"; - plus-empty-line-marker-style = "reverse green"; - - whitespace-error-style = "reverse green"; - - line-numbers-minus-style = "brightred"; - line-numbers-zero-style = "brightblack"; - line-numbers-plus-style = "brightgreen"; - - file-style = "bright${dominantName}"; - line-numbers-left-style = dominantName; - line-numbers-right-style = dominantName; + extraConfig = + let + deltaCommand = "${pkgs.gitAndTools.delta}/bin/delta"; + in + { + core = { + whitespace = "trailing-space,space-before-tab"; + pager = deltaCommand; + interactive.diffFilter = "${deltaCommand} --color-only"; + }; + merge = { tool = "nvimdiff"; }; + "mergetool \"nvimdiff\"" = { cmd = "nvim -d \"$LOCAL\" \"$MERGED\" \"$REMOTE\""; }; + + delta = with config.theme.colors; { + features = "line-numbers decorations"; + whitespace-error-style = "22 reverse"; + decorations = { + minus-style = "normal red"; + minus-non-emph-style = "normal red"; + minus-emph-style = "normal brightred"; + minus-empty-line-marker-style = "normal red"; + + plus-style = "reverse green"; + plus-non-emph-style = "reverse green"; + plus-emph-style = "reverse brightgreen"; + plus-empty-line-marker-style = "reverse green"; + + whitespace-error-style = "reverse green"; + + line-numbers-minus-style = "brightred"; + line-numbers-zero-style = "brightblack"; + line-numbers-plus-style = "brightgreen"; + + file-style = "bright${dominantName}"; + line-numbers-left-style = dominantName; + line-numbers-right-style = dominantName; + }; }; - }; - }; + }; }; }; - home-manager.users.root = { ... }: - { - programs.git = config.home-manager.users.minijackson.programs.git; + home-manager.users.root = { ... }: { + programs.git = + lib.mkDefault config.home-manager.users.minijackson.programs.git; }; } diff --git a/common/commandline/htop.nix b/common/commandline/htop.nix index f9732a6..95763a0 100644 --- a/common/commandline/htop.nix +++ b/common/commandline/htop.nix @@ -1,3 +1,5 @@ +inputs: + { config, ... }: { diff --git a/common/commandline/tmux.nix b/common/commandline/tmux.nix index aa4de9c..84d2cc8 100644 --- a/common/commandline/tmux.nix +++ b/common/commandline/tmux.nix @@ -1,3 +1,5 @@ +inputs: + { config, pkgs, ... } : let diff --git a/common/commandline/zsh.nix b/common/commandline/zsh.nix index 3376321..28899b1 100644 --- a/common/commandline/zsh.nix +++ b/common/commandline/zsh.nix @@ -1,3 +1,5 @@ +inputs: + { config, lib, pkgs, ... }: with import ../../lib/theme.nix { inherit lib; }; @@ -13,9 +15,6 @@ in source "${pkgs.grml-zsh-config}/etc/zsh/zshrc" is4 && xsource "${pkgs.grml-zsh-config}/etc/zsh/keephack" - PATH="${pkgs.pazi}/bin:$PATH" - eval "$(pazi init zsh)" - source "${pkgs.zsh-history-substring-search}/share/zsh-history-substring-search/zsh-history-substring-search.zsh" function () { @@ -30,8 +29,6 @@ in (mapAttrsToList (variable: value: "${variable}=\"${value}\"") config.programs.less.envVariables)} - - #eval "$(${pkgs.starship}/bin/starship init zsh)" ''; # otherwise it'll override the grml prompt @@ -56,4 +53,18 @@ in }; users.defaultUserShell = pkgs.zsh; + + home-manager.users.minijackson = { ... }: { + # Allows zsh config from home-manager + programs.zsh = { + enable = true; + # Completion is already handled by the GRML conf + enableCompletion = false; + }; + }; + + home-manager.users.root = { ... }: { + programs.zsh = + lib.mkDefault config.home-manager.users.minijackson.programs.zsh; + }; } diff --git a/common/default.nix b/common/default.nix index fc9086b..d4e2e39 100644 --- a/common/default.nix +++ b/common/default.nix @@ -1,11 +1,21 @@ -{ ... }: +inputs: + +{ config, ... }: { imports = [ - - ./commandline.nix - ./theme.nix - ./tinc.nix - ./vim.nix + (import ./commandline.nix inputs) + (import ./localization.nix inputs) + (import ./nix.nix inputs) + (import ./ssh.nix inputs) + (import ./theme.nix inputs) + (import ./tinc.nix inputs) + (import ./vim.nix inputs) + ]; + + nixpkgs.overlays = [ + (final: prev: { + unstable = inputs.nixpkgs-unstable.legacyPackages.${config.nixpkgs.system}; + }) ]; } diff --git a/common/localization.nix b/common/localization.nix new file mode 100644 index 0000000..958b36e --- /dev/null +++ b/common/localization.nix @@ -0,0 +1,11 @@ +inputs: + +{ ... }: + +{ + time.timeZone = "Europe/Paris"; + i18n = { + defaultLocale = "en_US.UTF-8"; + extraLocaleSettings = { LC_TIME = "en_DK.UTF-8"; }; + }; +} diff --git a/common/nix.nix b/common/nix.nix new file mode 100644 index 0000000..f16e1d9 --- /dev/null +++ b/common/nix.nix @@ -0,0 +1,19 @@ +inputs: + +{ pkgs, ... }: + +{ + nix = { + autoOptimiseStore = true; + gc = { + automatic = true; + dates = "03:15"; + options = "--delete-older-than 30d"; + }; + + package = pkgs.nixFlakes; + extraOptions = '' + experimental-features = nix-command flakes + ''; + }; +} diff --git a/common/ssh.nix b/common/ssh.nix new file mode 100644 index 0000000..8bdabc2 --- /dev/null +++ b/common/ssh.nix @@ -0,0 +1,15 @@ +inputs: + +{ config, pkgs, modulesPath, lib, ... }: + +{ + programs.gnupg.agent = { + enable = true; + enableSSHSupport = true; + }; + + services.openssh = { + enable = true; + passwordAuthentication = false; + }; +} diff --git a/common/theme.nix b/common/theme.nix index 675bc33..cadd65d 100644 --- a/common/theme.nix +++ b/common/theme.nix @@ -5,6 +5,8 @@ # - https://github.com/morhetz/gruvbox # - https://github.com/morhetz/gruvbox-contrib +inputs: + { config, lib, ... }: with lib; diff --git a/common/tinc.nix b/common/tinc.nix index d86b19c..e06bd27 100644 --- a/common/tinc.nix +++ b/common/tinc.nix @@ -1,11 +1,15 @@ +inputs: + { config, lib, ... }: with lib; with builtins; -let - networks = attrNames (readDir ./tinc/private); -in { - imports = map (network: (./tinc/private + "/${network}")) networks; +{ + imports = [ + (inputs.nixpkgs-unstable.outPath + "/nixos/modules/services/networking/tinc.nix") + ]; + + disabledModules = [ "services/networking/tinc.nix" ]; options.topology = { mainVpn = { @@ -27,16 +31,33 @@ in { }; config = { - services.tinc.networks = genAttrs networks (network: { - name = config.networking.hostName; - - hosts = let - hosts = attrNames (readDir (./tinc/private + "/${network}/hosts")); - config = hostname: readFile (./tinc/private + "/${network}/hosts/${hostname}"); - in genAttrs hosts config; - }); + # Tinc configuration is in downstream repo networking.firewall.allowedUDPPorts = [ 655 ]; networking.firewall.allowedTCPPorts = [ 655 ]; + + networking.hosts = + with builtins; + with lib; + let + networks = config.services.tinc.networks; + hosts = (flatten + (mapAttrsToList + (name: network: mapAttrsToList + (host: settings: { + host = "${host}.${name}.vpn"; + addresses = map (subnet: subnet.address) settings.subnets; + }) + network.hostSettings) + networks)); + + addresses = + zipAttrs + (flatten + (forEach hosts ({ host, addresses }: + (forEach addresses (address: + { "${address}" = host; }))))); + in + addresses; }; } diff --git a/common/vim.nix b/common/vim.nix index 821d43b..aa74a39 100644 --- a/common/vim.nix +++ b/common/vim.nix @@ -1,3 +1,5 @@ +inputs: + { config, pkgs, lib, ... }: let myNeovim = (pkgs.neovim.override { -- cgit v1.2.3