Update the config

This commit is contained in:
Gabriel Arazas 2020-10-20 23:56:10 +08:00
parent ef12c29f36
commit 0337611eb1
22 changed files with 213 additions and 77 deletions

View File

@ -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

View File

@ -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 <<Hosts>> 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 <<Packages>> section for more information.

View File

@ -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, ... }:

View File

@ -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 *~

View File

@ -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;

26
lib/attrs.nix Executable file
View File

@ -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);
}

18
lib/default.nix Executable file
View File

@ -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))

53
lib/modules.nix Executable file
View File

@ -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;
}

18
lib/options.nix Executable file
View File

@ -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;
};
}

View File

@ -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" ];

View File

@ -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.

View File

@ -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;

View File

@ -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.
];
};
}

View File

@ -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.
] ++

View File

@ -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).

View File

@ -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.

View File

@ -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
];

View File

@ -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

View File

@ -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!

View File

@ -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;
};
}

View File

@ -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

View File

@ -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; [