From 92c57d8825d7d1c92fd997d100272482a9476182 Mon Sep 17 00:00:00 2001 From: liv <shadows@with.al> Date: Sat, 3 Aug 2024 22:19:00 +0200 Subject: [PATCH] set up a default config --- flake.lock | 66 +++++++++++++++++ flake.nix | 61 ++++++++++++++++ home-manager/home.nix | 52 +++++++++++++ home-manager/neovim.nix | 121 +++++++++++++++++++++++++++++++ modules/home-manager/default.nix | 6 ++ modules/nixos/default.nix | 6 ++ nixos/configuration.nix | 108 +++++++++++++++++++++++++++ nixos/hardware-configuration.nix | 12 +++ overlays/default.nix | 23 ++++++ pkgs/default.nix | 5 ++ shell.nix | 19 +++++ 11 files changed, 479 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 home-manager/home.nix create mode 100644 home-manager/neovim.nix create mode 100644 modules/home-manager/default.nix create mode 100644 modules/nixos/default.nix create mode 100644 nixos/configuration.nix create mode 100644 nixos/hardware-configuration.nix create mode 100644 overlays/default.nix create mode 100644 pkgs/default.nix create mode 100644 shell.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..786b663 --- /dev/null +++ b/flake.lock @@ -0,0 +1,66 @@ +{ + "nodes": { + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1722630065, + "narHash": "sha256-QfM/9BMRkCmgWzrPDK+KbgJOUlSJnfX4OvsUupEUZvA=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "afc892db74d65042031a093adb6010c4c3378422", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "master", + "repo": "home-manager", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1722421184, + "narHash": "sha256-/DJBI6trCeVnasdjUo9pbnodCLZcFqnVZiLUfqLH4jA=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "9f918d616c5321ad374ae6cb5ea89c9e04bf3e58", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1722519197, + "narHash": "sha256-VEdJmVU2eLFtLqCjTYJd1J7+Go8idAcZoT11IewFiRg=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "05405724efa137a0b899cce5ab4dde463b4fd30b", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "home-manager": "home-manager", + "nixpkgs": "nixpkgs", + "nixpkgs-stable": "nixpkgs-stable" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..2e0323f --- /dev/null +++ b/flake.nix @@ -0,0 +1,61 @@ +{ + description = "Mine very own Nix(OS) / home-manager / nix-darwin configuration"; + + inputs = { + # Nixpkgs + nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-24.05"; + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + + # Home manager + home-manager.url = "github:nix-community/home-manager/master"; + home-manager.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = + { self + , nixpkgs + , home-manager + , ... + } @ inputs: + let + inherit (self) outputs; + lib = nixpkgs.lib // home-manager.lib; + systems = [ + "x86_64-linux" + "aarch64-darwin" + ]; + forEachSystem = f: lib.genAttrs systems (system: import nixpkgs { + inherit system; + config.allowUnfree = true; + }); + username = "lu"; + in + { + packages = forEachSystem (pkgs: import ./pkgs { inherit pkgs; }); + devShells = forEachSystem (pkgs: import ./shell.nix { inherit pkgs; }); + formatter = forEachSystem (pkgs: pkgs.nixpkgs-fmt); + + overlays = import ./overlays { inherit inputs outputs; }; + nixosModules = import ./modules/nixos; + homeManagerModules = import ./modules/home-manager; + + nixosConfigurations = { + enoko = lib.nixosSystem { + specialArgs = { inherit inputs outputs; }; + modules = [ + ./nixos/configuration.nix + ]; + }; + }; + + homeConfigurations = { + "${username}@yukari" = lib.homeManagerConfiguration { + pkgs = nixpkgs.legacyPackages.x86_64-linux; + extraSpecialArgs = { inherit inputs outputs username; }; + modules = [ + ./home-manager/home.nix + ]; + }; + }; + }; +} diff --git a/home-manager/home.nix b/home-manager/home.nix new file mode 100644 index 0000000..34d287f --- /dev/null +++ b/home-manager/home.nix @@ -0,0 +1,52 @@ +# This is your home-manager configuration file +# Use this to configure your home environment (it replaces ~/.config/nixpkgs/home.nix) +{ inputs +, outputs +, lib +, config +, pkgs +, username +, ... +}: { + # You can import other home-manager modules here + imports = [ + # If you want to use modules your own flake exports (from modules/home-manager): + # outputs.homeManagerModules.example + + # Or modules exported from other flakes (such as nix-colors): + # inputs.nix-colors.homeManagerModules.default + + ./neovim.nix + ]; + + nixpkgs = { + # You can add overlays here + overlays = [ + # Add overlays your own flake exports (from overlays and pkgs dir): + outputs.overlays.additions + outputs.overlays.modifications + outputs.overlays.unstable-packages + ]; + + # Configure your nixpkgs instance + config = { + # Disable if you don't want unfree packages + allowUnfree = true; + }; + }; + + home = { + inherit username; + homeDirectory = "/home/${username}"; + }; + + # Enable home-manager and git + programs.home-manager.enable = true; + programs.git.enable = true; + + # Nicely reload system units when changing configs + systemd.user.startServices = "sd-switch"; + + # https://nixos.wiki/wiki/FAQ/When_do_I_update_stateVersion + home.stateVersion = "24.05"; +} diff --git a/home-manager/neovim.nix b/home-manager/neovim.nix new file mode 100644 index 0000000..c8d5b83 --- /dev/null +++ b/home-manager/neovim.nix @@ -0,0 +1,121 @@ +{ config, lib, pkgs, ... }: + +{ + programs.neovim = { + extraPackages = with pkgs; [ + # LazyVim + lua-language-server + stylua + # Telescope + ripgrep + ]; + + plugins = with pkgs.vimPlugins; [ + lazy-nvim + ]; + + extraLuaConfig = + let + plugins = with pkgs.vimPlugins; [ + # LazyVim + LazyVim + bufferline-nvim + cmp-buffer + cmp-nvim-lsp + cmp-path + cmp_luasnip + conform-nvim + dashboard-nvim + dressing-nvim + flash-nvim + friendly-snippets + gitsigns-nvim + indent-blankline-nvim + lualine-nvim + neo-tree-nvim + neoconf-nvim + neodev-nvim + noice-nvim + nui-nvim + nvim-cmp + nvim-lint + nvim-lspconfig + nvim-notify + nvim-spectre + nvim-treesitter + nvim-treesitter-context + nvim-treesitter-textobjects + nvim-ts-autotag + nvim-ts-context-commentstring + nvim-web-devicons + persistence-nvim + plenary-nvim + telescope-fzf-native-nvim + telescope-nvim + todo-comments-nvim + tokyonight-nvim + trouble-nvim + vim-illuminate + vim-startuptime + which-key-nvim + { name = "LuaSnip"; path = luasnip; } + { name = "catppuccin"; path = catppuccin-nvim; } + { name = "mini.ai"; path = mini-nvim; } + { name = "mini.bufremove"; path = mini-nvim; } + { name = "mini.comment"; path = mini-nvim; } + { name = "mini.indentscope"; path = mini-nvim; } + { name = "mini.pairs"; path = mini-nvim; } + { name = "mini.surround"; path = mini-nvim; } + ]; + mkEntryFromDrv = drv: + if lib.isDerivation drv then + { name = "${lib.getName drv}"; path = drv; } + else + drv; + lazyPath = pkgs.linkFarm "lazy-plugins" (builtins.map mkEntryFromDrv plugins); + in + '' + require("lazy").setup({ + defaults = { + lazy = true, + }, + dev = { + -- reuse files from pkgs.vimPlugins.* + path = "${lazyPath}", + patterns = { "." }, + -- fallback to download + fallback = true, + }, + spec = { + { "LazyVim/LazyVim", import = "lazyvim.plugins" }, + -- The following configs are needed for fixing lazyvim on nix + -- force enable telescope-fzf-native.nvim + { "nvim-telescope/telescope-fzf-native.nvim", enabled = true }, + -- disable mason.nvim, use programs.neovim.extraPackages + { "williamboman/mason-lspconfig.nvim", enabled = false }, + { "williamboman/mason.nvim", enabled = false }, + -- import/override with your plugins + { import = "plugins" }, + -- treesitter handled by xdg.configFile."nvim/parser", put this line at the end of spec to clear ensure_installed + { "nvim-treesitter/nvim-treesitter", opts = { ensure_installed = {} } }, + }, + }) + ''; + }; + + # https://github.com/nvim-treesitter/nvim-treesitter#i-get-query-error-invalid-node-type-at-position + xdg.configFile."nvim/parser".source = + let + parsers = pkgs.symlinkJoin { + name = "treesitter-parsers"; + paths = (pkgs.vimPlugins.nvim-treesitter.withPlugins (plugins: with plugins; [ + c + lua + ])).dependencies; + }; + in + "${parsers}/parser"; + + # Normal LazyVim config here, see https://github.com/LazyVim/starter/tree/main/lua + xdg.configFile."nvim/lua".source = ./lua; +} diff --git a/modules/home-manager/default.nix b/modules/home-manager/default.nix new file mode 100644 index 0000000..45aae31 --- /dev/null +++ b/modules/home-manager/default.nix @@ -0,0 +1,6 @@ +# Add your reusable home-manager modules to this directory, on their own file (https://nixos.wiki/wiki/Module). +# These should be stuff you would like to share with others, not your personal configurations. +{ + # List your module files here + # my-module = import ./my-module.nix; +} diff --git a/modules/nixos/default.nix b/modules/nixos/default.nix new file mode 100644 index 0000000..8605069 --- /dev/null +++ b/modules/nixos/default.nix @@ -0,0 +1,6 @@ +# Add your reusable NixOS modules to this directory, on their own file (https://nixos.wiki/wiki/Module). +# These should be stuff you would like to share with others, not your personal configurations. +{ + # List your module files here + # my-module = import ./my-module.nix; +} diff --git a/nixos/configuration.nix b/nixos/configuration.nix new file mode 100644 index 0000000..3b4ca08 --- /dev/null +++ b/nixos/configuration.nix @@ -0,0 +1,108 @@ +# This is your system's configuration file. +# Use this to configure your system environment (it replaces /etc/nixos/configuration.nix) +{ + inputs, + outputs, + lib, + config, + pkgs, + ... +}: { + # You can import other NixOS modules here + imports = [ + # If you want to use modules your own flake exports (from modules/nixos): + # outputs.nixosModules.example + + # Or modules from other flakes (such as nixos-hardware): + # inputs.hardware.nixosModules.common-cpu-amd + # inputs.hardware.nixosModules.common-ssd + + # You can also split up your configuration and import pieces of it here: + # ./users.nix + + # Import your generated (nixos-generate-config) hardware configuration + ./hardware-configuration.nix + ]; + + nixpkgs = { + # You can add overlays here + overlays = [ + # Add overlays your own flake exports (from overlays and pkgs dir): + outputs.overlays.additions + outputs.overlays.modifications + outputs.overlays.unstable-packages + + # You can also add overlays exported from other flakes: + # neovim-nightly-overlay.overlays.default + + # Or define it inline, for example: + # (final: prev: { + # hi = final.hello.overrideAttrs (oldAttrs: { + # patches = [ ./change-hello-to-hi.patch ]; + # }); + # }) + ]; + # Configure your nixpkgs instance + config = { + # Disable if you don't want unfree packages + allowUnfree = true; + }; + }; + + nix = let + flakeInputs = lib.filterAttrs (_: lib.isType "flake") inputs; + in { + settings = { + # Enable flakes and new 'nix' command + experimental-features = "nix-command flakes"; + # Opinionated: disable global registry + flake-registry = ""; + # Workaround for https://github.com/NixOS/nix/issues/9574 + nix-path = config.nix.nixPath; + }; + # Opinionated: disable channels + channel.enable = false; + + # Opinionated: make flake registry and nix path match flake inputs + registry = lib.mapAttrs (_: flake: {inherit flake;}) flakeInputs; + nixPath = lib.mapAttrsToList (n: _: "${n}=flake:${n}") flakeInputs; + }; + + # FIXME: Add the rest of your current configuration + + # TODO: Set your hostname + networking.hostName = "your-hostname"; + + # TODO: Configure your system-wide user settings (groups, etc), add more users as needed. + users.users = { + # FIXME: Replace with your username + your-username = { + # TODO: You can set an initial password for your user. + # If you do, you can skip setting a root password by passing '--no-root-passwd' to nixos-install. + # Be sure to change it (using passwd) after rebooting! + initialPassword = "correcthorsebatterystaple"; + isNormalUser = true; + openssh.authorizedKeys.keys = [ + # TODO: Add your SSH public key(s) here, if you plan on using SSH to connect + ]; + # TODO: Be sure to add any other groups you need (such as networkmanager, audio, docker, etc) + extraGroups = ["wheel"]; + }; + }; + + # This setups a SSH server. Very important if you're setting up a headless system. + # Feel free to remove if you don't need it. + services.openssh = { + enable = true; + settings = { + # Opinionated: forbid root login through SSH. + PermitRootLogin = "no"; + # Opinionated: use keys only. + # Remove if you want to SSH using passwords + PasswordAuthentication = false; + }; + }; + + # https://nixos.wiki/wiki/FAQ/When_do_I_update_stateVersion + system.stateVersion = "23.05"; +} diff --git a/nixos/hardware-configuration.nix b/nixos/hardware-configuration.nix new file mode 100644 index 0000000..1c4b000 --- /dev/null +++ b/nixos/hardware-configuration.nix @@ -0,0 +1,12 @@ +# This is just an example, you should generate yours with nixos-generate-config and put it in here. +{ + boot.loader.systemd-boot.enable = true; + + fileSystems."/" = { + device = "/dev/sda1"; + fsType = "ext4"; + }; + + # Set your system kind (needed for flakes) + nixpkgs.hostPlatform = "x86_64-linux"; +} diff --git a/overlays/default.nix b/overlays/default.nix new file mode 100644 index 0000000..7bfcb4c --- /dev/null +++ b/overlays/default.nix @@ -0,0 +1,23 @@ +# This file defines overlays +{inputs, ...}: { + # This one brings our custom packages from the 'pkgs' directory + additions = final: _prev: import ../pkgs final.pkgs; + + # This one contains whatever you want to overlay + # You can change versions, add patches, set compilation flags, anything really. + # https://nixos.wiki/wiki/Overlays + modifications = final: prev: { + # example = prev.example.overrideAttrs (oldAttrs: rec { + # ... + # }); + }; + + # When applied, the unstable nixpkgs set (declared in the flake inputs) will + # be accessible through 'pkgs.unstable' + unstable-packages = final: _prev: { + unstable = import inputs.nixpkgs-unstable { + system = final.system; + config.allowUnfree = true; + }; + }; +} diff --git a/pkgs/default.nix b/pkgs/default.nix new file mode 100644 index 0000000..3d9e23c --- /dev/null +++ b/pkgs/default.nix @@ -0,0 +1,5 @@ +# Custom packages, that can be defined similarly to ones from nixpkgs +# You can build them using 'nix build .#example' +pkgs: { + # example = pkgs.callPackage ./example { }; +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..6ea1dc4 --- /dev/null +++ b/shell.nix @@ -0,0 +1,19 @@ +# Shell for bootstrapping flake-enabled nix and other tooling +{ pkgs ? let + lock = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.nixpkgs.locked; + nixpkgs = fetchTarball { + url = "https://github.com/nixos/nixpkgs/archive/${lock.rev}.tar.gz"; + sha256 = lock.narHash; + }; + in + import nixpkgs { overlays = [ ]; } +, ... +}: { + default = pkgs.mkShell { + NIX_CONFIG = "extra-experimental-features = nix-command flakes repl-flake"; + nativeBuildInputs = with pkgs; [ + home-manager + git + ]; + }; +}