Added custom lib (stolen from hlissner's dotifles)

This commit is contained in:
marc
2022-11-14 21:19:51 +01:00
parent e22078b34a
commit 5c609ddd42
11 changed files with 202 additions and 113 deletions

View File

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

View File

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

View File

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

View File

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

17
flake.lock generated
View File

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

View File

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

26
lib/attrs.nix Normal 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);
}

31
lib/default.nix Normal file
View File

@@ -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": <<lambda>>; # from makeExtensible
# "__unfix__": <<lambda>>; # 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))

53
lib/modules.nix Normal 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 Normal 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

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