commit b5febd439528389e86c24311646ec93f99f97e1a Author: Nickolaj Jepsen Date: Sun Apr 7 17:53:24 2024 +0000 initial commit diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..2d17adf --- /dev/null +++ b/flake.lock @@ -0,0 +1,411 @@ +{ + "nodes": { + "beautysh": { + "inputs": { + "nixpkgs": [ + "nixvim", + "nixpkgs" + ], + "poetry2nix": "poetry2nix", + "utils": "utils" + }, + "locked": { + "lastModified": 1680308980, + "narHash": "sha256-aUEHV0jk2qIFP3jlsWYWhBbm+w/N9gzH3e4I5DcdB5s=", + "owner": "lovesegfault", + "repo": "beautysh", + "rev": "9845efc3ea3e86cc0d41465d720a47f521b2799c", + "type": "github" + }, + "original": { + "owner": "lovesegfault", + "repo": "beautysh", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "inputs": { + "systems": "systems_3" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_4": { + "inputs": { + "systems": "systems_4" + }, + "locked": { + "lastModified": 1681202837, + "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "nixvim", + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1712386041, + "narHash": "sha256-dA82pOMQNnCJMAsPG7AXG35VmCSMZsJHTFlTHizpKWQ=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "d6bb9f934f2870e5cbc5b94c79e9db22246141ff", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "release-23.11", + "repo": "home-manager", + "type": "github" + } + }, + "nixos-wsl": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1710519878, + "narHash": "sha256-0dbc10OBFUVYyXC+C+N6vRUd8xyBSRxkcZ4Egipbx0M=", + "owner": "nix-community", + "repo": "nixos-wsl", + "rev": "aef95bdb6800a3a2af7aa7083d6df03067da6592", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixos-wsl", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1712437997, + "narHash": "sha256-g0whLLwRvgO2FsyhY8fNk+TWenS3jg5UdlWL4uqgFeo=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "e38d7cb66ea4f7a0eb6681920615dfcc30fc2920", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1712437997, + "narHash": "sha256-g0whLLwRvgO2FsyhY8fNk+TWenS3jg5UdlWL4uqgFeo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e38d7cb66ea4f7a0eb6681920615dfcc30fc2920", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixvim": { + "inputs": { + "beautysh": "beautysh", + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "nixpkgs" + ], + "pre-commit-hooks": "pre-commit-hooks" + }, + "locked": { + "lastModified": 1704297403, + "narHash": "sha256-g7+4SiXDGzIlWIfANyH1J5CeEaY+Alah6KOm6IO4nIk=", + "owner": "nix-community", + "repo": "nixvim", + "rev": "b3ea5256e07ee9105060cffa075028402946bd63", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "nixos-23.11", + "repo": "nixvim", + "type": "github" + } + }, + "poetry2nix": { + "inputs": { + "flake-utils": [ + "nixvim", + "beautysh", + "utils" + ], + "nixpkgs": [ + "nixvim", + "beautysh", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1658665240, + "narHash": "sha256-/wkx7D7enyBPRjIkK0w7QxLQhzEkb3UxNQnjyc3FTUI=", + "owner": "nix-community", + "repo": "poetry2nix", + "rev": "8b8edc85d24661d5a6d0d71d6a7011f3e699780f", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "poetry2nix", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat_2", + "flake-utils": "flake-utils_3", + "gitignore": "gitignore", + "nixpkgs": [ + "nixvim", + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1711760932, + "narHash": "sha256-DqUTQ2iAAqSDwMhKBqvi24v0Oc7pD3LCK/0FCG//TdA=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "c11e43aed6f17336c25cd120eac886b96c455731", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "home-manager": "home-manager", + "nixos-wsl": "nixos-wsl", + "nixpkgs": "nixpkgs", + "nixvim": "nixvim", + "vscode-server": "vscode-server" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_3": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_4": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "locked": { + "lastModified": 1678901627, + "narHash": "sha256-U02riOqrKKzwjsxc/400XnElV+UtPUQWpANPlyazjH0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "93a2b84fc4b70d9e089d029deacc3583435c2ed6", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "vscode-server": { + "inputs": { + "flake-utils": "flake-utils_4", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709622318, + "narHash": "sha256-bTscF0366xtoIXgH7Zq+Mn0mpX3w4h/2xKpHiYMyLNc=", + "owner": "nix-community", + "repo": "nixos-vscode-server", + "rev": "d0ed9b8cf1f0a71f110df9119489ab047e0726bd", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixos-vscode-server", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..1f7a467 --- /dev/null +++ b/flake.nix @@ -0,0 +1,56 @@ +{ + description = "Your new nix config"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11"; + + home-manager = { + url = "github:nix-community/home-manager/release-23.11"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + nixos-wsl = { + url = "github:nix-community/nixos-wsl"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + vscode-server = { + url = "github:nix-community/nixos-vscode-server"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + nixvim = { + url = "github:nix-community/nixvim/nixos-23.11"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { + self, + nixpkgs, + home-manager, + nixos-wsl, + vscode-server, + nixvim, + ... + } @ inputs: let + inherit (self) outputs; + in { + # Available through 'nixos-rebuild --flake .#wsl' + nixosConfigurations = { + wsl = nixpkgs.lib.nixosSystem { + specialArgs = { + inherit inputs outputs; + username = "nickolaj"; + hostname = "wsl"; + }; + modules = [ + nixos-wsl.nixosModules.wsl + vscode-server.nixosModules.default + ./nixos/configuration.nix + ./nixos/machines/wsl.nix + ]; + }; + }; + }; +} diff --git a/home-manager/default.nix b/home-manager/default.nix new file mode 100644 index 0000000..5401882 --- /dev/null +++ b/home-manager/default.nix @@ -0,0 +1,50 @@ +{ + pkgs, + inputs, + username, + ... +}: { + imports = [ + ./modules/fish/default.nix + ./modules/nixvim/default.nix + ]; + + nixpkgs = { + config = { + allowUnfree = true; + allowUnfreePredicate = _: true; + }; + }; + + home = { + username = username; + homeDirectory = "/home/${username}"; + }; + + home.packages = with pkgs; [ + fzf + ripgrep + fd + git + jq + httpie + git + gh + ]; + + programs.git = { + enable = true; + userName = "Nickolaj Jepsen"; + userEmail = "nickolaj@fireproof.website"; + extraConfig = { + push = { + autoSetupRemote = true; + }; + pull = { + rebase = true; + }; + }; + }; + + home.stateVersion = "23.11"; +} diff --git a/home-manager/modules/fish/conf.d/10_theme.fish b/home-manager/modules/fish/conf.d/10_theme.fish new file mode 100644 index 0000000..0596940 --- /dev/null +++ b/home-manager/modules/fish/conf.d/10_theme.fish @@ -0,0 +1,38 @@ +set -gx theme_date_timezone Europe/Copenhagen +set -gx theme_date_format "+%a %H:%M" + +function bobthefish_colors -S -d 'Define a custom bobthefish color scheme' + + # Optionally include a base color scheme + # __bobthefish_colors default + + # Then override everything you want! + # Note that these must be defined with `set -x` + set -x color_initial_segment_exit white red --bold + set -x color_initial_segment_su white green --bold + set -x color_initial_segment_jobs white blue --bold + + set -x color_path 161616 888 + set -x color_path_basename 161616 white + set -x color_path_nowrite magenta black + set -x color_path_nowrite_basename magenta black --bold + + set -x color_repo green black + set -x color_repo_work_tree black black --bold + set -x color_repo_dirty brred black + set -x color_repo_staged yellow black + + set -x color_vi_mode_default brblue black --bold + set -x color_vi_mode_insert brgreen black --bold + set -x color_vi_mode_visual bryellow black --bold + + set -x color_vagrant brcyan black + set -x color_k8s magenta white --bold + set -x color_username black white --bold + set -x color_hostname black white + set -x color_rvm brmagenta black --bold + set -x color_virtualfish brblue black --bold + set -x color_virtualgo brblue black --bold + set -x color_desk brblue black --bold + set -g theme_display_nix yes +end \ No newline at end of file diff --git a/home-manager/modules/fish/conf.d/20_alias.fish b/home-manager/modules/fish/conf.d/20_alias.fish new file mode 100644 index 0000000..c7fc16f --- /dev/null +++ b/home-manager/modules/fish/conf.d/20_alias.fish @@ -0,0 +1,37 @@ +if type -q nvim + alias vim nvim +end + +if type -q docker + abbr d "docker" +end + +if type -q docker-compose + abbr dc "docker-compose" +end + +if type -q snap + set PYCHARM_SNAP (snap list | grep 'pycharm' | awk '{ print $1 }') + set HELM_SNAP (snap list | grep 'helm' | awk '{ print $1 }') + if test -n "$HELM_SNAP" + alias helm "snap run $HELM_SNAP" + end + if test -n "$PYCHARM_SNAP" + alias pycharm "snap run $PYCHARM_SNAP" + end +end + +if type -q to + abbr z "to" +end + +if type -q broot + abbr br "broot" +end + +if type -q terraform + abbr tf "terraform" + abbr tfp "terraform plan" + abbr tfa "terraform apply" + abbr tfi "terraform init" +end \ No newline at end of file diff --git a/home-manager/modules/fish/conf.d/30_kubectl.fish b/home-manager/modules/fish/conf.d/30_kubectl.fish new file mode 100644 index 0000000..1a8bd78 --- /dev/null +++ b/home-manager/modules/fish/conf.d/30_kubectl.fish @@ -0,0 +1,47 @@ +set __kube_verbs get describe delete edit +set __kube_verbs_short g d rm e +set __kube_resource pods deployments services ingresses configmaps daemonsets statefulsets namespace namespace +set __kube_resource_short p d s i c ds ss n ns + +function __echo_kubeexec; + set _flag_namespace (kubectl config view --minify --output 'jsonpath={..namespace}') + if test -z "$_flag_namespace" + set _flag_namespace default + end + + set _flag_pod shop + set POD (kubectl get pods --namespace $_flag_namespace 2>/dev/null | grep "^$_flag_pod" | grep Running | head -n1 | awk '{ print $1 }') + if test -z "$POD" + echo "kubectl exec --namespace $_flag_namespace -it" + return + end + echo "kubectl exec --namespace $_flag_namespace -it $POD --" +end + +if type -q kubectl + for verb_index in (seq (count $__kube_verbs)) + abbr "k$__kube_verbs_short[$verb_index]" "kubectl $__kube_verbs[$verb_index]" + for res_index in (seq (count $__kube_resource)) + abbr "k$__kube_verbs_short[$verb_index]$__kube_resource_short[$res_index]" "kubectl $__kube_verbs[$verb_index] $__kube_resource[$res_index]" + end + end + + abbr k kubectl + abbr kl kubectl logs -f + abbr kgl kubectl logs -f + abbr kaf kubectl apply -f + abbr kr kubectl rollout + abbr krs kubectl rollout status + abbr krr kubectl rollout restart + abbr kt kubectl top + abbr ktp kubectl top pods + abbr ktn kubectl top nodes + abbr kpf kubectl port-forward + abbr kfp kubectl port-forward + + alias kns "kubectl config view --minify --output 'jsonpath={..namespace}'" + abbr ksns "kubectl config set-context --current --namespace" + + abbr kexec --function __echo_kubeexec + abbr kmanage "kexec python3 /src/lib/manage.py" +end \ No newline at end of file diff --git a/home-manager/modules/fish/default.nix b/home-manager/modules/fish/default.nix new file mode 100644 index 0000000..5119b9a --- /dev/null +++ b/home-manager/modules/fish/default.nix @@ -0,0 +1,42 @@ +{ + pkgs, + config, + ... +}: { + home.file."${config.home.homeDirectory}/.config/fish/conf.d/" = { source = ./conf.d; recursive = true;}; + + programs.fish = { + enable = true; + plugins = with pkgs.fishPlugins; [ + { + name = "fzf"; + src = fzf.src; + } + { + name = "bobthefish"; + src = bobthefish.src; + } + { + name = "to"; + src = pkgs.fetchFromGitHub { + owner = "joehillen"; + repo = "to-fish"; + rev = "52b151cfe67c00cb64d80ccc6dae398f20364938"; + hash = "sha256-DfDsU/qY2XdYlkLISIOv02ggHfKEpb+YompNWWjs5/A="; + }; + } + ]; + }; + + # Init fish from bash + programs.bash = { + enable = true; + initExtra = '' + if [[ $(${pkgs.procps}/bin/ps --no-header --pid=$PPID --format=comm) != "fish" && -z ''${BASH_EXECUTION_STRING} ]] + then + shopt -q login_shell && LOGIN_OPTION='--login' || LOGIN_OPTION="" + exec ${pkgs.fish}/bin/fish $LOGIN_OPTION + fi + ''; + }; +} \ No newline at end of file diff --git a/home-manager/modules/nixvim/default.nix b/home-manager/modules/nixvim/default.nix new file mode 100644 index 0000000..f6015e2 --- /dev/null +++ b/home-manager/modules/nixvim/default.nix @@ -0,0 +1,95 @@ +{ inputs, ... }: +{ + imports = [ + inputs.nixvim.homeManagerModules.nixvim + ]; + + programs.neovim = { + defaultEditor = true; + }; + + programs.nixvim = { + enable = true; + + options = { + number = true; + relativenumber = false; + tabstop = 4; + shiftwidth = 4; + expandtab = false; + }; + + globals.mapleader = " "; + + keymaps = [ + { + key = "jk"; + action = ""; + mode = "i"; + } + { + key = "o"; + action = ":NvimTreeToggle"; + options = { + silent = true; + }; + } + ]; + + colorschemes.base16 = { + enable = true; + colorscheme = "twilight"; + }; + + plugins = { + barbecue.enable = true; + nvim-colorizer.enable = true; + gitsigns.enable = true; + indent-blankline.enable = true; + surround.enable = true; + bufferline.enable = true; + nvim-autopairs.enable = true; + lsp-format.enable = true; + lightline.enable = true; + intellitab.enable = true; + which-key.enable = true; + + telescope = { + enable = true; + keymaps = { + "ff" = "find_files"; + }; + }; + + nvim-tree = { + enable = true; + filters.custom = [ + ".git" + ]; + }; + + treesitter = { + enable = true; + nixGrammars = true; + }; + + lsp = { + enable = true; + servers.nil_ls.enable = true; + }; + + lspkind = { + enable = true; + }; + + nvim-cmp = { + enable = true; + sources = [{ name = "nvim_lsp"; }]; + mappingPresets = [ "insert" ]; + mapping = { + "" = "cmp.mapping.confirm({ select = true })"; + }; + }; + }; + }; +} \ No newline at end of file diff --git a/home-manager/wsl.nix b/home-manager/wsl.nix new file mode 100644 index 0000000..34fb5aa --- /dev/null +++ b/home-manager/wsl.nix @@ -0,0 +1,8 @@ +{ + pkgs, + ... +}: { + home.packages = with pkgs; [ + nodejs_20 + ]; +} diff --git a/nixos/configuration.nix b/nixos/configuration.nix new file mode 100644 index 0000000..6abeb19 --- /dev/null +++ b/nixos/configuration.nix @@ -0,0 +1,51 @@ +{ + inputs, + outputs, + username, + hostname, + pkgs, + lib, + ... +}: { + imports = [ + inputs.home-manager.nixosModules.home-manager + ]; + + nixpkgs = { + config = { + allowUnfree = true; + }; + hostPlatform = lib.mkDefault "x86_64-linux"; + }; + + nix.settings = { + experimental-features = "nix-command flakes"; + auto-optimise-store = true; + }; + + home-manager = { + extraSpecialArgs = { inherit inputs outputs username hostname; }; + users.${username}.imports = [ + ../home-manager/default.nix + ]; + }; + + networking.hostName = hostname; + + environment.systemPackages = with pkgs; [ + wget + fish + ]; + + programs.fish.enable = true; + + users.users = { + ${username} = { + initialPassword = "fireproof"; + isNormalUser = true; + extraGroups = ["wheel"]; + }; + }; + + system.stateVersion = "23.11"; +} diff --git a/nixos/machines/wsl.nix b/nixos/machines/wsl.nix new file mode 100644 index 0000000..c6525af --- /dev/null +++ b/nixos/machines/wsl.nix @@ -0,0 +1,26 @@ +{ + username, + pkgs, + ... +}: { + programs.nix-ld = { + enable = true; + }; + + wsl = { + enable = true; + defaultUser = username; + }; + + home-manager.users.${username}.imports = [ + ../../home-manager/wsl.nix + ]; + + # Hacks to enable vscode + services.vscode-server.enable = true; + wsl.extraBin = with pkgs; [ + { src = "${coreutils}/bin/uname"; } + { src = "${coreutils}/bin/dirname"; } + { src = "${coreutils}/bin/readlink"; } + ]; +}