From f77fc421dee47ddc45106891b155ebd1693fe9ba Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Thu, 30 May 2019 21:51:13 -0300 Subject: Format all Nix code with nixfmt --- nixos/configuration.nix | 637 +++++++++++++++++++-------------------- nixos/hardware-configuration.nix | 26 +- nixos/utils.nix | 118 ++++++++ nixos/velhinho.nix | 2 +- 4 files changed, 438 insertions(+), 345 deletions(-) create mode 100644 nixos/utils.nix (limited to 'nixos') diff --git a/nixos/configuration.nix b/nixos/configuration.nix index d6346a0..805413b 100644 --- a/nixos/configuration.nix +++ b/nixos/configuration.nix @@ -1,12 +1,10 @@ { config, pkgs, ... }: let localConfiguration = import /etc/nixos/local-configuration.nix; -in -{ - imports = - [ # Include the results of the hardware scan. - /etc/nixos/hardware-configuration.nix - ]; +in { + imports = [ # Include the results of the hardware scan. + /etc/nixos/hardware-configuration.nix + ]; # Use the systemd-boot EFI boot loader. boot = { @@ -15,13 +13,11 @@ in efi.canTouchEfiVariables = true; }; initrd = { - luks.devices = [ - { - name = "root"; - device = localConfiguration.luksDevice; - preLVM = true; - } - ]; + luks.devices = [{ + name = "root"; + device = localConfiguration.luksDevice; + preLVM = true; + }]; }; }; @@ -66,281 +62,268 @@ in freefont_ttf ]; - - environment.systemPackages = - let - # pkgsUnstable = import(fetchTarball https://github.com/NixOS/nixpkgs-channels/archive/nixos-unstable.tar.gz) {}; - # pkgs-18-03 = import(pkgs.fetchzip { - # url = "https://github.com/NixOS/nixpkgs/archive/18.03.zip"; - # sha256 = "0hk4y2vkgm1qadpsm4b0q1vxq889jhxzjx3ragybrlwwg54mzp4f"; - # }) {}; - - timidityWithEvenMoreFormats = with pkgs; timidity.overrideAttrs (oldAttrs: { - configureFlags = oldAttrs.configureFlags ++ [ "--enable-audio=vorbis,flac" ]; - buildInputs = oldAttrs.buildInputs ++ [ libogg libvorbis flac ]; - }); - - # See https://github.com/NixOS/nixpkgs/issues/53938#issuecomment-454158967 - untested-quodlibet-full = with pkgs; quodlibet-full.overrideAttrs (oldAttrs: { - doInstallCheck = false; - doCheck = false; - }); - - - nixfmt = import (builtins.fetchTarball "https://github.com/serokell/nixfmt/archive/master.tar.gz") { }; - - # https://github.com/nixos/nixpkgs/blob/0d202221f98e500f1df79112dc464d013eefcdae/pkgs/development/web/nodejs/v10.nix#L4 - in with pkgs; [ - nixfmt - - ## Personal data tools - - gitAndTools.git-open - gitAndTools.gitFull - gitAndTools.diff-so-fancy - gitAndTools.git-annex - gitAndTools.gitRemoteGcrypt - gitAndTools.git-dit - gitAndTools.git-secrets - git-crypt - git-lfs - gnupg - mr - nextcloud-client - owncloud-client - nextcloud-client - borgbackup - git-sizer - - - ## CLI tools - - bash - bash-completion - nix-bash-completions - youtube-dl - wget - vim - thefuck - tmux - tmuxinator - sox # =play= - gettext # =envsubst= - ag - gnugrep - ack - htop - rlwrap - awscli - jq - openvpn - xclip - bc # binary calculator used in nucli - sassc - watchman - ipfs - gnumake - gcc - psmisc # =killall= - xorg.xkill - autojump - bfg-repo-cleaner - pwgen - gksu # =gksudo= - gnome2.GConf # https://github.com/NixOS/nixpkgs/issues/15978 - lsof - pciutils - python27Packages.pywatchman # =watchman-wait= - libressl - tree - i2p - libxml2 # =xmllint= - unzip # used by extract bash function and Clojure go-to-source - odt2txt # used to diff odf files - feh # simplistic image viewer - nixUnstable # =nix= - zip - zlib - redis - alsaUtils # for xmonad volume commands - multimarkdown # =markdown= - pup # command-line HTML parsing https://github.com/ericchiang/pup - binutils-unwrapped # =ar= command for cargo build - nssTools # =pk12util= - gitAndTools.hub # GitHub helper - insomnia - bind # =dig= - file - gitlab-runner - sshpass - zathura # for viewing Emacs PDF files - nvi - cacert - gtypist - pandoc - inotify-tools - fzf - ncdu - fd - nnn - python36Packages.python-slugify - moreutils # =vipe= - bazel - graphviz # =dot= and others - mkpasswd - direnv - - diffoscope # - poppler_utils # used by diffoscope for comparing PDF files - pdftk # - - gnome3.libgnome-keyring - gnome3.gnome-keyring - - - ## Mail - - notmuch - isync - - - ## Spell checking - - (aspellWithDicts (ps : with ps; [ en eo fr pt_BR ])) - languagetool - - - ## NixOS - - pypi2nix - bundix - - - ## Music - - texlive.combined.scheme-full - lilypond - python36Packages.python-ly - lame - frescobaldi - timidityWithEvenMoreFormats - - - ## Programming tools - - sbcl - stack - leiningen - python3 - python - yarn - elixir - openjdk - solc - bundler - rustup - cargo - clojure # =clj= - visualvm # JVM profiling tool - ant - maven - go_bootstrap - rakudo - bats - ledger - newsboat - perl - dhall - dhall-json - nodePackages.node2nix - shellcheck - # (haskell.lib.justStaticExecutables haskellPackages.github-backup) - rustracer - xsel - nodejs-10_x - swift - - - ## Containers and VMs - - packer - docker_compose - docker-machine - vagrant - kubernetes - ansible - qemu - gnome3.gtk-vnc - nixops - terraform-full - - - ## xmonad - - xorg.xmodmap - trayer - dmenu - escrotum - xorg.xbacklight - networkmanagerapplet - playerctl - lightdm - fvwm # =xpmroot= - haskellPackages.xmobar - haskellPackages.yeganesh - arandr - - - ## GUI programs - - untested-quodlibet-full - inkscape - calibre - cozy - rhythmbox - gpodder - firefox - emacs - tdesktop - vlc - keepassx2-http - yubioath-desktop - # tor-browser-bundle-bin - transmission_gtk - libreoffice - android-studio - # androidsdk_extras - # androidndk - patchwork-classic - # gnome3.gpaste - - - ## Cryptocururencies - - electrum - zbar # for on-screen QR Code scanning - monero - - - ## nu specific packages - - sshuttle - slack - chromium - ]; + environment.systemPackages = let + # pkgsUnstable = import(fetchTarball https://github.com/NixOS/nixpkgs-channels/archive/nixos-unstable.tar.gz) {}; + # pkgs-18-03 = import(pkgs.fetchzip { + # url = "https://github.com/NixOS/nixpkgs/archive/18.03.zip"; + # sha256 = "0hk4y2vkgm1qadpsm4b0q1vxq889jhxzjx3ragybrlwwg54mzp4f"; + # }) {}; + + timidityWithEvenMoreFormats = with pkgs; + timidity.overrideAttrs (oldAttrs: { + configureFlags = oldAttrs.configureFlags + ++ [ "--enable-audio=vorbis,flac" ]; + buildInputs = oldAttrs.buildInputs ++ [ libogg libvorbis flac ]; + }); + + # See https://github.com/NixOS/nixpkgs/issues/53938#issuecomment-454158967 + untested-quodlibet-full = with pkgs; + quodlibet-full.overrideAttrs (oldAttrs: { + doInstallCheck = false; + doCheck = false; + }); + + nixfmt = import (builtins.fetchTarball + "https://github.com/serokell/nixfmt/archive/master.tar.gz") { }; + + # https://github.com/nixos/nixpkgs/blob/0d202221f98e500f1df79112dc464d013eefcdae/pkgs/development/web/nodejs/v10.nix#L4 + in with pkgs; [ + nixfmt + + ## Personal data tools + + gitAndTools.git-open + gitAndTools.gitFull + gitAndTools.diff-so-fancy + gitAndTools.git-annex + gitAndTools.gitRemoteGcrypt + gitAndTools.git-dit + gitAndTools.git-secrets + git-crypt + git-lfs + gnupg + mr + nextcloud-client + owncloud-client + nextcloud-client + borgbackup + git-sizer + + ## CLI tools + + bash + bash-completion + nix-bash-completions + youtube-dl + wget + vim + thefuck + tmux + tmuxinator + sox # =play= + gettext # =envsubst= + ag + gnugrep + ack + htop + rlwrap + awscli + jq + openvpn + xclip + bc # binary calculator used in nucli + sassc + watchman + ipfs + gnumake + gcc + psmisc # =killall= + xorg.xkill + autojump + bfg-repo-cleaner + pwgen + gksu # =gksudo= + gnome2.GConf # https://github.com/NixOS/nixpkgs/issues/15978 + lsof + pciutils + python27Packages.pywatchman # =watchman-wait= + libressl + tree + i2p + libxml2 # =xmllint= + unzip # used by extract bash function and Clojure go-to-source + odt2txt # used to diff odf files + feh # simplistic image viewer + nixUnstable # =nix= + zip + zlib + redis + alsaUtils # for xmonad volume commands + multimarkdown # =markdown= + pup # command-line HTML parsing https://github.com/ericchiang/pup + binutils-unwrapped # =ar= command for cargo build + nssTools # =pk12util= + gitAndTools.hub # GitHub helper + insomnia + bind # =dig= + file + gitlab-runner + sshpass + zathura # for viewing Emacs PDF files + nvi + cacert + gtypist + pandoc + inotify-tools + fzf + ncdu + fd + nnn + python36Packages.python-slugify + moreutils # =vipe= + bazel + graphviz # =dot= and others + mkpasswd + direnv + + diffoscope + poppler_utils # used by diffoscope for comparing PDF files + pdftk + + gnome3.libgnome-keyring + gnome3.gnome-keyring + + ## Mail + + notmuch + isync + + ## Spell checking + + (aspellWithDicts (ps: with ps; [ en eo fr pt_BR ])) + languagetool + + ## NixOS + + pypi2nix + bundix + + ## Music + + texlive.combined.scheme-full + lilypond + python36Packages.python-ly + lame + frescobaldi + timidityWithEvenMoreFormats + + ## Programming tools + + sbcl + stack + leiningen + python3 + python + yarn + elixir + openjdk + solc + bundler + rustup + cargo + clojure # =clj= + visualvm # JVM profiling tool + ant + maven + go_bootstrap + rakudo + bats + ledger + newsboat + perl + dhall + dhall-json + nodePackages.node2nix + shellcheck + # (haskell.lib.justStaticExecutables haskellPackages.github-backup) + rustracer + xsel + nodejs-10_x + swift + + ## Containers and VMs + + packer + docker_compose + docker-machine + vagrant + kubernetes + ansible + qemu + gnome3.gtk-vnc + nixops + terraform-full + + ## xmonad + + xorg.xmodmap + trayer + dmenu + escrotum + xorg.xbacklight + networkmanagerapplet + playerctl + lightdm + fvwm # =xpmroot= + haskellPackages.xmobar + haskellPackages.yeganesh + arandr + + ## GUI programs + + untested-quodlibet-full + inkscape + calibre + cozy + rhythmbox + gpodder + firefox + emacs + tdesktop + vlc + keepassx2-http + yubioath-desktop + # tor-browser-bundle-bin + transmission_gtk + libreoffice + android-studio + # androidsdk_extras + # androidndk + patchwork-classic + # gnome3.gpaste + + ## Cryptocururencies + + electrum + zbar # for on-screen QR Code scanning + monero + + ## nu specific packages + + sshuttle + slack + chromium + ]; nixpkgs.config = { android_sdk.accept_license = true; allowUnfree = true; # Require for slack (unfree) derivation }; - # Look at # https://www.vivaolinux.com.br/topico/Off-Code-Cafe/Me-apresente-sua-distro - programs = { - bash.enableCompletion = true; - }; + programs = { bash.enableCompletion = true; }; services = { cron.enable = true; @@ -390,14 +373,14 @@ in gnome-terminal-server.enable = true; # gpaste.enable = true; # clipboard manager tracker.enable = true; - sushi.enable = true; # nautilus previewer + sushi.enable = true; # nautilus previewer gnome-online-accounts.enable = true; gnome-documents.enable = true; evolution-data-server.enable = true; gvfs.enable = true; }; - pcscd.enable = true; # required by yubioath + pcscd.enable = true; # required by yubioath # Taken from: # https://unix.stackexchange.com/questions/378711/how-do-i-configure-postgress-authorization-settings-in-nixos @@ -430,62 +413,56 @@ in users = { mutableUsers = false; - extraUsers = - let - andrehUser = { - andreh = { - isNormalUser = true; - uid = 1000; - description = "EuAndreh"; - extraGroups = [ "wheel" "networkmanager" "docker" ]; - # Generated with: - # mkpasswd -m sha-512 > password-file.txt - passwordFile = localConfiguration.passwordFile; - }; + extraUsers = let + andrehUser = { + andreh = { + isNormalUser = true; + uid = 1000; + description = "EuAndreh"; + extraGroups = [ "wheel" "networkmanager" "docker" ]; + # Generated with: + # mkpasswd -m sha-512 > password-file.txt + passwordFile = localConfiguration.passwordFile; }; - # From the Guix manual: - # https://www.gnu.org/software/guix/manual/en/html_node/Build-Environment-Setup.html#Build-Environment-Setup - buildUser = (i: - { - "guixbuilder${i}" = { # guixbuilder$i - group = "guixbuild"; # -g guixbuild - extraGroups = ["guixbuild"]; # -G guixbuild - home = "/var/empty"; # -d /var/empty - shell = pkgs.nologin; # -s `which nologin` - description = "Guix build user ${i}"; # -c "Guix buid user $i" - isSystemUser = true; # --system - }; - } - ); - in - # merge all users - pkgs.lib.fold (str: acc: acc // buildUser str) - andrehUser - # for i in `seq -w 1 10` - (map (pkgs.lib.fixedWidthNumber 2) (builtins.genList (n: n+1) 10)); - - extraGroups.guixbuild = { - name = "guixbuild"; - }; + }; + # From the Guix manual: + # https://www.gnu.org/software/guix/manual/en/html_node/Build-Environment-Setup.html#Build-Environment-Setup + buildUser = (i: { + "guixbuilder${i}" = { # guixbuilder$i + group = "guixbuild"; # -g guixbuild + extraGroups = [ "guixbuild" ]; # -G guixbuild + home = "/var/empty"; # -d /var/empty + shell = pkgs.nologin; # -s `which nologin` + description = "Guix build user ${i}"; # -c "Guix buid user $i" + isSystemUser = true; # --system + }; + }); + # merge all users + in pkgs.lib.fold (str: acc: acc // buildUser str) andrehUser + # for i in `seq -w 1 10` + (map (pkgs.lib.fixedWidthNumber 2) (builtins.genList (n: n + 1) 10)); + + extraGroups.guixbuild = { name = "guixbuild"; }; }; systemd = { services = { # Derived from Guix guix-daemon.service.in # https://git.savannah.gnu.org/cgit/guix.git/tree/etc/guix-daemon.service.in?id=00c86a888488b16ce30634d3a3a9d871ed6734a2 - guix-daemon = { - enable = false; - description = "Build daemon for GNU Guix"; - serviceConfig = { - ExecStart = "/var/guix/profiles/per-user/root/guix-profile/bin/guix-daemon --build-users-group=guixbuild"; - Environment="GUIX_LOCPATH=/root/.guix-profile/lib/locale"; - RemainAfterExit="yes"; - StandardOutput="syslog"; - StandardError="syslog"; - TaskMax= "8192"; - }; - wantedBy = [ "multi-user.target" ]; - }; + guix-daemon = { + enable = false; + description = "Build daemon for GNU Guix"; + serviceConfig = { + ExecStart = + "/var/guix/profiles/per-user/root/guix-profile/bin/guix-daemon --build-users-group=guixbuild"; + Environment = "GUIX_LOCPATH=/root/.guix-profile/lib/locale"; + RemainAfterExit = "yes"; + StandardOutput = "syslog"; + StandardError = "syslog"; + TaskMax = "8192"; + }; + wantedBy = [ "multi-user.target" ]; + }; }; }; diff --git a/nixos/hardware-configuration.nix b/nixos/hardware-configuration.nix index 2670a09..a07470d 100644 --- a/nixos/hardware-configuration.nix +++ b/nixos/hardware-configuration.nix @@ -4,27 +4,25 @@ { config, lib, pkgs, ... }: { - imports = - [ - ]; + imports = [ ]; - boot.initrd.availableKernelModules = [ "ehci_pci" "ahci" "usb_storage" "sd_mod" "sr_mod" ]; + boot.initrd.availableKernelModules = + [ "ehci_pci" "ahci" "usb_storage" "sd_mod" "sr_mod" ]; boot.kernelModules = [ "kvm-intel" ]; boot.extraModulePackages = [ ]; - fileSystems."/" = - { device = "/dev/disk/by-uuid/337ad499-b479-4fe9-ad98-0a9b2b92f4e9"; - fsType = "ext4"; - }; + fileSystems."/" = { + device = "/dev/disk/by-uuid/337ad499-b479-4fe9-ad98-0a9b2b92f4e9"; + fsType = "ext4"; + }; - fileSystems."/boot" = - { device = "/dev/disk/by-uuid/0975-7A26"; - fsType = "vfat"; - }; + fileSystems."/boot" = { + device = "/dev/disk/by-uuid/0975-7A26"; + fsType = "vfat"; + }; swapDevices = - [ { device = "/dev/disk/by-uuid/c08158aa-677a-4984-83fe-c938edb7021e"; } - ]; + [{ device = "/dev/disk/by-uuid/c08158aa-677a-4984-83fe-c938edb7021e"; }]; nix.maxJobs = lib.mkDefault 4; powerManagement.cpuFreqGovernor = lib.mkDefault "powersave"; diff --git a/nixos/utils.nix b/nixos/utils.nix new file mode 100644 index 0000000..f809dd9 --- /dev/null +++ b/nixos/utils.nix @@ -0,0 +1,118 @@ +{ pkgs, rootSrc ? pkgs.nix-gitignore.gitignoreSource [ ] ./., baseName }: +let + nixfmt = import (builtins.fetchTarball + "https://github.com/serokell/nixfmt/archive/master.tar.gz") { }; + +in rec { + baseTask = pkgs.stdenv.mkDerivation { + name = "${baseName}-task"; + src = rootSrc; + buildInputs = [ ]; + phases = "unpackPhase buildPhase"; + buildPhase = '' + echo "ERROR: base task buildPhase not overriden." + exit 1 + ''; + }; + shellcheck = baseTask.overrideAttrs (baseAttrs: { + name = "${baseAttrs.name}-shellcheck"; + buildInputs = baseAttrs.buildInputs ++ [ pkgs.shellcheck ]; + buildPhase = '' + export SHELLCHECK_OPTS="-e SC1090 -e SC1091 -e SC2139" + ignored='(encrypted|os-installation.sh|notmuch-post.sh)' + find . -type f -name '*.sh' | grep -E -v $ignored | xargs shellcheck + touch $out + ''; + }); + formatNix = baseTask.overrideAttrs (baseAttrs: { + name = "${baseAttrs.name}-nixfmt"; + buildInputs = baseAttrs.buildInputs ++ [ nixfmt ]; + buildPhase = '' + format() { + nix_file="$1" + diff <(nixfmt < "$nix_file") "$nix_file" || { + echo "The $nix_file is unformatted. To fix it, run:" + echo " nixfmt $nix_file" + exit 1 + } + } + export -f format + find . -type f -name '*.nix' -print0 | xargs -0 -I{} bash -c "format {}" \; + touch $out + ''; + }); + + fixme = baseTask.overrideAttrs (baseAttrs: { + name = "${baseAttrs.name}-fixme"; + buildInputs = baseAttrs.buildInputs ++ [ pkgs.ag ]; + buildPhase = '' + ag FIXME --ignore default.nix || { + touch $out + exit 0 + } + echo "^^^^^^^^^^^^^^^^^" + echo " Found dangling FIXME markers on the project xp" + exit 1 + ''; + }); + + test = testDerivations: + baseTask.overrideAttrs (baseAttrs: { + + name = "${baseAttrs.name}-test"; + buildPhase = '' + echo "Ran tests for:" + for d in ${builtins.toString testDerivations}; do + echo " $d" + done + echo "All tests passed!" + touch $out + ''; + }); +} + +# subtasks = rec { +# shellcheck = baseTask.overrideAttrs(baseAttrs: { +# name = "${baseAttrs.name}-shellcheck"; +# buildInputs = baseAttrs.buildInputs ++ [ pkgs.shellcheck ]; +# buildPhase = '' +# export SHELLCHECK_OPTS="-e SC1090 -e SC1091 -e SC2139" +# ignored='(encrypted|os-installation.sh|notmuch-post.sh)' +# find . -type f -name '*.sh' | grep -E -v $ignored | xargs shellcheck +# touch $out +# ''; +# }); +# fixme = baseTask.overrideAttrs(baseAttrs: { +# name = "${baseAttrs.name}-fixme"; +# buildInputs = baseAttrs.buildInputs ++ [ ag ]; +# buildPhase = '' +# ag FIXME --ignore default.nix || { +# touch $out +# } +# ''; +# }); +# uniqueFeeds = baseTask.overrideAttrs (baseAttrs: { +# name = "${baseAttrs.name}-unique-feeds"; +# buildPhase = '' +# OUT="$(uniq -D <(sort ./newsboat/urls))" +# [[ $OUT = "" ]] || { +# echo "Duplicate subscriptions found in ./newsboat/urls:" +# echo "$OUT" +# exit 1 +# } +# touch $out +# ''; +# }); +# formatNix = baseTask.overrideAttrs (baseAttrs: { +# name = "${baseAttrs.name}-nixfmt"; +# buildInputs = baseAttrs.buildInputs ++ [nixfmt]; +# buildPhase = '' +# diff <(nixfmt < default.nix) default.nix || { +# echo "The default.nix is unformatted. To fix it, run:" +# echo " nixfmt default.nix" +# exit 1 +# } +# touch $out +# ''; +# }); +# }; diff --git a/nixos/velhinho.nix b/nixos/velhinho.nix index f2f270f..3de1d77 100644 --- a/nixos/velhinho.nix +++ b/nixos/velhinho.nix @@ -1,5 +1,5 @@ { hostName = "velhinho-nixos"; luksDevice = "/dev/sda3"; - passwordFile = "/home/andreh/dev/libre/dotfiles/encrypted/password-hash.txt"; + passwordFile = "/home/andreh/dev/libre/dotfiles/encrypted/password-hash.txt"; } -- cgit v1.2.3