diff --git a/Makefile b/Makefile index 8dec3b59..67a4d39a 100755 --- a/Makefile +++ b/Makefile @@ -3,21 +3,18 @@ HOST := zilch HOME := /home/$(USER) DOTS := /etc/dotfiles -NIXOS_VERSION := 20.09 -NIXOS_PREFIX := $(PREFIX)/etc/nixos -FLAGS := -I "config=$$(pwd)/config" \ +NIXOS_VERSION := 20.09 +NIXOS_PREFIX := $(PREFIX)/etc/nixos +FLAGS := -I "config=$$(pwd)/config" \ -I "modules=$$(pwd)/modules" \ -I "bin=$$(pwd)/bin" \ $(FLAGS) -config: $(NIXOS_PREFIX)/configuration.nix -home: $(HOME)/dotfiles - # The channels will be used on certain modules like in `packages/default.nix` where it will be referred to install certain packages from the unstable channel. channels: @sudo nix-channel --add "https://nixos.org/channels/nixos-unstable" nixos @sudo nix-channel --add "https://github.com/rycee/home-manager/archive/master.tar.gz" home-manager - @sudo nix-channel --add "https://nixos.org/channels/nixpkgs-unstable" nixpkgs-unstable + @sudo nix-channel --add "https://nixos.org/channels/nixpkgs-unstable" nixpkgs update: @sudo nix-channel --update @@ -29,11 +26,13 @@ switch: boot: @sudo nixos-rebuild $(FLAGS) boot +# A little bootstrapping script. install: channels update @sudo nixos-generate-config --root "$(PREFIX)" - @echo "import \"$(DOTS)\" \"$(HOST)\" \"$${USER}\"" | sudo tee "${NIXOS_PREFIX}/configuration.nix" + @echo "import \"$$(pwd)\" \"$(HOST)\" \"$${USER}\"" | sudo tee "${NIXOS_PREFIX}/configuration.nix" @sudo nixos-install --root "$(PREFIX)" $(FLAGS) - @sudo cp -r "$(DOTS)" "$(PREFIX)/etc/dotfiles" + @sudo cp -r "$(DOTS)" "$(PREFIX)/$(DOTS)" + @echo "import \"$(DOTS)\" \"$(HOST)\" \"$${USER}\"" | sudo tee "${NIXOS_PREFIX}/configuration.nix" @sudo nixos-enter --root "$(PREFIX)" --command "chown $(USER):users $(DOTS) --recursive" @sudo nixos-enter --root "$(PREFIX)" --command "make -C $(DOTS) channels" @echo "Set password for $(USER)" && sudo nixos-enter --root "$(PREFIX)" --command "passwd $(USER)" @@ -44,7 +43,7 @@ clean: upgrade: update switch rollback: - @sudo nix-env --rollback + @sudo nixos-rebuild switch $(FLAGS) --rollback test: @nixos-rebuild $(FLAGS) test diff --git a/README.adoc b/README.adoc index f2ea2477..4a9c8d63 100755 --- a/README.adoc +++ b/README.adoc @@ -15,8 +15,8 @@ You can replace your NixOS configuration with this bad boi. To install, you have to do the following first: - Set up your partitions. -- Copy this setup (either with `git` or what-have-you) to `/etc/dotfiles`. -- Install GNU Make. +- Copy this setup (either with `git` or what-have-you) in whatever location you prefer. +- Install GNU Make (i.e., `nix-env -i gnumake`). Then simply run `make install`. It is equivalent to the following command: @@ -67,6 +67,7 @@ The project structure should look like the following: nixos-config ├── config/ ├── hosts/ +├── lib/ ├── modules/ ├── packages/ ├── templates/ @@ -92,6 +93,8 @@ In this case, it is my https://github.com/foo-dogsquared/dotflies[dotfiles] dire It is also used on the installation phase (from `make install`) by setting the `HOST` variable (i.e., `HOST=zilch make -C /etc/install`) with the folder name as the argument. See the <> section for more details. +* A little library in link:./lib[`./lib`] based from https://github.com/hlissner/dotfiles[original source] which being used for various uses (e.g., limiting certain modules). + * Though my custom packages are now placed in my https://github.com/foo-dogsquared/nur-packages[NUR repo], the `packages/` folder still exists here intended for "private" packages. Also contains third-party package repositories and overlays such as the https://github.com/nix-community/NUR[NUR], https://github.com/nix-community/emacs-overlay[unstable branch of Emacs], or the unstable branch of https://github.com/NixOS/nixpkgs/[nixpkgs]. See the <> section for more information. diff --git a/default.nix b/default.nix index 97ab37d3..cda67f21 100755 --- a/default.nix +++ b/default.nix @@ -5,6 +5,7 @@ # # This is ground zero, where the absolute essentials go, to be present on all systems I use nixos on. # Contains cluser-wide configurations shared between all of the systems (located in `hosts/`). +# TODO: Convert into a flake-based configuration so it'll make my life easier. device: username: { pkgs, options, lib, config, ... }: diff --git a/hosts/zilch/config/unison/default.prf b/hosts/zilch/config/unison/default.prf index 11a5ae07..0121dfb3 100755 --- a/hosts/zilch/config/unison/default.prf +++ b/hosts/zilch/config/unison/default.prf @@ -13,6 +13,9 @@ path = .password-store # My SSH keys path = .ssh +# My Cachix signing key +path = .config/cachix + # Some regexps specifying names and paths to ignore ignore = Name temp.* ignore = Name *~ diff --git a/hosts/zilch/default.nix b/hosts/zilch/default.nix index 95741b02..3300f861 100755 --- a/hosts/zilch/default.nix +++ b/hosts/zilch/default.nix @@ -3,6 +3,18 @@ { config, pkgs, lib, ... }: { + nixpkgs.config.permittedInsecurePackages = [ + "spidermonkey-38.8.0" + ]; + + # Set the Nix package manager to use the unstable version for flakes. + nix = { + package = pkgs.nixUnstable; + extraOptions = '' + experimental-features = nix-command flakes + ''; + }; + # Use the systemd-boot EFI boot loader. boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; diff --git a/lib/attrs.nix b/lib/attrs.nix new file mode 100755 index 00000000..0f8ebd19 --- /dev/null +++ b/lib/attrs.nix @@ -0,0 +1,26 @@ +{ lib, ... }: + +with builtins; +with lib; +rec { + # attrsToList + attrsToList = attrs: + mapAttrsToList (name: value: { inherit name value; }) attrs; + + # mapFilterAttrs :: + # (name -> value -> bool) + # (name -> value -> { name = any; value = any; }) + # attrs + mapFilterAttrs = pred: f: attrs: filterAttrs pred (mapAttrs' f attrs); + + # Generate an attribute set by mapping a function over a list of values. + genAttrs' = values: f: listToAttrs (map f values); + + # anyAttrs :: (name -> value -> bool) attrs + anyAttrs = pred: attrs: + any (attr: pred attr.name attr.value) (attrsToList attrs); + + # countAttrs :: (name -> value -> bool) attrs + countAttrs = pred: attrs: + count (attr: pred attr.name attr.value) (attrsToList attrs); +} diff --git a/lib/default.nix b/lib/default.nix new file mode 100755 index 00000000..d74386d8 --- /dev/null +++ b/lib/default.nix @@ -0,0 +1,18 @@ +{ lib, pkgs, ... }: + +let + inherit (lib) makeExtensible attrValues foldr; + inherit (modules) mapModules; + + modules = import ./modules.nix { + inherit lib; + self.attrs = import ./attrs.nix { inherit lib; self = {}; }; + }; + + mylib = makeExtensible (self: + with self; mapModules (toString ./.) + (file: import file { inherit self lib pkgs; })); +in +mylib.extend + (self: super: + foldr (a: b: a // b) {} (attrValues super)) diff --git a/lib/modules.nix b/lib/modules.nix new file mode 100755 index 00000000..47743f12 --- /dev/null +++ b/lib/modules.nix @@ -0,0 +1,53 @@ +{ self, lib, ... }: + +let + inherit (builtins) attrValues readDir pathExists concatLists; + inherit (lib) id mapAttrsToList filterAttrs hasPrefix hasSuffix nameValuePair removeSuffix; + inherit (self.attrs) mapFilterAttrs; +in +rec { + mapModules = dir: fn: + mapFilterAttrs + (n: v: + v != null && + !(hasPrefix "_" n)) + (n: v: + let path = "${toString dir}/${n}"; in + if v == "directory" && pathExists "${path}/default.nix" + then nameValuePair n (fn path) + else if v == "regular" && + n != "default.nix" && + hasSuffix ".nix" n + then nameValuePair (removeSuffix ".nix" n) (fn path) + else nameValuePair "" null) + (readDir dir); + + mapModules' = dir: fn: + attrValues (mapModules dir fn); + + mapModulesRec = dir: fn: + mapFilterAttrs + (n: v: + v != null && + !(hasPrefix "_" n)) + (n: v: + let path = "${toString dir}/${n}"; in + if v == "directory" + then nameValuePair n (mapModulesRec path fn) + else if v == "regular" && n != "default.nix" && hasSuffix ".nix" n + then nameValuePair (removeSuffix ".nix" n) (fn path) + else nameValuePair "" null) + (readDir dir); + + mapModulesRec' = dir: fn: + let + dirs = + mapAttrsToList + (k: _: "${dir}/${k}") + (filterAttrs + (n: v: v == "directory" && !(hasPrefix "_" n)) + (readDir dir)); + files = attrValues (mapModules dir id); + paths = files ++ concatLists (map (d: mapModulesRec' d id) dirs); + in map fn paths; +} diff --git a/lib/options.nix b/lib/options.nix new file mode 100755 index 00000000..2b9c0810 --- /dev/null +++ b/lib/options.nix @@ -0,0 +1,18 @@ +{ lib, ... }: + +let + inherit (lib) mkOption types; +in +rec { + mkOpt = type: default: + mkOption { inherit type default; }; + + mkOpt' = type: default: description: + mkOption { inherit type default description; }; + + mkBoolOpt = default: mkOption { + inherit default; + type = types.bool; + example = true; + }; +} diff --git a/modules/desktop/audio.nix b/modules/desktop/audio.nix index 146d4f59..ea1faae5 100755 --- a/modules/desktop/audio.nix +++ b/modules/desktop/audio.nix @@ -21,7 +21,6 @@ in { config = mkIf cfg.enable { # Enable JACK for the most serious audio applications. services.jack = { - alsa.enable = true; jackd.enable = true; }; @@ -55,7 +54,7 @@ in { ] else []); # Required when enabling JACK daemon. - my.user.extraGroups = [ "jackaudio" ]; + my.user.extraGroups = [ "audio" "jackaudio" ]; # Add the sequencer and the MIDI kernel module. boot.kernelModules = [ "snd-seq" "snd-rawmidi" ]; diff --git a/modules/desktop/files.nix b/modules/desktop/files.nix index 0efd84c3..75a80b0f 100755 --- a/modules/desktop/files.nix +++ b/modules/desktop/files.nix @@ -19,8 +19,9 @@ in { (recoll.override { withGui = false; }) # Bring the search engine to the desktop! - unison + unison # Back those files up, son. magic-wormhole # Magically transfer stuff between your wormholes! + oneshot # Basically `python -m http.server` that can deliver files to various devices. qbittorrent # Free version of uBittorrent. xfce.thunar # A graphical file manager. xfce.thunar-volman # A Thunar plugin on volume management for external devices. diff --git a/modules/desktop/fonts.nix b/modules/desktop/fonts.nix index 3e990b08..9589f468 100755 --- a/modules/desktop/fonts.nix +++ b/modules/desktop/fonts.nix @@ -13,7 +13,7 @@ with lib; config = mkIf config.modules.desktop.fonts.enable { # Enable fontconfig to easily discover fonts installed from home-manager. fonts = { - enableFontDir = true; + fontDir.enable = true; enableDefaultFonts = true; fontconfig = { enable = true; diff --git a/modules/dev/data.nix b/modules/dev/data.nix index d7b77b7b..e71d2a23 100755 --- a/modules/dev/data.nix +++ b/modules/dev/data.nix @@ -18,6 +18,7 @@ with lib; jq # A JSON parser on the command-line (with the horrible syntax, in my opinion). pup # A cute little puppy that can understand HTML. sqlite # A cute little battle-tested library for your data abominations. + sqlitebrowser # Skim the DB and create a quick scraping script for it. ]; }; } diff --git a/modules/dev/documentation.nix b/modules/dev/documentation.nix index af1bc1d4..2fa8977a 100755 --- a/modules/dev/documentation.nix +++ b/modules/dev/documentation.nix @@ -25,20 +25,22 @@ in config = mkIf cfg.enable { my.packages = with pkgs; [ - asciidoctor # An Asciidoctor document keeps a handful of few frustrated users a day. - aspell # The not-opinionated spell checker. + asciidoctor # An Asciidoctor document keeps a handful of few frustrated users a day. + aspell # The not-opinionated spell checker. aspellDicts.en aspellDicts.en-computers aspellDicts.en-science - hugo # An SSG for your DDD (documentation-driven development) workflow. - languagetool # A grammar checker with a HUGE data set. - pandoc # The Swiss army knife for document conversion. - R # Rated G for accessibility. - vale # The customizable linter for your intended writings. + editorconfig-core-c # A library just for formatting files? + editorconfig-checker # Check yer formatting. + hugo # An SSG for your DDD (documentation-driven development) workflow. + languagetool # A grammar checker with a HUGE data set. + pandoc # The Swiss army knife for document conversion. + R # Rated G for accessibility. + vale # The customizable linter for your intended writings. # TODO: Make Neuron its own package. (let - neuronRev = "2ea28ba1f023f169657a31a3cad621f1d745c606"; + neuronRev = "e7568ca5f51609bb406a48527b5ba52d31d11f9c"; neuronSrc = builtins.fetchTarball "https://github.com/srid/neuron/archive/${neuronRev}.tar.gz"; in import neuronSrc {}) # Neurons and zettels are good for the brain. ] ++ diff --git a/modules/dev/go.nix b/modules/dev/go.nix index 1c16e66e..5f1b179d 100755 --- a/modules/dev/go.nix +++ b/modules/dev/go.nix @@ -2,6 +2,10 @@ { config, options, lib, pkgs, ... }: with lib; + +let + cfg = config.modules.dev.go; +in { options.modules.dev.go = { enable = mkOption { @@ -10,7 +14,7 @@ with lib; }; }; - config = mkIf config.modules.dev.go.enable { + config = mkIf cfg.enable { my.packages = with pkgs; [ delve # Wait, Go doesn't have a proper debugger? go # The other zoomer proglang (READ: proglang is a zoomer term for programming language). diff --git a/modules/dev/java.nix b/modules/dev/java.nix index 21edd168..d3c3b766 100755 --- a/modules/dev/java.nix +++ b/modules/dev/java.nix @@ -3,6 +3,10 @@ { config, options, lib, pkgs, ... }: with lib; + +let + cfg = config.modules.dev.java; +in { options.modules.dev.java = { enable = mkOption { @@ -11,7 +15,7 @@ with lib; }; }; - config = mkIf config.modules.dev.java.enable { + config = mkIf cfg.enable { my.packages = with pkgs; [ jdk # The Java Development Kit. jre # The Java Runtime Environment for running Java apps. diff --git a/modules/dev/rust.nix b/modules/dev/rust.nix index 10601638..8c8d559b 100755 --- a/modules/dev/rust.nix +++ b/modules/dev/rust.nix @@ -3,6 +3,10 @@ { config, options, lib, pkgs, ... }: with lib; + +let + cfg = config.modules.dev.rust; +in { options.modules.dev.rust = { enable = mkOption { @@ -11,7 +15,7 @@ with lib; }; }; - config = mkIf config.modules.dev.rust.enable { + config = mkIf cfg.enable { my.packages = with pkgs; [ rustup ]; diff --git a/modules/dev/vcs.nix b/modules/dev/vcs.nix index 137d9a4d..8f32bfd4 100755 --- a/modules/dev/vcs.nix +++ b/modules/dev/vcs.nix @@ -2,6 +2,10 @@ { config, options, lib, pkgs, ... }: with lib; + +let + cfg = config.modules.dev.vcs; +in { options.modules.dev.vcs = { enable = mkOption { @@ -10,7 +14,7 @@ with lib; }; }; - config = mkIf config.modules.dev.vcs.enable { + config = mkIf cfg.enable { my.packages = with pkgs; [ gitAndTools.gitFull mercurial diff --git a/modules/shell/base.nix b/modules/shell/base.nix index 368d5a5a..18d59131 100755 --- a/modules/shell/base.nix +++ b/modules/shell/base.nix @@ -19,14 +19,15 @@ with lib; exa # ls(1) after an exodus. fd # find(1) after a cognitive behavioral therapy. fzf # A fuzzy finder that enables fuzzy finding not furry finding, a common misconception. + gopass # The improved version of Password Store which is a password manager for hipsters. + graphviz # The biz central for graphical flowcharts. hexyl # Binary viewer with a cool name on the command-line. hledger # Do your accountancy thing ON THE COMMAND LINE, sure why not! httpie # Want a piece of the HTTP pie. - gitAndTools.tig # The Deltarune of Git. - gopass # The improved version of Password Store which is a password manager for hipsters. - graphviz # The biz central for graphical flowcharts. - maim # A command-line interface for parsing screenshots. jq # A command-line interface for parsing JSON. + lazygit # For the lazy gits who cannot get good at Git. + lazydocker # For the lazy gits who cannot get good at Docker. + maim # A command-line interface for parsing screenshots. pup # A command-line interface for parsing HTML. (ripgrep.override { withPCRE2 = true; }) # Super-fast full-text searcher. (recoll.override { withGui = false; }) # Bring the search engine to the desktop! diff --git a/modules/themes/default.nix b/modules/themes/default.nix index 7381bea0..a5f39c21 100755 --- a/modules/themes/default.nix +++ b/modules/themes/default.nix @@ -4,37 +4,15 @@ with lib; let cfg = config.modules.themes; + my = import ../../lib { inherit pkgs; lib = lib; }; in { + assertions = [{ + assertion = my.countAttrs (_: x: x.enable) cfg < 2; + message = "Can't have more than one theme enabled at a time"; + }]; + imports = [ ./fair-and-square ]; - - options.modules.themes = { - name = mkOption { - type = with types; nullOr str; - default = null; - }; - - version = mkOption { - type = with types; nullOr str; - default = null; - }; - - path = mkOption { - type = with types; nullOr path; - default = null; - }; - - wallpaper = mkOption { - type = with types; nullOr path; - default = if cfg.path != null - then "${cfg.path}/config/wallpaper" - else null; - }; - }; - - config = mkIf (cfg.path != null && builtins.pathExists cfg.wallpaper) { - my.home.home.file.".background-image".source = cfg.wallpaper; - }; } diff --git a/modules/themes/fair-and-square/config/polybar/config b/modules/themes/fair-and-square/config/polybar/config index d0339a2a..df4bb52e 100755 --- a/modules/themes/fair-and-square/config/polybar/config +++ b/modules/themes/fair-and-square/config/polybar/config @@ -59,7 +59,7 @@ modules-left = bspwm modules-center = date - modules-right = pulseaudio eth memory root-fs + modules-right = pulseaudio eth memory root-fs home-fs [module/root-fs] @@ -73,6 +73,17 @@ label-unmounted = N/A +[module/home-fs] + type = internal/fs + mount-0 = /home/ + format-mounted-prefix = "" + format-mounted-prefix-margin-right = 1 + format-unmounted-prefix = "" + format-unmounted-prefix-margin-right = 1 + label-mounted = %free% + label-unmounted = N/A + + [module/bspwm] type = internal/bspwm wrapping-scroll = false diff --git a/modules/themes/fair-and-square/default.nix b/modules/themes/fair-and-square/default.nix index d6c6b79c..391e0df0 100755 --- a/modules/themes/fair-and-square/default.nix +++ b/modules/themes/fair-and-square/default.nix @@ -10,13 +10,6 @@ with lib; }; config = mkIf config.modules.themes."fair-and-square".enable { - # Pass the metadata of the theme. - modules.theme = { - name = "Fair and square"; - version = "0.1.0"; - path = ./.; - }; - services = { # Enable picom compositor. picom = { @@ -29,8 +22,6 @@ with lib; xserver = { displayManager = { lightdm.enable = true; - lightdm.greeters.mini.enable = true; - lightdm.greeters.mini.user = config.my.username; defaultSession = "none+bspwm"; }; enable = true; @@ -45,6 +36,9 @@ with lib; # Enable GTK configuration. gtk.enable = true; + # Set the wallpaper. + home.file.".background-image".source = ./config/wallpaper; + # Enable QT configuration and set it to the same GTK config. qt.enable = true; qt.platformTheme = "gtk"; @@ -89,14 +83,14 @@ with lib; ''; }) ]; - }; - # Set the cursor theme. - xdg.dataFile = { - "icons/default/index.theme".text = '' - [icon theme] - Inherits=Adwaita - ''; + # Set the cursor theme. + xdg.dataFile = { + "icons/default/index.theme".text = '' + [icon theme] + Inherits=Adwaita + ''; + }; }; my.packages = with pkgs; [