diff --git a/custom/default.nix b/custom/default.nix index 54879c0..cae8643 100644 --- a/custom/default.nix +++ b/custom/default.nix @@ -7,9 +7,8 @@ let # url = "https://github.com/nixos/nixpkgs/archive/9b7fb215d4d8399772a4f3d6f00fab3747136f53.tar.gz"; # sha256 = "02d1841j7jg161q7cwh7vryxhv7x3bmnhd1jczx14ggfa66vqfhm"; # }) { inherit system; }; - callPackage = pkgs.lib.callPackageWith ( pkgs // self ); + callPackage = pkgs.lib.callPackageWith (pkgs // self); self = { gallery-tagger = callPackage ./gallery-tagger {}; }; -in self - +in(self) diff --git a/extralib.nix b/extralib.nix deleted file mode 100644 index ddfc75e..0000000 --- a/extralib.nix +++ /dev/null @@ -1,98 +0,0 @@ -{ lib ? (import {}).lib, ... }: -with lib; -with builtins; -{ - lib = { - floats = rec { - _floatComponents = f: lib.strings.splitString "." (toString f); - - ceil = f: - let - comp = _floatComponents f; - int = strings.toInt (head comp); - inc = if match "[1-9][[:digit:]]*" (head (tail comp)) != null then 1 else 0; - in - assert(isFloat f); - int + inc; - - floor = f: - let - int = strings.toInt (head (_floatComponents f)); - in - assert(isFloat f); - int; - - toInt = f: - let - comp = _floatComponents f; - int = strings.toInt (head comp); - inc = if match "[5-9][[:digit:]]*" (head (tail comp)) != null then 1 else 0; - in - assert(isFloat f); - int + inc; - }; - - hex = rec { - parseDigit = c: - let - v = strings.toUpper c; - in - assert(match "[0-9A-F]" c != null); - { - "0" = 0; - "1" = 1; - "2" = 2; - "3" = 3; - "4" = 4; - "5" = 5; - "6" = 6; - "7" = 7; - "8" = 8; - "9" = 9; - "A" = 10; - "B" = 11; - "C" = 12; - "D" = 13; - "E" = 14; - "F" = 15; - }."${v}"; - - toDec = s: - let characters = stringToCharacters s; - values = map parseDigit characters; - value = foldl (acc: n: acc * 16 + n) 0 values; - in value; - - fromDec = trivial.toHexString; - - }; - - # colors = rec { - - - - # colorFromHex = s: - # let rgba = match "#([[:xdigit:]]{2})([[:xdigit:]]{2})([[:xdigit:]]{2})([[:xdigit:]]{2})" s; - # rgb = match "#([[:xdigit:]]{2})([[:xdigit:]]{2})([[:xdigit:]]{2})" s; - # values = map hexToDec (if isNull rgb then rgba else rgb ++ [ "FF" ]); - # in { - # r = (head values) / 255.0; - # g = (head (tail values)) / 255.0; - # b = (head (drop 2 values)) / 255.0; - # a = (last values) / 255.0; - # }; - - # red = { r = 255.0; g = 0.0; b = 0.0; }; - # green = { r = 0.0; g = 255.0; b = 0.0; }; - # blue = { r = 0.0; g = 0.0; b = 255.0; }; - - # toRGBHex = { r, g, b, ... }: - # ''#${concatMapStrings (v: fixedWidthString 2 "0" (toHexString (v * 255))) [ r g b ]}''; - # toRGBAHex = { r, g, b, a }: - # ''#${concatMapStrings (v: fixedWidthString 2 "0" (toHexString v)) [ r g b a ]}''; - - # toRgbHex = c: strings.toLower (toRGBHex c); - # toRgbaHex = c: strings.toLower (toRGBAHex c); - # }; - }; -} diff --git a/home.nix b/home.nix index 15b45da..d9f0b5b 100644 --- a/home.nix +++ b/home.nix @@ -2,9 +2,7 @@ let callPackage = pkgs.lib.callPackageWith pkgs; - custom = import ./custom/default.nix {}; nord = import ./configs/themes/nord.nix; - extra = callPackage ./extra/default.nix {}; in { fonts.fontconfig = { @@ -12,12 +10,13 @@ in }; nixpkgs.overlays = [ - (final: prev: { extra = (prev.lib.callPackageWith prev) ./extra/default.nix {}; }) + (final: prev: { extra = (prev.lib.callPackageWith prev) ./extra/default.nix {}; }) # Custom library + (final: prev: (prev.lib.callPackageWith prev) ./custom/default.nix {}) # Custom packges ( final: prev: { extra = prev.extra // { colorTheme = import ./configs/themes/nord.nix; - colorPalette = with extra; palette.palette { + colorPalette = with pkgs.extra; palette.palette { black = color.hexToRgba nord.n0; red = color.hexToRgba nord.n11; green = color.hexToRgba nord.n14; @@ -40,7 +39,7 @@ in language.base = "it_IT.UTF-8"; keyboard.layout = "it"; keyboard.options = [ "terminate:ctrl_alt_bksp" "compose:rctrl" ]; - packages = ( + packages = with pkgs; [ audacity authy @@ -49,6 +48,7 @@ in evolution firefox gallery-dl + gallery-tagger gnome3.dconf-editor gnome3.easytag gnome3.eog @@ -65,7 +65,6 @@ in google-chrome htop jetbrains.datagrip - keepassxc krita libreoffice-fresh lutris @@ -79,7 +78,6 @@ in pavucontrol pcmanfm pentablet-driver - # polybarFull procps-ng shotwell skypeforlinux @@ -91,12 +89,7 @@ in wireguard zoom-us zotero - ] - ) ++ ( - with custom; [ - gallery-tagger - ] - ); + ]; }; programs.zsh.enable = true; @@ -120,6 +113,7 @@ in ./modules/info.nix ./modules/jq.nix ./modules/kakoune.nix + ./modules/keepassxc.nix ./modules/keychain.nix # ./modules/kitty.nix ./modules/lf.nix @@ -161,8 +155,9 @@ in caffeine.enable = true; cbatticon.enable = true; gnome-keyring.enable = true; - playerctld.enable = true; network-manager-applet.enable = true; + playerctld.enable = true; + # poweralertd.enable = true; }; xsession.numlock.enable = true; } diff --git a/modules/kakoune.nix b/modules/kakoune.nix index 276e979..e9dd4d9 100644 --- a/modules/kakoune.nix +++ b/modules/kakoune.nix @@ -8,7 +8,9 @@ let cargo-watch clippy rust-analyzer - rustup + ]; + cppPlugins = with pkgs; [ + clang-tools ]; pythonPlugins = with pkgs.python38Packages; [ pyls-black @@ -79,8 +81,6 @@ in ]; hooks = [ { name = "BufCreate"; option = ".*"; commands = "editorconfig-load"; } - { name = "InsertCompletionHide"; option = ".*"; commands = builtins.concatStringsSep "\n" [ "unmap window insert " "unmap window insert " ]; } - { name = "InsertCompletionShow"; option = ".*"; commands = builtins.concatStringsSep "\n" [ "map window insert " "map window insert " ]; } { name = "ModuleLoaded"; option = "auto-pairs"; commands = "auto-pairs-enable"; } { name = "ModuleLoaded"; option = "powerline"; commands = builtins.concatStringsSep "\n" [ "powerline-enable" ]; } { name = "WinSetOption"; option = "filetype=(rust|python|c|cpp|latex|javascript|go|nix)"; commands = builtins.concatStringsSep "\n" [ "lsp-enable-window" ]; } @@ -113,7 +113,7 @@ in with nixpkgs; [ kakounePlugins.connect-kak ] - ) ++ rustPlugins ++ pythonPlugins ++ nixPlugins ++ spellingPlugins ++ dataFormats; + ) ++ rustPlugins ++ cppPlugins ++ pythonPlugins ++ nixPlugins ++ spellingPlugins ++ dataFormats; }; xdg.configFile."kak-lsp/kak-lsp.toml".source = ../configs/kak-lsp/kak-lsp.toml; diff --git a/modules/keepassxc.nix b/modules/keepassxc.nix new file mode 100644 index 0000000..5feaa95 --- /dev/null +++ b/modules/keepassxc.nix @@ -0,0 +1,13 @@ +{ config, pkgs, ... }: +{ + config.systemd.user.services.keepassxc = { + Unit = { + Description = "KeePassXC password manager"; + After = [ "graphical-session-pre.target" ]; + Partof = [ "graphical-session.target" ]; + }; + + Install = { WantedBy = [ "graphical-session.target" ]; }; + + Service = { ExecStart = "${pkgs.keepassxc}/bin/keepassxc"; }; + };} diff --git a/modules/polybar.nix b/modules/polybar.nix index aed06f5..3364800 100644 --- a/modules/polybar.nix +++ b/modules/polybar.nix @@ -119,12 +119,15 @@ in format = { charging = colors.selected // { + padding = 1; text = " "; }; discharging = colors.active // { + padding = 1; text = " "; }; full = colors.normal // { + padding = 1; text = " "; }; }; @@ -278,13 +281,17 @@ in menu = [ [ ({ text = "Reboot"; exec = "menu-open-1"; }) - ({ text = "Power off"; exec = "menu-open-2"; }) + ({ text = "Hibernate"; exec = "menu-open-2"; }) + ({ text = "Power off"; exec = "menu-open-3"; }) ] [ - ({ text = "Reboot"; exec = "reboot"; }) + ({ text = "Reboot"; exec = "systemctl reboot"; }) ] [ - ({ text = "Power off"; exec = "poweroff"; }) + ({ text = "Hibernate"; exec = "systemctl hibernate"; }) + ] + [ + ({ text = "Power off"; exec = "systemctl poweroff"; }) ] ]; }; diff --git a/modules/update_background.nix b/modules/update_background.nix index 35cc8b8..fe15dbe 100644 --- a/modules/update_background.nix +++ b/modules/update_background.nix @@ -1,9 +1,10 @@ { pkgs, config, ... }: let fehCmd = "${pkgs.feh}/bin/feh"; - backgrounds_directory = ~/Immagini/Sfondi ; - update_time = 10; -in { + backgrounds_directory = ~/Immagini/Sfondi; + update_time = "10m"; +in +{ home.file.".local/bin/update_background.sh" = { text = '' #!${pkgs.bash}/bin/bash @@ -16,8 +17,8 @@ in { systemd.user.services."update-background" = { Unit = { - Description = "Update the desktop background"; - After = [ "graphical-session.target" ]; + Description = "Set random desktop background using feh"; + After = [ "graphical-session.pre.target" ]; PartOf = [ "graphical-session.target" ]; RequiresMountsFor = [ "/home/bertof/Immagini" ]; }; @@ -25,21 +26,15 @@ in { WantedBy = [ "graphical-session.target" ]; }; Service = { + Type = "oneshot"; + IOSchedulingClass = "idle"; ExecStart = "${config.home.homeDirectory}/${config.home.file.".local/bin/update_background.sh".target}"; }; }; systemd.user.timers."update-background" = { - Unit = { - Description="Run update-background every ${toString update_time} minutes"; - PartOf = [ "graphical-session.target" ]; - After = [ "graphical-session.target" ]; - }; - Timer = { - OnUnitActiveSec="${toString update_time}m"; - }; - Install = { - WantedBy = [ "graphical-session.target" ]; - }; + Unit = { Description = "Set random desktop background using feh"; }; + Timer = { OnUnitActiveSec = update_time; }; + Install = { WantedBy = [ "timers.target" ]; }; }; } diff --git a/nixos/base.nix b/nixos/base.nix new file mode 100644 index 0000000..38d33f6 --- /dev/null +++ b/nixos/base.nix @@ -0,0 +1,188 @@ +{}: + +{ + + + imports = + [ + # Include the results of the hardware scan. + /etc/nixos/hardware-configuration.nix + ./laptop.nix + ./pentablet.nix + ]; + + # Use the systemd-boot EFI boot loader. + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + + # # Cross-build arm + boot.binfmt.emulatedSystems = [ "armv7l-linux" "aarch64-linux" ]; + + # Use same ACPI identifier as Dell Ubuntu + boot.kernelParams = [ + "acpi_osi=Linux-Dell-Video" + ]; + + networking = { + hostName = "odin"; + networkmanager.enable = true; + + # The global useDHCP flag is deprecated, therefore explicitly set to false here. + # Per-interface useDHCP will be mandatory in the future, so this generated config + # replicates the default behaviour. + useDHCP = false; + interfaces = { + enp60s0.useDHCP = true; + wlp0s20f3.useDHCP = true; + virbr0.useDHCP = true; + }; + + # Configure network proxy if necessary + # proxy.default = "http://user:password@proxy:port/"; + # proxy.noProxy = "127.0.0.1,localhost,internal.domain"; + + # Open ports in the firewall. + # firewall.allowedTCPPorts = [ ... ]; + # firewall.allowedUDPPorts = [ ... ]; + # Or disable the firewall altogether. + # firewall.enable = false; + }; + + + # Set your time zone. + time.timeZone = "Europe/Rome"; + + # Select internationalisation properties. + i18n.defaultLocale = "it_IT.UTF-8"; + console = { + font = "Lat2-Terminus16"; + keyMap = "it"; + }; + + # Enable the X11 windowing system. + services.xserver.enable = true; + + # Enable the GNOME 3 Desktop Environment. + # services.xserver.displayManager.gdm = { + # enable = true; + # wayland = true; + # nvidiaWayland = true; + # }; + services.xserver.desktopManager.gnome.enable = true; + services.xserver.displayManager.sddm.autoNumlock = true; + services.xserver.displayManager.sddm.enable = true; + services.xserver.windowManager.bspwm.enable = true; + + # Configure keymap in X11 + services.xserver.layout = "it"; + services.xserver.xkbOptions = "eurosign:e;"; + + # Enable CUPS to print documents. + services.printing.enable = true; + + # Enable sound. + sound.enable = true; + hardware.pulseaudio.enable = true; + # services.pipewire = { + # enable = true; + # pulse.enable = true; + # jack.enable = true; + # alsa = { + # enable = true; + # support32Bit = true; + # }; + # }; + + # Enable touchpad support (enabled default in most desktopManager). + services.xserver.libinput.enable = true; + + # Define a user account. Don't forget to set a password with ‘passwd’. + users.users.bertof = { + isNormalUser = true; + extraGroups = [ "wheel" "input" ]; # Enable ‘sudo’ for the user. + shell = pkgs.zsh; + }; + + # List packages installed in system profile. To search, run: + # $ nix search wget + environment.systemPackages = with pkgs; [ + tmux + firefox + kakoune + vim + ]; + + # 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; + }; + + programs.steam.enable = true; + programs.dconf.enable = true; + programs.zsh = { + enable = true; + syntaxHighlighting.enable = true; + }; + + # List services that you want to enable: + + # Enable the OpenSSH daemon. + services.openssh.enable = true; + + # Cooling management + services.thermald.enable = true; + + services.snapper = { + configs = let + bertofExtraConfig = '' + ALLOW_USERS="bertof" + TIMELINE_CREATE=yes + TIMELINE_CLEANUP=yes + ''; + in + { + bertof_home = { subvolume = "/home/bertof"; extraConfig = bertofExtraConfig; }; + bertof_images = { subvolume = "/home/bertof/Immagini"; extraConfig = bertofExtraConfig; }; + bertof_music = { subvolume = "/home/bertof/Musica"; extraConfig = bertofExtraConfig; }; + bertof_videos = { subvolume = "/home/bertof/Video"; extraConfig = bertofExtraConfig; }; + bertof_hdd_games = { subvolume = "/home/bertof/Giochi/HDD"; extraConfig = bertofExtraConfig; }; + bertof_ssd_games = { subvolume = "/home/bertof/Giochi/SSD"; extraConfig = bertofExtraConfig; }; + }; + }; + + services.dbus.packages = with pkgs; [ gnome.dconf ]; + services.gnome.gnome-keyring.enable = true; + hardware.bluetooth.enable = true; + services.blueman.enable = true; + services.zerotierone = { enable = true; joinNetworks = [ "8056c2e21cf9c753" ]; }; + services.gvfs.enable = true; + services.tlp.enable = false; + + # Clamav + services.clamav = { daemon.enable = true; updater.enable = true; }; + + # Virtualisation + virtualisation = { kvmgt.enable = true; libvirtd.enable = true; }; + + # Allow completion for system packages + environment.pathsToLink = [ "/share/zsh" ]; + + security.sudo.extraConfig = '' + Defaults pwfeedback + ''; + + # Allow non free packages + nixpkgs.config.allowUnfree = 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 = "21.05"; # Did you read the comment? + +} diff --git a/nixos/intel.nix b/nixos/intel.nix new file mode 100644 index 0000000..d9d66d9 --- /dev/null +++ b/nixos/intel.nix @@ -0,0 +1,19 @@ +# Edit this configuration file to define what should be installed on +# your system. Help is available in the configuration.nix(5) man page +# and in the NixOS manual (accessible by running ‘nixos-help’). + +{ config, pkgs, ... }: + +{ + imports = [ + + ./base.nix + ]; + + # This runs only Intel and nvidia does not drain power. + ##### disable nvidia for a very nice battery life. + hardware.nvidiaOptimus.disable = true; + boot.blacklistedKernelModules = [ "nouveau" "nvidia" ]; + services.xserver.videoDrivers = [ "intel" ]; + hardware.opengl.driSupport32Bit = true; +} diff --git a/nixos/laptop.nix b/nixos/laptop.nix new file mode 100644 index 0000000..98b5971 --- /dev/null +++ b/nixos/laptop.nix @@ -0,0 +1,27 @@ +{ config, lib, ... }: +{ + # SSD swappines + boot.kernel.sysctl = { + "vm.swappiness" = lib.mkDefault 1; + }; + + # Atheros WiFi module + boot.blacklistedKernelModules = lib.optionals (!config.hardware.enableRedistributableFirmware) [ + "ath3k" + ]; + + # ACPI support + boot = { + kernelModules = [ "acpi_call" ]; + extraModulePackages = with config.boot.kernelPackages; [ acpi_call ]; + }; + + # Touchpad support + services.xserver.libinput.enable = lib.mkDefault true; + + # SSD trim service + services.fstrim.enable = lib.mkDefault true; + + # Hard disk protection if the laptop falls: + services.hdapsd.enable = lib.mkDefault true; +} diff --git a/nixos/nvidia.nix b/nixos/nvidia.nix new file mode 100644 index 0000000..b7339f0 --- /dev/null +++ b/nixos/nvidia.nix @@ -0,0 +1,24 @@ +# Edit this configuration file to define what should be installed on +# your system. Help is available in the configuration.nix(5) man page +# and in the NixOS manual (accessible by running ‘nixos-help’). + +{ config, pkgs, ... }: + +{ + imports = + [ + + ./base.nix + ]; + + services.xserver.videoDrivers = [ "nvidia" ]; + hardware.nvidia.prime = { + offload.enable = false; + sync.enable = true; + intelBusId = "PCI:0:2:0"; + nvidiaBusId = "PCI:1:0:0"; + }; + # hardware.nvidia.modesetting.enable = true; + # hardware.nvidia.package = pkgs.linuxPackages.nvidia_x11; + hardware.opengl.driSupport32Bit = true; +} diff --git a/nixos/pentablet.nix b/nixos/pentablet.nix new file mode 100644 index 0000000..98e2995 --- /dev/null +++ b/nixos/pentablet.nix @@ -0,0 +1,11 @@ +{ config, lib, pkgs, modulesPath, ...}: +{ + # udev rules + services.udev.extraRules = '' + KERNEL=="uinput",MODE:="0666",OPTIONS+="static_node=uinput" + SUBSYSTEMS=="usb",ATTRS{idVendor}=="28bd",MODE:="0666" + ''; + + # XP-Pen tablet driver + environment.systemPackages = [ pkgs.pentablet-driver ]; +} diff --git a/update-intel.sh b/update-intel.sh new file mode 100755 index 0000000..e347684 --- /dev/null +++ b/update-intel.sh @@ -0,0 +1,3 @@ +#!/bin/sh +sudo nix-channel --update && +sudo nixos-rebuild switch -p Intel -I ./nixos/intel.nix diff --git a/update-nvidia.sh b/update-nvidia.sh new file mode 100755 index 0000000..5b8d0df --- /dev/null +++ b/update-nvidia.sh @@ -0,0 +1,4 @@ +#!/bin/sh +sudo nix-channel --update && +sudo nixos-rebuild switch -p Nvidia -I ./nixos/nvidia.nix && +sudo nixos-rebuild switch -I ./nixos/nvidia.nix diff --git a/update-user.sh b/update-user.sh new file mode 100755 index 0000000..434133c --- /dev/null +++ b/update-user.sh @@ -0,0 +1,3 @@ +#!/bin/sh +nix-channel --update +home-manager switch