From 5c609ddd42bdec6991eebe620ec913542045768f Mon Sep 17 00:00:00 2001 From: marc Date: Mon, 14 Nov 2022 21:19:51 +0100 Subject: [PATCH] Added custom lib (stolen from hlissner's dotifles) --- README.org | 18 -------- config/doom/config.el | 75 +++++++++++++++----------------- config/doom/init.el | 3 +- config/doom/packages.el | 6 +-- flake.lock | 17 -------- flake.nix | 53 +++++++++++----------- lib/attrs.nix | 26 +++++++++++ lib/default.nix | 31 +++++++++++++ lib/modules.nix | 53 ++++++++++++++++++++++ lib/options.nix | 18 ++++++++ system/modules/editors/emacs.nix | 15 ++++--- 11 files changed, 202 insertions(+), 113 deletions(-) create mode 100644 lib/attrs.nix create mode 100644 lib/default.nix create mode 100644 lib/modules.nix create mode 100644 lib/options.nix diff --git a/README.org b/README.org index a0e4318..96d1dfb 100644 --- a/README.org +++ b/README.org @@ -1,90 +1,72 @@ * Installing - ** Fresh system (nixos USB drive) - 1. Open a nix-shell with git: #+BEGIN_SRC bash nix-shell -p git #+END_SRC - 2. Clone the flake #+BEGIN_SRC bash git clone https://git.lajuntament.space/marc/samfelag.git #+END_SRC - 3. Partition the disk 1. Locate the disk #+BEGIN_SRC bash lsblk #+END_SRC - 2. Create a GPT partition table #+BEGIN_SRC bash sudo parted /dev/nvme0n1 -- mklabel gpt #+END_SRC - 3. Create the root partition #+BEGIN_SRC bash sudo parted /dev/nvme0n1 -- mkpart primary 512MB -8GB #+END_SRC - 4. Create the swap partition #+BEGIN_SRC bash sudo parted /dev/nvme0n1 -- mkpart primary linux-swap -8GB 100% #+END_SRC - 5. Create the boot partition #+BEGIN_SRC bash sudo parted /dev/nvme0n1 -- mkpart ESP fat32 1MB 512MB sudo parted /dev/nvme0n1 -- set 3 esp on #+END_SRC - 4. Format the partitions 1. Root partition #+BEGIN_SRC bash sudo mkfs.ext4 -L nixos /dev/nvme0n1p1 #+END_SRC - 2. Swap partition #+BEGIN_SRC bash sudo mkswap -L swap /dev/nvme0n1p2 #+END_SRC - 3. Boot partition #+BEGIN_SRC bash sudo mkfs.fat -F 32 -n BOOT /dev/nvme0n1p3 #+END_SRC - 5. Mount the filesystems 1. Root partition #+BEGIN_SRC bash sudo mount /dev/disk/by-label/nixos /mnt #+END_SRC - 2. Boot partition #+BEGIN_SRC bash sudo mkdir -p /mnt/boot sudo mount /dev/disk/by-label/BOOT /mnt/boot #+END_SRC - 3. Swap partition (if needed) #+BEGIN_SRC bash sudo swapon /dev/disk/by-label/swap #+END_SRC - 6. Create the host nix configuration If the host is not present under system/hosts, create a new folder for the host. Generate the hardware configuration file, you can use nixos-generate-config as a base: - #+BEGIN_SRC bash nixos-generate-config --dir <> --no-filesystems #+END_SRC - 7. Install nixos! #+BEGIN_SRC bash sudo nixos-install --impure --root /mnt --flake .#reykjavik #+END_SRC - 8. Set up the user You'll set the root password during the installation. You can then reboot and use the installed OS. First thing you'll have to do is log in as root and set the password for your user: #+BEGIN_SRC bash diff --git a/config/doom/config.el b/config/doom/config.el index e4a6ef1..6f1ebfc 100644 --- a/config/doom/config.el +++ b/config/doom/config.el @@ -22,6 +22,7 @@ ;; (setq doom-font (font-spec :family "monospace" :size 12 :weight 'semi-light) ;; doom-variable-pitch-font (font-spec :family "sans" :size 13)) (setq doom-font (font-spec :family "Iosevka" :size 15)) +(setq doom-unicode-font (font-spec :family "Iosevka Nerd Font" :size 15)) ;; There are two ways to load a theme. Both assume the theme is installed and ;; available. You can either set `doom-theme' or manually load a theme with the @@ -105,47 +106,39 @@ (setq org-directory "~/org/") -(use-package org-roam - :ensure t - :init - (setq org-roam-v2-ack t) - :custom - (org-roam-directory "~/org-roam") - (org-roam-capture-templates - '(("d" "default" plain "%?" - :target (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n") - :unnarrowed t) - ("m" "màquina" plain (file "~/org-roam/templates/maquina.org") - :target (file "%<%Y%m%d%H%M%S>-${slug}.org") - :unnarrowed t) - ("s" "software" plain (file "~/org-roam/templates/software.org") - :target (file "%<%Y%m%d%H%M%S>-${slug}.org") - :unnarrowed t))) - :config - (org-roam-setup)) - -(use-package! websocket - :after org-roam) - -(use-package! org-roam-ui - :after org-roam ;; or :after org -;; normally we'd recommend hooking orui after org-roam, but since org-roam does not have -;; a hookable mode anymore, you're advised to pick something yourself -;; if you don't care about startup time, use -;; :hook (after-init . org-roam-ui-mode) - :config - (setq org-roam-ui-sync-theme t - org-roam-ui-follow t - org-roam-ui-update-on-save t - org-roam-ui-open-on-start nil)) - - -;; ----------------------------------------------------------------------------- -;; Lilypond -;; ----------------------------------------------------------------------------- - -(load-library "lilypond-mode") -(add-to-list 'auto-mode-alist '("\\.ly$" . LilyPond-mode)) +; (use-package org-roam +; :ensure t +; :init +; (setq org-roam-v2-ack t) +; :custom +; (org-roam-directory "~/org-roam") +; (org-roam-capture-templates +; '(("d" "default" plain "%?" +; :target (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n") +; :unnarrowed t) +; ("m" "màquina" plain (file "~/org-roam/templates/maquina.org") +; :target (file "%<%Y%m%d%H%M%S>-${slug}.org") +; :unnarrowed t) +; ("s" "software" plain (file "~/org-roam/templates/software.org") +; :target (file "%<%Y%m%d%H%M%S>-${slug}.org") +; :unnarrowed t))) +; :config +; (org-roam-setup)) +; +; (use-package! websocket +; :after org-roam) +; +; (use-package! org-roam-ui +; :after org-roam ;; or :after org +; ;; normally we'd recommend hooking orui after org-roam, but since org-roam does not have +; ;; a hookable mode anymore, you're advised to pick something yourself +; ;; if you don't care about startup time, use +; ;; :hook (after-init . org-roam-ui-mode) +; :config +; (setq org-roam-ui-sync-theme t +; org-roam-ui-follow t +; org-roam-ui-update-on-save t +; org-roam-ui-open-on-start nil)) ;; ----------------------------------------------------------------------------- ;; Appearance - Prettify diff --git a/config/doom/init.el b/config/doom/init.el index 9cc978c..e5ba83c 100644 --- a/config/doom/init.el +++ b/config/doom/init.el @@ -31,7 +31,7 @@ doom-dashboard ; a nifty splash screen for Emacs ;; doom-quit ; DOOM quit-message prompts when you quit Emacs ;;(emoji +unicode) ; 🙂 - fill-column ; a `fill-column' indicator + ;; fill-column ; a `fill-column' indicator hl-todo ; highlight TODO/FIXME/NOTE/DEPRECATED/HACK/REVIEW ;;hydra ;;indent-guides ; highlighted indent columns @@ -149,7 +149,6 @@ ;;ocaml ; an objective camel (org +journal - +roam2 +pretty) ; organize your plain life in plain text php ; perl's insecure younger brother ;;plantuml ; diagrams for confusing people more diff --git a/config/doom/packages.el b/config/doom/packages.el index b651ae1..43e5abc 100644 --- a/config/doom/packages.el +++ b/config/doom/packages.el @@ -60,6 +60,6 @@ ;; Org ;; Org-Roam UI -(unpin! org-roam) -(package! websocket) -(package! org-roam-ui :recipe (:host github :repo "org-roam/org-roam-ui" :files ("*.el" "out"))) +; (unpin! org-roam) +; (package! websocket) +; (package! org-roam-ui :recipe (:host github :repo "org-roam/org-roam-ui" :files ("*.el" "out"))) diff --git a/flake.lock b/flake.lock index b1b33fb..4b613cd 100644 --- a/flake.lock +++ b/flake.lock @@ -1,21 +1,5 @@ { "nodes": { - "doom-emacs": { - "flake": false, - "locked": { - "lastModified": 1667229496, - "narHash": "sha256-SURAFrtblyvkflQz1cEQogfo31UzSvKd+UOgczUyJ8k=", - "owner": "doomemacs", - "repo": "doomemacs", - "rev": "9d4d5b756a8598c4b5c842e9f1f33148af2af8fd", - "type": "github" - }, - "original": { - "owner": "doomemacs", - "repo": "doomemacs", - "type": "github" - } - }, "emacs-overlay": { "inputs": { "flake-utils": "flake-utils", @@ -103,7 +87,6 @@ }, "root": { "inputs": { - "doom-emacs": "doom-emacs", "emacs-overlay": "emacs-overlay", "home-manager": "home-manager", "nixpkgs": "nixpkgs_2" diff --git a/flake.nix b/flake.nix index d5503ff..a129f64 100644 --- a/flake.nix +++ b/flake.nix @@ -20,35 +20,11 @@ config.allowUnfree = true; overlays = import ./overlays; }; - lib = nixpkgs.lib; + lib = nixpkgs.lib.extend + (self: super: { my = import ./lib { inherit pkgs inputs; lib = self; }; }); in { nixosConfigurations = { - # - Kopavogur ---------------------------- - kopavogur = lib.nixosSystem { - inherit system; - inherit pkgs; - modules = [ - - ./system/modules - ./system/profiles - ./system/hosts/kopavogur - - home-manager.nixosModules.home-manager { - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - home-manager.users.marc = { - imports = [ - ./home/modules - ./home/profiles - ./home/hosts/kopavogur.nix - ]; - }; - } - - ]; - }; - # - Reykjavik ---------------------------- reykjavik = lib.nixosSystem { inherit system; @@ -76,6 +52,31 @@ ]; }; + # - Kopavogur ---------------------------- + kopavogur = lib.nixosSystem { + inherit system; + inherit pkgs; + modules = [ + + ./system/modules + ./system/profiles + ./system/hosts/kopavogur + + home-manager.nixosModules.home-manager { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.users.marc = { + imports = [ + ./home/modules + ./home/profiles + ./home/hosts/kopavogur.nix + ]; + }; + } + + ]; + }; + }; }; } diff --git a/lib/attrs.nix b/lib/attrs.nix new file mode 100644 index 0000000..0f8ebd1 --- /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 100644 index 0000000..708de78 --- /dev/null +++ b/lib/default.nix @@ -0,0 +1,31 @@ +{ inputs, lib, pkgs, ... }: + +let + inherit (lib) makeExtensible attrValues foldr; + inherit (modules) mapModules; + + # We define modules, so we can use mapModules + modules = import ./modules.nix { + inherit lib; + self.attrs = import ./attrs.nix { inherit lib; self = {}; }; + }; + + # mylib = { + # "attrs" = import "attrs.nix" { selg lib pkgs inputs }; + # "options" = import "options.nix" { selg lib pkgs inputs }; + # ... + # "extend": <>; # from makeExtensible + # "__unfix__": <>; # from makeExtensible + # } + mylib = makeExtensible (self: + with self; mapModules ./. + (file: import file { inherit self lib pkgs inputs; })); +in +# We have +# (attrValues super) = [ (import "attrs.nix" {...}) (import "options.nix" {...}) ... ] +# And thus +# mylib.extend(...) = (import "attrs.nix" {...}) // (import "options.nix" {...}) // ... +# Which is what we want, default.nix returns all modules merged (and extensible) +mylib.extend + (self: super: + foldr (a: b: a // b) {} (attrValues super)) diff --git a/lib/modules.nix b/lib/modules.nix new file mode 100644 index 0000000..47743f1 --- /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 100644 index 0000000..2b9c081 --- /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/system/modules/editors/emacs.nix b/system/modules/editors/emacs.nix index 77df2dd..d6439e7 100644 --- a/system/modules/editors/emacs.nix +++ b/system/modules/editors/emacs.nix @@ -33,7 +33,8 @@ in { environment.systemPackages = with pkgs; [ ## Emacs itself binutils - emacs + ((emacsPackagesFor emacsNativeComp).emacsWithPackages + (epkgs: [ epkgs.vterm ])) # emacsPgtkGcc ## Doom dependencies @@ -47,7 +48,13 @@ in { pinentry_emacs zstd - # ## Modules deps + ## Modules deps + # :tools vterm + gcc + gnumake + libtool + cmake + # # :lang cc # ccls # cmake @@ -74,10 +81,6 @@ in { # sqlite # # :tools direnv # direnv - # # :tools vterm - # gcc - # gnumake - # libtool # Fonts emacs-all-the-icons-fonts