From d0c72f5d3c46c5133e5e115145acc1c4af52ab8e Mon Sep 17 00:00:00 2001 From: tristan <> Date: Thu, 22 May 2025 13:18:59 -0400 Subject: [PATCH] initial flaking --- caddy.nix | 10 +++ configuration.nix | 177 +++++++++++++++++++++++++++++++++++++ flake.nix | 19 ++++ hardware-configuration.nix | 41 +++++++++ wireguard.nix | 39 ++++++++ 5 files changed, 286 insertions(+) create mode 100644 caddy.nix create mode 100644 configuration.nix create mode 100644 flake.nix create mode 100644 hardware-configuration.nix create mode 100644 wireguard.nix diff --git a/caddy.nix b/caddy.nix new file mode 100644 index 0000000..a4def1d --- /dev/null +++ b/caddy.nix @@ -0,0 +1,10 @@ +{ + services.caddy = { + enable = true; + + virtualHosts."mymarseille.duckdns.org".extraConfig = '' + reverse_proxy localhost:4533 + + ''; + }; +} diff --git a/configuration.nix b/configuration.nix new file mode 100644 index 0000000..a1f8ea4 --- /dev/null +++ b/configuration.nix @@ -0,0 +1,177 @@ +# Edit this configuration file to define what should be installed on +# your system. Help is available in the configuration.nix(5) man page, on +# https://search.nixos.org/options and in the NixOS manual (`nixos-help`). + +{ config, lib, pkgs, ... }: + +{ + imports = + [ # Include the results of the hardware scan. + ./hardware-configuration.nix + ./caddy.nix + ./wireguard.nix + ]; + + # Use the systemd-boot EFI boot loader. + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + + + # Enable Flakes + nix.settings.experimental-features = [ "nix-command" "flakes" ]; + + + networking.hostName = "mini"; # Define your hostname. + # Pick only one of the below networking options. + networking.wireless = { + enable = true; + networks."CT7D6".psk = "pz3zvb5x4k9j88j8"; + networks."Wifi".psk = "WifiWifi"; + }; # Enables wireless support via wpa_supplicant. + + networking.wireless.userControlled.enable = false; + + # networking.networkmanager.enable = true; # Easiest to use and most distros use this by default. + + + + # Set your time zone. + time.timeZone = "America/Montreal"; + + # Configure network proxy if necessary + # networking.proxy.default = "http://user:password@proxy:port/"; + # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain"; + + # Select internationalisation properties. + i18n.defaultLocale = "en_US.UTF-8"; + # console = { + # font = "Lat2-Terminus16"; + # keyMap = "us"; + # useXkbConfig = true; # use xkb.options in tty. + # }; + + + + + # Enable the X11 windowing system. + # services.xserver.enable = true; + + # Configure keymap in X11 + # services.xserver.xkb.layout = "us"; + # services.xserver.xkb.options = "eurosign:e,caps:escape"; + + # Enable CUPS to print documents. + # services.printing.enable = true; + + # Enable sound. + # hardware.pulseaudio.enable = true; + # OR + # services.pipewire = { + # enable = true; + # pulse.enable = true; + # }; + + # Enable touchpad support (enabled default in most desktopManager). + # services.libinput.enable = true; + + + + + # Define a user account. Don't forget to set a password with ‘passwd’. + users.users.tristan = { + isNormalUser = true; + extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user. + packages = with pkgs; [ + tree + ]; + }; + + + + + # programs.firefox.enable = true; + + + + + # List packages installed in system profile. To search, run: + # $ nix search wget + environment.systemPackages = with pkgs; [ + vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default. + wget + wireguard-tools + kakoune + git + gay + blahaj + ]; + + services.navidrome = { + enable = true; + settings = { + Address = "0.0.0.0"; + Port = 4533; + MusicFolder = "/srv/music"; + }; + }; + + nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ + "broadcom-sta" + ]; + # Some programs need SUID wrappers, can be configured further or are + # started in user sessions. + # programs.mtr.enable = true; + # programs.gnupg.agent = { + # enable = true; + # enableSSHSupport = true; + # }; + + # List services that you want to enable: + + # Enable the OpenSSH daemon. + services.openssh.enable = true; + services.openssh.settings.PermitRootLogin = "no"; + services.openssh.settings.PasswordAuthentication = true; + + + # Open ports in the firewall. + networking.firewall.allowedTCPPorts = [ + 22 + 4533 + ]; + networking.firewall.allowedUDPPorts = [ + 22 + 4533 + ]; + # Or disable the firewall altogether. + networking.firewall.enable = true; + + # Copy the NixOS configuration file and link it from the resulting system + # (/run/current-system/configuration.nix). This is useful in case you + # accidentally delete configuration.nix. + system.copySystemConfiguration = true; + + + + + # This option defines the first version of NixOS you have installed on this particular machine, + # and is used to maintain compatibility with application data (e.g. databases) created on older NixOS versions. + # + # Most users should NEVER change this value after the initial install, for any reason, + # even if you've upgraded your system to a new NixOS release. + # + # This value does NOT affect the Nixpkgs version your packages and OS are pulled from, + # so changing it will NOT upgrade your system - see https://nixos.org/manual/nixos/stable/#sec-upgrading for how + # to actually do that. + # + # This value being lower than the current NixOS release does NOT mean your system is + # out of date, out of support, or vulnerable. + # + # Do NOT change this value unless you have manually inspected all the changes it would make to your configuration, + # and migrated your data accordingly. + # + # For more information, see `man configuration.nix` or https://nixos.org/manual/nixos/stable/options#opt-system.stateVersion . + system.stateVersion = "24.11"; # Did you read the comment? + +} + diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..723de29 --- /dev/null +++ b/flake.nix @@ -0,0 +1,19 @@ +{ + description = "A very basic flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + }; + + outputs = { self, nixpkgs }: { + nixosConfigurations = { + mini = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + ./configuration.nix + ]; + }; + }; + + }; +} diff --git a/hardware-configuration.nix b/hardware-configuration.nix new file mode 100644 index 0000000..2f23b5b --- /dev/null +++ b/hardware-configuration.nix @@ -0,0 +1,41 @@ +# 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") + ]; + + boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "usb_storage" "usbhid" "sd_mod" "sdhci_pci" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-intel" "wl" ]; + boot.extraModulePackages = [ config.boot.kernelPackages.broadcom_sta ]; + + fileSystems."/" = + { device = "/dev/disk/by-uuid/85854283-7f0f-4b2e-b2fc-846954d28b35"; + fsType = "ext4"; + }; + + fileSystems."/boot" = + { device = "/dev/disk/by-uuid/1AFE-F75D"; + fsType = "vfat"; + options = [ "fmask=0077" "dmask=0077" ]; + }; + + swapDevices = + [ { device = "/dev/disk/by-uuid/b2437f9b-a84a-4f12-8db1-8064c9f7bab1"; } + ]; + + # Enables DHCP on each ethernet and wireless interface. In case of scripted networking + # (the default) this is the recommended approach. When using systemd-networkd it's + # still possible to use this option, but it's recommended to use it in conjunction + # with explicit per-interface declarations with `networking.interfaces..useDHCP`. + networking.useDHCP = lib.mkDefault true; + # networking.interfaces.enp0s20u2.useDHCP = lib.mkDefault true; + # networking.interfaces.enp3s0f0.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +} diff --git a/wireguard.nix b/wireguard.nix new file mode 100644 index 0000000..7044fab --- /dev/null +++ b/wireguard.nix @@ -0,0 +1,39 @@ +{ + # Enable WireGuard + networking.wireguard.enable = true; + networking.wireguard.interfaces = { + # "wg0" is the network interface name. You can name the interface arbitrarily. + tr = { + # Determines the IP address and subnet of the client's end of the tunnel interface. + ips = [ "10.0.1.2/24" ]; + #listenPort = 51821; # to match firewall allowedUDPPorts (without this wg uses random port numbers) + + # Path to the private key file. + # + # Note: The private key can also be included inline via the privateKey option, + # but this makes the private key world-readable; thus, using privateKeyFile is + # recommended. + privateKeyFile = "/root/wireguard-keys/private"; + + peers = [ + # For a client configuration, one peer entry for the server will suffice. + + { + # Public key of the server (not a file path). + publicKey = "TSPq7sJbY9DNhCu76sc0s9wtFnfHhk/ud0D/JiEPfV4="; + + # Forward all the traffic via VPN. + allowedIPs = [ "10.0.1.1" ]; + # Or forward only particular subnets + #allowedIPs = [ "10.100.0.1" "91.108.12.0/22" ]; + + # Set this to the server IP and port. + endpoint = "79.72.30.126:51821"; # ToDo: route to endpoint not automatically configured https://wiki.archlinux.org/index.php/WireGuard#Loop_routing https://discourse.nixos.org/t/solved-minimal-firewall-setup-for-wireguard-client/7577 + + # Send keepalives every 25 seconds. Important to keep NAT tables alive. + persistentKeepalive = 25; + } + ]; + }; + }; +}