From 53d0bdf0ceeb31dcfce39ef480f3b7cfbef381d8 Mon Sep 17 00:00:00 2001 From: Laurent Le Houerou Date: Mon, 10 Mar 2025 21:11:14 +0400 Subject: [PATCH] wip --- README.md | 103 ++++++++++ flake.lock | 18 +- flake.nix | 116 +++++++++-- home/base/default.nix | 39 ++++ home/base/zsh/default.nix | 64 ++++++ home/base/zsh/oh-my-posh/config.json | 185 ++++++++++++++++++ home/core.nix | 8 - .../home.nix => home/desktop/default.nix | 51 +++-- home/{ => desktop}/i3/config | 0 home/{ => desktop}/i3/default.nix | 0 home/{ => desktop}/picom/default.nix | 0 home/{ => desktop}/polybar/config.ini | 0 home/{ => desktop}/polybar/default.nix | 0 home/{ => desktop}/polybar/launch.sh | 4 +- home/server/default.nix | 70 +++++++ home/zsh/default.nix | 0 hosts/vm/default.nix | 25 --- machines/desktop-pc/default.nix | 40 ++++ .../desktop-pc/hardware-configuration.nix | 36 ++++ machines/home-server/default.nix | 87 ++++++++ .../home-server/hardware-configuration.nix | 36 ++++ machines/vm/default.nix | 23 +++ .../vm/hardware-configuration.nix | 4 +- switch.sh | 20 ++ modules/system.nix => system/base/default.nix | 41 +++- modules/i3.nix => system/desktop/default.nix | 21 +- system/server/default.nix | 43 ++++ users/laurent/nixos.nix | 2 - 28 files changed, 929 insertions(+), 107 deletions(-) create mode 100644 README.md create mode 100644 home/base/default.nix create mode 100644 home/base/zsh/default.nix create mode 100644 home/base/zsh/oh-my-posh/config.json delete mode 100644 home/core.nix rename users/laurent/home.nix => home/desktop/default.nix (89%) rename home/{ => desktop}/i3/config (100%) rename home/{ => desktop}/i3/default.nix (100%) rename home/{ => desktop}/picom/default.nix (100%) rename home/{ => desktop}/polybar/config.ini (100%) rename home/{ => desktop}/polybar/default.nix (100%) rename home/{ => desktop}/polybar/launch.sh (82%) create mode 100644 home/server/default.nix delete mode 100644 home/zsh/default.nix delete mode 100644 hosts/vm/default.nix create mode 100644 machines/desktop-pc/default.nix create mode 100644 machines/desktop-pc/hardware-configuration.nix create mode 100644 machines/home-server/default.nix create mode 100644 machines/home-server/hardware-configuration.nix create mode 100644 machines/vm/default.nix rename {hosts => machines}/vm/hardware-configuration.nix (93%) create mode 100755 switch.sh rename modules/system.nix => system/base/default.nix (60%) rename modules/i3.nix => system/desktop/default.nix (54%) create mode 100644 system/server/default.nix delete mode 100644 users/laurent/nixos.nix diff --git a/README.md b/README.md new file mode 100644 index 0000000..eb7d798 --- /dev/null +++ b/README.md @@ -0,0 +1,103 @@ +# NixOS Configuration + +This repository contains my personal NixOS configuration, structured in a pyramidal way for easy management and reuse. + +## Structure + +### System Configuration + +The system configuration is organized in layers: + +1. **Base** (`system/base/default.nix`): Common configuration for all machines +2. **Desktop** (`system/desktop/default.nix`): Configuration specific to desktop environments +3. **Server** (`system/server/default.nix`): Configuration specific to server environments +4. **Machine-specific** (`machines//default.nix`): Configuration specific to individual machines + +### Home Configuration + +The home configuration follows a similar structure: + +1. **Base** (`home/base/default.nix`): Common home configuration for all environments +2. **Desktop** (`home/desktop/default.nix`): Home configuration specific to desktop environments +3. **Server** (`home/server/default.nix`): Home configuration specific to server environments + +## Available Configurations + +This repository includes configurations for the following machines: + +1. **nixos** (VM): A virtual machine configuration for testing +2. **desktop-pc**: A physical desktop PC with NVIDIA GPU +3. **home-server**: A home server with Samba and Jellyfin services + +## Usage + +To build and switch to a specific configuration: + +```bash +# For the VM +sudo nixos-rebuild switch --flake .#nixos + +# For the desktop PC +sudo nixos-rebuild switch --flake .#desktop-pc + +# For the home server +sudo nixos-rebuild switch --flake .#home-server +``` + +### Helper Script + +A helper script is provided to make switching between configurations easier: + +```bash +# Switch to the VM configuration (default) +./switch.sh + +# Switch to the desktop PC configuration +./switch.sh desktop-pc + +# Switch to the home server configuration +./switch.sh home-server +``` + +## Adding a New Machine + +To add a new machine: + +1. Create a new directory in `machines/` with the machine name +2. Create a `default.nix` file with machine-specific configuration +3. Copy the hardware configuration to `machines//hardware-configuration.nix` +4. Update `flake.nix` to include the new machine + +Example: + +```nix +# In flake.nix +new-machine = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + specialArgs = inputs; + modules = [ + # Base system configuration + ./system/base + + # Desktop or server configuration + ./system/desktop # or ./system/server + + # Machine-specific configuration + ./machines/new-machine + + # Home-manager configuration + home-manager.nixosModules.home-manager { + # ... home-manager configuration + } + ]; +}; +``` + +## Customization + +- For desktop environments, enable the desktop configurations +- For server environments, enable the server configurations and disable desktop configurations + +## License + +This configuration is personal and provided as-is without any warranty. \ No newline at end of file diff --git a/flake.lock b/flake.lock index 8c6c062..6b2c71a 100644 --- a/flake.lock +++ b/flake.lock @@ -7,11 +7,11 @@ ] }, "locked": { - "lastModified": 1730633670, - "narHash": "sha256-ZFJqIXpvVKvzOVFKWNRDyIyAo+GYdmEPaYi1bZB6uf0=", + "lastModified": 1741579508, + "narHash": "sha256-skRbH+UF2ES+msEa+KWi7AQFX73S+QsGlPsyCU6XyE0=", "owner": "nix-community", "repo": "home-manager", - "rev": "8f6ca7855d409aeebe2a582c6fd6b6a8d0bf5661", + "rev": "744f749dd6fbc1489591ea370b95156858629cb9", "type": "github" }, "original": { @@ -23,11 +23,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1730531603, - "narHash": "sha256-Dqg6si5CqIzm87sp57j5nTaeBbWhHFaVyG7V6L8k3lY=", + "lastModified": 1741379970, + "narHash": "sha256-Wh7esNh7G24qYleLvgOSY/7HlDUzWaL/n4qzlBePpiw=", "owner": "nixos", "repo": "nixpkgs", - "rev": "7ffd9ae656aec493492b44d0ddfb28e79a1ea25d", + "rev": "36fd87baa9083f34f7f5027900b62ee6d09b1f2f", "type": "github" }, "original": { @@ -39,11 +39,11 @@ }, "nixpkgs-stable": { "locked": { - "lastModified": 1730327045, - "narHash": "sha256-xKel5kd1AbExymxoIfQ7pgcX6hjw9jCgbiBjiUfSVJ8=", + "lastModified": 1735563628, + "narHash": "sha256-OnSAY7XDSx7CtDoqNh8jwVwh4xNL/2HaJxGjryLWzX8=", "owner": "nixos", "repo": "nixpkgs", - "rev": "080166c15633801df010977d9d7474b4a6c549d7", + "rev": "b134951a4c9f3c995fd7be05f3243f8ecd65d798", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 8d263fb..e385682 100644 --- a/flake.nix +++ b/flake.nix @@ -18,25 +18,103 @@ ... }: { - nixosConfigurations.nixos = let - username = "laurent"; - specialArgs = { inherit username; }; - in nixpkgs.lib.nixosSystem { - inherit specialArgs; - system = "x86_64-linux"; - modules = [ - ./hosts/vm - ./users/${username}/nixos.nix - - home-manager.nixosModules.home-manager - { - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - home-manager.extraSpecialArgs = inputs // specialArgs; - home-manager.users.${username} = import ./users/${username}/home.nix; - } - - ]; + # Common configuration function to reduce repetition + nixosConfigurations = { + # VM configuration + nixos = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + specialArgs = inputs; + modules = [ + # Base system configuration + ./system/base + + # Desktop-specific configuration + ./system/desktop + + # Machine-specific configuration + ./machines/vm + + # Home-manager configuration + home-manager.nixosModules.home-manager { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.extraSpecialArgs = inputs; + home-manager.users.laurent = { ... }: { + imports = [ + # Base home configuration + ./home/base + + # Desktop-specific home configuration + ./home/desktop + ]; + }; + } + ]; + }; + + # Desktop PC configuration + desktop-pc = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + specialArgs = inputs; + modules = [ + # Base system configuration + ./system/base + + # Desktop-specific configuration + ./system/desktop + + # Machine-specific configuration + ./machines/desktop-pc + + # Home-manager configuration + home-manager.nixosModules.home-manager { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.extraSpecialArgs = inputs; + home-manager.users.laurent = { ... }: { + imports = [ + # Base home configuration + ./home/base + + # Desktop-specific home configuration + ./home/desktop + ]; + }; + } + ]; + }; + + # Home server configuration + home-server = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + specialArgs = inputs; + modules = [ + # Base system configuration + ./system/base + + # Server-specific configuration + ./system/server + + # Machine-specific configuration + ./machines/home-server + + # Home-manager configuration + home-manager.nixosModules.home-manager { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.extraSpecialArgs = inputs; + home-manager.users.laurent = { ... }: { + imports = [ + # Base home configuration + ./home/base + + # Server-specific home configuration + ./home/server + ]; + }; + } + ]; + }; }; }; } diff --git a/home/base/default.nix b/home/base/default.nix new file mode 100644 index 0000000..3c48c64 --- /dev/null +++ b/home/base/default.nix @@ -0,0 +1,39 @@ +{ + config, + pkgs, + lib, + ... +}: { + + imports = [ + ./zsh + ]; + # Base home configuration for all environments + + home = { + username = "laurent"; + homeDirectory = "/home/laurent"; + stateVersion = "24.05"; + }; + + + programs.home-manager.enable = true; + + # Common programs for all environments + programs.git = { + enable = true; + userName = "Laurent Le Houerou"; + userEmail = "laurent@lehouerou.net"; + }; + + # Common packages for all environments + home.packages = with pkgs; [ + btop + neovim + lazygit + eza + fzf + ripgrep + zoxide + ]; +} \ No newline at end of file diff --git a/home/base/zsh/default.nix b/home/base/zsh/default.nix new file mode 100644 index 0000000..8d15c7f --- /dev/null +++ b/home/base/zsh/default.nix @@ -0,0 +1,64 @@ +{ pkgs, ... }: + +{ + programs.zsh = { + enable = true; + enableCompletion = true; + + # History settings + history = { + size = 10000; + path = "$HOME/.zsh_history"; + ignoreDups = true; + share = true; + }; + + autosuggestion = { + enable = true; + }; + + # Shell options + initExtra = '' + # Enable vi mode + bindkey -v + + # Better history search + bindkey '^R' history-incremental-search-backward + + # Basic auto/tab completion + autoload -U compinit + zstyle ':completion:*' menu select + zmodload zsh/complist + compinit + _comp_options+=(globdots) + ''; + + # Aliases + shellAliases = { + ll = "ls -la"; + ".." = "cd .."; + "..." = "cd ../.."; + update = "sudo nixos-rebuild switch"; + vim = "nvim"; + }; + + plugins = [ + { + name = "zsh-syntax-highlighting"; + src = pkgs.fetchFromGitHub { + owner = "zsh-users"; + repo = "zsh-syntax-highlighting"; + rev = "refs/tags/0.8.0"; + sha256 = "1yl8zdip1z9inp280sfa5byjbf2vqh2iazsycar987khjsi5d5w8"; + }; + } + ]; + }; + + programs.oh-my-posh = { + enable = true; + enableZshIntegration = true; + package = pkgs.oh-my-posh; + settings = builtins.fromJSON (builtins.readFile ./oh-my-posh/config.json); + }; +} diff --git a/home/base/zsh/oh-my-posh/config.json b/home/base/zsh/oh-my-posh/config.json new file mode 100644 index 0000000..a571627 --- /dev/null +++ b/home/base/zsh/oh-my-posh/config.json @@ -0,0 +1,185 @@ +{ + "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json", + "palette": { + "base": "#1E1E2E", + "blue": "#89B4FA", + "crust": "#11111B", + "false": "p:red", + "flamingo": "#F2CDCD", + "green": "#A6E3A1", + "lavender": "#B4BEFE", + "mantle": "#181825", + "maroon": "#EBA0AC", + "mauve": "#CBA6F7", + "overlay0": "#6C7086", + "overlay1": "#7F849C", + "overlay2": "#9399B2", + "peach": "#FAB387", + "pink": "#F5C2E7", + "red": "#F38BA8", + "rosewater": "#F5E0DC", + "sapphire": "#74C7EC", + "sky": "#89DCEB", + "subtext0": "#A6ADC8", + "subtext1": "#BAC2DE", + "surface0": "#313244", + "surface1": "#45475A", + "surface2": "#585B70", + "teal": "#94E2D5", + "text": "#CDD6F4", + "true": "p:green", + "yellow": "#F9E2AF" + }, + "transient_prompt": { + "template": "{{ .PWD }} {{ now | date \"15:04:05\" }} {{ if gt .Code 0 }}❯{{ else }}❯{{ end }} ", + "foreground": "p:text" + }, + "console_title_template": "{{ .Shell }} in {{ .Folder }}", + "blocks": [ + { + "type": "prompt", + "alignment": "left", + "segments": [ + { + "style": "diamond", + "leading_diamond": "\ue0b2", + "template": " {{.Icon}} ", + "foreground": "p:text", + "background": "p:surface0", + "type": "os" + }, + { + "properties": { + "home_icon": "~", + "style": "full" + }, + "style": "powerline", + "template": " \uf07c {{ .Path }} ", + "foreground": "p:base", + "powerline_symbol": "\ue0b0", + "background": "p:lavender", + "type": "path" + }, + { + "properties": { + "branch_icon": "\uf126 ", + "fetch_stash_count": true, + "fetch_status": true, + "fetch_upstream_icon": true + }, + "style": "powerline", + "template": " {{ .UpstreamIcon }}{{ .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 }} ", + "foreground": "#000000", + "powerline_symbol": "\ue0b0", + "background": "#4e9a06", + "type": "git", + "background_templates": [ + "{{ if or (.Working.Changed) (.Staging.Changed) }}#c4a000{{ end }}", + "{{ if and (gt .Ahead 0) (gt .Behind 0) }}#f26d50{{ end }}", + "{{ if gt .Ahead 0 }}#89d1dc{{ end }}", + "{{ if gt .Behind 0 }}#4e9a06{{ end }}" + ] + } + ] + }, + { + "type": "prompt", + "alignment": "right", + "segments": [ + { + "properties": { + "fetch_version": true + }, + "style": "powerline", + "template": " {{ if .PackageManagerIcon }}{{ .PackageManagerIcon }} {{ end }}{{ .Full }} \ue718 ", + "foreground": "#ffffff", + "powerline_symbol": "\ue0b2", + "background": "#689f63", + "type": "node", + "invert_powerline": true + }, + { + "properties": { + "fetch_version": true + }, + "style": "powerline", + "template": " {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} \ue627 ", + "foreground": "#111111", + "powerline_symbol": "\ue0b2", + "background": "#00acd7", + "type": "go", + "invert_powerline": true + }, + { + "properties": { + "fetch_version": true + }, + "style": "powerline", + "template": " {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} \ue624 ", + "foreground": "#111111", + "powerline_symbol": "\ue0b2", + "background": "#4063D8", + "type": "julia", + "invert_powerline": true + }, + { + "properties": { + "display_mode": "files", + "fetch_virtual_env": false + }, + "style": "powerline", + "template": " {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} \ue235 ", + "foreground": "#111111", + "powerline_symbol": "\ue0b2", + "background": "#FFDE57", + "type": "python", + "invert_powerline": true + }, + { + "style": "accordion", + "template": " \uf0ad ", + "foreground": "p:text", + "powerline_symbol": "\ue0b2", + "background": "p:yellow", + "type": "root", + "invert_powerline": true + }, + { + "properties": { + "always_enabled": true + }, + "style": "diamond", + "trailing_diamond": "\ue0b0", + "template": " {{ if gt .Code 0 }}{{ reason .Code }}{{ else }}\uf42e{{ end }} ", + "foreground": "p:text", + "powerline_symbol": "\ue0b2", + "background": "p:surface0", + "type": "status", + "foreground_templates": [ + "{{ if gt .Code 0 }}p:surface0{{ end }}" + ], + "background_templates": [ + "{{ if gt .Code 0 }}p:red{{ end }}" + ], + "invert_powerline": true + } + ] + }, + { + "type": "prompt", + "alignment": "left", + "segments": [ + { + "style": "plain", + "template": "❯", + "foreground": "p:text", + "type": "text" + } + ], + "newline": true + } + ], + "version": 3, + "final_space": true + } + \ No newline at end of file diff --git a/home/core.nix b/home/core.nix deleted file mode 100644 index 93e803e..0000000 --- a/home/core.nix +++ /dev/null @@ -1,8 +0,0 @@ -{username, ...}: { - home = { - inherit username; - homeDirectory = "/home/${username}"; - stateVersion = "24.05"; - }; - programs.home-manager.enable = true; -} \ No newline at end of file diff --git a/users/laurent/home.nix b/home/desktop/default.nix similarity index 89% rename from users/laurent/home.nix rename to home/desktop/default.nix index d9fbe01..8f82392 100644 --- a/users/laurent/home.nix +++ b/home/desktop/default.nix @@ -1,27 +1,25 @@ -{ config, pkgs, lib, ... }: - { - imports = [ - ../../home/core.nix - ../../home/i3 - ]; - - programs.git = { - userName = "Laurent Le Houerou"; - userEmail = "laurent@lehouerou.net"; - }; - + config, + pkgs, + lib, + ... +}: { + # Desktop-specific home configuration - - home.packages = with pkgs; [ - btop - code-cursor - lazygit - neovim - brave - + # Import i3 configuration + imports = [ + ./i3 + ./polybar + ./picom ]; - + + # Desktop-specific packages + home.packages = with pkgs; [ + brave + code-cursor + ]; + + # Terminal configuration programs.kitty = lib.mkForce { enable = true; settings = { @@ -73,11 +71,8 @@ color15 = "#A6ADC8"; }; }; - - programs.zsh = { - enable = true; - }; - + + # Multi-monitor setup services.grobi = { enable = true; rules = [ @@ -102,7 +97,5 @@ ]; } ]; - - }; -} +} \ No newline at end of file diff --git a/home/i3/config b/home/desktop/i3/config similarity index 100% rename from home/i3/config rename to home/desktop/i3/config diff --git a/home/i3/default.nix b/home/desktop/i3/default.nix similarity index 100% rename from home/i3/default.nix rename to home/desktop/i3/default.nix diff --git a/home/picom/default.nix b/home/desktop/picom/default.nix similarity index 100% rename from home/picom/default.nix rename to home/desktop/picom/default.nix diff --git a/home/polybar/config.ini b/home/desktop/polybar/config.ini similarity index 100% rename from home/polybar/config.ini rename to home/desktop/polybar/config.ini diff --git a/home/polybar/default.nix b/home/desktop/polybar/default.nix similarity index 100% rename from home/polybar/default.nix rename to home/desktop/polybar/default.nix diff --git a/home/polybar/launch.sh b/home/desktop/polybar/launch.sh similarity index 82% rename from home/polybar/launch.sh rename to home/desktop/polybar/launch.sh index ce342b2..599b449 100644 --- a/home/polybar/launch.sh +++ b/home/desktop/polybar/launch.sh @@ -9,6 +9,4 @@ while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done # Launch bar1 and bar2 MONITORS=$(xrandr --query | grep " connected" | cut -d" " -f1) -MONITORS=$MONITORS polybar top; - -echo "Bars launched..." \ No newline at end of file +MONITORS=$MONITORS polybar top; \ No newline at end of file diff --git a/home/server/default.nix b/home/server/default.nix new file mode 100644 index 0000000..d5e5d69 --- /dev/null +++ b/home/server/default.nix @@ -0,0 +1,70 @@ +{ + config, + pkgs, + lib, + ... +}: { + # Server-specific home configuration + + # Server-specific packages + home.packages = with pkgs; [ + tmux + htop + iotop + iftop + nmap + ]; + + # Tmux configuration + programs.tmux = { + enable = true; + clock24 = true; + historyLimit = 10000; + terminal = "screen-256color"; + + plugins = with pkgs.tmuxPlugins; [ + sensible + yank + resurrect + continuum + ]; + + extraConfig = '' + # Enable mouse mode + set -g mouse on + + # Start windows and panes at 1, not 0 + set -g base-index 1 + setw -g pane-base-index 1 + + # Set status bar + set -g status-style 'bg=#333333 fg=#5eacd3' + ''; + }; + + # Vim configuration for server use + programs.neovim = { + enable = true; + defaultEditor = true; + viAlias = true; + vimAlias = true; + + plugins = with pkgs.vimPlugins; [ + vim-nix + vim-sensible + vim-fugitive + vim-surround + ]; + + extraConfig = '' + set number + set relativenumber + set tabstop=2 + set shiftwidth=2 + set expandtab + set smartindent + set ignorecase + set smartcase + ''; + }; +} \ No newline at end of file diff --git a/home/zsh/default.nix b/home/zsh/default.nix deleted file mode 100644 index e69de29..0000000 diff --git a/hosts/vm/default.nix b/hosts/vm/default.nix deleted file mode 100644 index 8ecb02d..0000000 --- a/hosts/vm/default.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ config, pkgs, ... }: - -{ - imports = - [ - ../../modules/system.nix - ../../modules/i3.nix - # Include the results of the hardware scan. - ./hardware-configuration.nix - ]; - - # Bootloader. - boot.loader.grub = { - enable = true; - device = "/dev/vda"; - useOSProber = true; - }; - - networking.hostName = "nixos"; # Define your hostname. - networking.networkmanager.enable = true; - - - system.stateVersion = "24.05"; # Did you read the comment? - -} diff --git a/machines/desktop-pc/default.nix b/machines/desktop-pc/default.nix new file mode 100644 index 0000000..48e6958 --- /dev/null +++ b/machines/desktop-pc/default.nix @@ -0,0 +1,40 @@ +{ config, pkgs, lib, ... }: + +{ + imports = [ ./hardware-configuration.nix ]; + + # Bootloader + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + + # Networking + networking.hostName = "desktop-pc"; + networking.networkmanager.enable = true; + + # GPU drivers (NVIDIA example) + services.xserver.videoDrivers = [ "nvidia" ]; + hardware.nvidia = { + modesetting.enable = true; + powerManagement.enable = true; + open = false; + nvidiaSettings = true; + }; + + # Additional hardware-specific settings + hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + + # Enable CUPS for printing + services.printing = { + enable = true; + drivers = [ pkgs.hplip ]; + }; + + # Enable scanning + hardware.sane = { + enable = true; + extraBackends = [ pkgs.sane-airscan ]; + }; + + # System state version + system.stateVersion = "24.05"; +} \ No newline at end of file diff --git a/machines/desktop-pc/hardware-configuration.nix b/machines/desktop-pc/hardware-configuration.nix new file mode 100644 index 0000000..4dde4e0 --- /dev/null +++ b/machines/desktop-pc/hardware-configuration.nix @@ -0,0 +1,36 @@ +# Do not modify this file! It was generated by 'nixos-generate-config' +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ config, lib, pkgs, modulesPath, ... }: + +{ + imports = [ + (modulesPath + "/installer/scan/not-detected.nix") + ]; + + # This is a placeholder. Replace with actual hardware configuration + # generated by nixos-generate-config when setting up the machine. + + boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "nvme" "usbhid" "usb_storage" "sd_mod" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-intel" ]; + boot.extraModulePackages = [ ]; + + # Example filesystem configuration + fileSystems."/" = { + device = "/dev/disk/by-label/nixos"; + fsType = "ext4"; + }; + + fileSystems."/boot" = { + device = "/dev/disk/by-label/boot"; + fsType = "vfat"; + }; + + swapDevices = [ { device = "/dev/disk/by-label/swap"; } ]; + + # Enables DHCP on each ethernet and wireless interface + networking.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; +} \ No newline at end of file diff --git a/machines/home-server/default.nix b/machines/home-server/default.nix new file mode 100644 index 0000000..9d64942 --- /dev/null +++ b/machines/home-server/default.nix @@ -0,0 +1,87 @@ +{ config, pkgs, lib, ... }: + +{ + imports = [ ./hardware-configuration.nix ]; + + # Bootloader + boot.loader.grub = { + enable = true; + device = "/dev/sda"; + useOSProber = false; + }; + + # Networking + networking.hostName = "home-server"; + networking.networkmanager.enable = true; + + # Static IP configuration + networking.interfaces.enp1s0 = { + useDHCP = false; + ipv4.addresses = [{ + address = "192.168.1.100"; + prefixLength = 24; + }]; + }; + networking.defaultGateway = "192.168.1.1"; + networking.nameservers = [ "1.1.1.1" "8.8.8.8" ]; + + # Additional services for a home server + services = { + # Network file sharing + samba = { + enable = true; + securityType = "user"; + extraConfig = '' + workgroup = WORKGROUP + server string = Home Server + netbios name = HOME-SERVER + security = user + use sendfile = yes + max protocol = smb2 + # note: localhost is the ipv4 localhost address + hosts allow = 192.168.1. 127.0.0.1 localhost + hosts deny = 0.0.0.0/0 + ''; + shares = { + public = { + path = "/mnt/data/public"; + browseable = "yes"; + "read only" = "no"; + "guest ok" = "yes"; + "create mask" = "0644"; + "directory mask" = "0755"; + }; + private = { + path = "/mnt/data/private"; + browseable = "yes"; + "read only" = "no"; + "guest ok" = "no"; + "create mask" = "0644"; + "directory mask" = "0755"; + "valid users" = "laurent"; + }; + }; + }; + + # Media server + jellyfin.enable = true; + }; + + # Firewall settings + networking.firewall = { + enable = true; + allowedTCPPorts = [ + 22 # SSH + 445 # SMB + 139 # SMB + 8096 # Jellyfin + ]; + allowedUDPPorts = [ + 137 # SMB + 138 # SMB + ]; + }; + + # System state version + system.stateVersion = "24.05"; +} \ No newline at end of file diff --git a/machines/home-server/hardware-configuration.nix b/machines/home-server/hardware-configuration.nix new file mode 100644 index 0000000..4591b04 --- /dev/null +++ b/machines/home-server/hardware-configuration.nix @@ -0,0 +1,36 @@ +# Do not modify this file! It was generated by 'nixos-generate-config' +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ config, lib, pkgs, modulesPath, ... }: + +{ + imports = [ + (modulesPath + "/installer/scan/not-detected.nix") + ]; + + # This is a placeholder. Replace with actual hardware configuration + # generated by nixos-generate-config when setting up the machine. + + boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "usb_storage" "usbhid" "sd_mod" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-intel" ]; + boot.extraModulePackages = [ ]; + + # Example filesystem configuration + fileSystems."/" = { + device = "/dev/disk/by-label/nixos"; + fsType = "ext4"; + }; + + fileSystems."/mnt/data" = { + device = "/dev/disk/by-label/data"; + fsType = "ext4"; + }; + + swapDevices = [ { device = "/dev/disk/by-label/swap"; } ]; + + # Enables DHCP on each ethernet and wireless interface + networking.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; +} \ No newline at end of file diff --git a/machines/vm/default.nix b/machines/vm/default.nix new file mode 100644 index 0000000..ad43cda --- /dev/null +++ b/machines/vm/default.nix @@ -0,0 +1,23 @@ +{ config, pkgs, ... }: + +{ + imports = [ ./hardware-configuration.nix ]; + + # Bootloader. + boot.loader.grub = { + enable = true; + device = "/dev/vda"; + useOSProber = true; + }; + + networking.hostName = "nixos"; # Define your hostname. + networking.networkmanager.enable = true; + + # This value determines the NixOS release from which the default + # settings for stateful data, like file locations and database versions + # on your system were taken. It's perfectly fine and recommended to leave + # this value at the release version of the first install of this system. + # Before changing this value read the documentation for this option + # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). + system.stateVersion = "24.05"; # Did you read the comment? +} \ No newline at end of file diff --git a/hosts/vm/hardware-configuration.nix b/machines/vm/hardware-configuration.nix similarity index 93% rename from hosts/vm/hardware-configuration.nix rename to machines/vm/hardware-configuration.nix index e37f78a..d986e50 100644 --- a/hosts/vm/hardware-configuration.nix +++ b/machines/vm/hardware-configuration.nix @@ -1,4 +1,4 @@ -# Do not modify this file! It was generated by ‘nixos-generate-config’ +# Do not modify this file! It was generated by 'nixos-generate-config' # and may be overwritten by future invocations. Please make changes # to /etc/nixos/configuration.nix instead. { config, lib, pkgs, modulesPath, ... }: @@ -30,4 +30,4 @@ # networking.interfaces.enp1s0.useDHCP = lib.mkDefault true; nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; -} +} \ No newline at end of file diff --git a/switch.sh b/switch.sh new file mode 100755 index 0000000..50688f6 --- /dev/null +++ b/switch.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# Helper script to switch between NixOS configurations + +set -e + +# Default to the nixos configuration if no argument is provided +CONFIG=${1:-nixos} + +# Check if the configuration exists in flake.nix +if ! grep -q "nixosConfigurations.$CONFIG" flake.nix; then + echo "Error: Configuration '$CONFIG' not found in flake.nix" + echo "Available configurations:" + grep -o "nixosConfigurations\.[a-zA-Z0-9_-]*" flake.nix | sed 's/nixosConfigurations\./ - /' + exit 1 +fi + +echo "Switching to configuration: $CONFIG" +sudo nixos-rebuild switch --flake ".#$CONFIG" +echo "Successfully switched to $CONFIG configuration" \ No newline at end of file diff --git a/modules/system.nix b/system/base/default.nix similarity index 60% rename from modules/system.nix rename to system/base/default.nix index 82855f7..52cbb79 100644 --- a/modules/system.nix +++ b/system/base/default.nix @@ -1,13 +1,13 @@ { pkgs, lib, - username, ... }: { - users.users.${username} = { + users.users.laurent = { isNormalUser = true; - description = username; + description = "laurent"; extraGroups = [ "networkmanager" "wheel" ]; + shell = pkgs.zsh; }; nix.settings = { @@ -20,6 +20,11 @@ options = lib.mkDefault "--delete-older-than 7d"; }; + nix.optimise = { + automatic = lib.mkDefault true; + dates = lib.mkDefault [ "weekly" ]; + }; + nixpkgs.config.allowUnfree = true; time.timeZone = "Indian/Reunion"; @@ -41,16 +46,34 @@ }; services.printing.enable = true; - - fonts.packages = with pkgs; [ - (nerdfonts.override { fonts = [ "FiraCode" ]; }) - ]; - + environment.systemPackages = with pkgs; [ git vim wget pavucontrol + eza + zoxide + btop + fzf + ripgrep ]; -} \ No newline at end of file + fonts = { + packages = with pkgs; [ + nerd-fonts.fira-code + noto-fonts + noto-fonts-cjk-sans + noto-fonts-emoji + ]; + fontconfig = { + defaultFonts = { + serif = [ "Noto Serif" ]; + sansSerif = [ "Noto Sans" ]; + monospace = [ "FiraCode Nerd Font Mono" ]; + }; + }; + }; + + programs.zsh.enable = true; +} \ No newline at end of file diff --git a/modules/i3.nix b/system/desktop/default.nix similarity index 54% rename from modules/i3.nix rename to system/desktop/default.nix index 965c0c2..31a3d89 100644 --- a/modules/i3.nix +++ b/system/desktop/default.nix @@ -2,6 +2,9 @@ pkgs, ... }: { + # Desktop-specific configuration that builds on the base + + # Include i3 window manager services.xserver = { enable = true; windowManager.i3 = { @@ -23,4 +26,20 @@ }; services.displayManager.defaultSession = "none+i3"; -} \ No newline at end of file + + # Additional desktop-specific packages + environment.systemPackages = with pkgs; [ + firefox + libreoffice + vlc + gimp + ]; + + # Enable sound + sound.enable = true; + hardware.pulseaudio.enable = true; + + # Enable bluetooth + hardware.bluetooth.enable = true; + services.blueman.enable = true; +} \ No newline at end of file diff --git a/system/server/default.nix b/system/server/default.nix new file mode 100644 index 0000000..38046e7 --- /dev/null +++ b/system/server/default.nix @@ -0,0 +1,43 @@ +{ + pkgs, + ... +}: { + # Server-specific configuration that builds on the base + + # Disable unnecessary graphical services + services.xserver.enable = false; + + # Server-specific packages + environment.systemPackages = with pkgs; [ + tmux + htop + iotop + iftop + nmap + ]; + + # Enable SSH server + services.openssh = { + enable = true; + settings = { + PasswordAuthentication = false; + PermitRootLogin = "no"; + }; + }; + + # Firewall configuration + networking.firewall = { + enable = true; + allowedTCPPorts = [ 22 ]; # SSH + }; + + # Optimize for server use + services.fstrim.enable = true; + boot.tmp.cleanOnBoot = true; + + # More aggressive garbage collection for servers + nix.gc = { + dates = "daily"; + options = "--delete-older-than 3d"; + }; +} \ No newline at end of file diff --git a/users/laurent/nixos.nix b/users/laurent/nixos.nix deleted file mode 100644 index 0af704e..0000000 --- a/users/laurent/nixos.nix +++ /dev/null @@ -1,2 +0,0 @@ -{ -} \ No newline at end of file