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 * Installing
** Fresh system (nixos USB drive) ** Fresh system (nixos USB drive)
1. Open a nix-shell with git: 1. Open a nix-shell with git:
#+BEGIN_SRC bash #+BEGIN_SRC bash
nix-shell -p git nix-shell -p git
#+END_SRC #+END_SRC
2. Clone the flake 2. Clone the flake
#+BEGIN_SRC bash #+BEGIN_SRC bash
git clone https://git.lajuntament.space/marc/samfelag.git git clone https://git.lajuntament.space/marc/samfelag.git
#+END_SRC #+END_SRC
3. Partition the disk 3. Partition the disk
1. Locate the disk 1. Locate the disk
#+BEGIN_SRC bash #+BEGIN_SRC bash
lsblk lsblk
#+END_SRC #+END_SRC
2. Create a GPT partition table 2. Create a GPT partition table
#+BEGIN_SRC bash #+BEGIN_SRC bash
sudo parted /dev/nvme0n1 -- mklabel gpt sudo parted /dev/nvme0n1 -- mklabel gpt
#+END_SRC #+END_SRC
3. Create the root partition 3. Create the root partition
#+BEGIN_SRC bash #+BEGIN_SRC bash
sudo parted /dev/nvme0n1 -- mkpart primary 512MB -8GB sudo parted /dev/nvme0n1 -- mkpart primary 512MB -8GB
#+END_SRC #+END_SRC
4. Create the swap partition 4. Create the swap partition
#+BEGIN_SRC bash #+BEGIN_SRC bash
sudo parted /dev/nvme0n1 -- mkpart primary linux-swap -8GB 100% sudo parted /dev/nvme0n1 -- mkpart primary linux-swap -8GB 100%
#+END_SRC #+END_SRC
5. Create the boot partition 5. Create the boot partition
#+BEGIN_SRC bash #+BEGIN_SRC bash
sudo parted /dev/nvme0n1 -- mkpart ESP fat32 1MB 512MB sudo parted /dev/nvme0n1 -- mkpart ESP fat32 1MB 512MB
sudo parted /dev/nvme0n1 -- set 3 esp on sudo parted /dev/nvme0n1 -- set 3 esp on
#+END_SRC #+END_SRC
4. Format the partitions 4. Format the partitions
1. Root partition 1. Root partition
#+BEGIN_SRC bash #+BEGIN_SRC bash
sudo mkfs.ext4 -L nixos /dev/nvme0n1p1 sudo mkfs.ext4 -L nixos /dev/nvme0n1p1
#+END_SRC #+END_SRC
2. Swap partition 2. Swap partition
#+BEGIN_SRC bash #+BEGIN_SRC bash
sudo mkswap -L swap /dev/nvme0n1p2 sudo mkswap -L swap /dev/nvme0n1p2
#+END_SRC #+END_SRC
3. Boot partition 3. Boot partition
#+BEGIN_SRC bash #+BEGIN_SRC bash
sudo mkfs.fat -F 32 -n BOOT /dev/nvme0n1p3 sudo mkfs.fat -F 32 -n BOOT /dev/nvme0n1p3
#+END_SRC #+END_SRC
5. Mount the filesystems 5. Mount the filesystems
1. Root partition 1. Root partition
#+BEGIN_SRC bash #+BEGIN_SRC bash
sudo mount /dev/disk/by-label/nixos /mnt sudo mount /dev/disk/by-label/nixos /mnt
#+END_SRC #+END_SRC
2. Boot partition 2. Boot partition
#+BEGIN_SRC bash #+BEGIN_SRC bash
sudo mkdir -p /mnt/boot sudo mkdir -p /mnt/boot
sudo mount /dev/disk/by-label/BOOT /mnt/boot sudo mount /dev/disk/by-label/BOOT /mnt/boot
#+END_SRC #+END_SRC
3. Swap partition (if needed) 3. Swap partition (if needed)
#+BEGIN_SRC bash #+BEGIN_SRC bash
sudo swapon /dev/disk/by-label/swap sudo swapon /dev/disk/by-label/swap
#+END_SRC #+END_SRC
6. Create the host nix configuration 6. Create the host nix configuration
If the host is not present under system/hosts, create a new folder for the host. 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: Generate the hardware configuration file, you can use nixos-generate-config as a base:
#+BEGIN_SRC bash #+BEGIN_SRC bash
nixos-generate-config --dir <<host directory>> --no-filesystems nixos-generate-config --dir <<host directory>> --no-filesystems
#+END_SRC #+END_SRC
7. Install nixos! 7. Install nixos!
#+BEGIN_SRC bash #+BEGIN_SRC bash
sudo nixos-install --impure --root /mnt --flake .#reykjavik sudo nixos-install --impure --root /mnt --flake .#reykjavik
#+END_SRC #+END_SRC
8. Set up the user 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: 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 #+BEGIN_SRC bash

View File

@@ -22,6 +22,7 @@
;; (setq doom-font (font-spec :family "monospace" :size 12 :weight 'semi-light) ;; (setq doom-font (font-spec :family "monospace" :size 12 :weight 'semi-light)
;; doom-variable-pitch-font (font-spec :family "sans" :size 13)) ;; doom-variable-pitch-font (font-spec :family "sans" :size 13))
(setq doom-font (font-spec :family "Iosevka" :size 15)) (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 ;; 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 ;; available. You can either set `doom-theme' or manually load a theme with the
@@ -105,47 +106,39 @@
(setq org-directory "~/org/") (setq org-directory "~/org/")
(use-package org-roam ; (use-package org-roam
:ensure t ; :ensure t
:init ; :init
(setq org-roam-v2-ack t) ; (setq org-roam-v2-ack t)
:custom ; :custom
(org-roam-directory "~/org-roam") ; (org-roam-directory "~/org-roam")
(org-roam-capture-templates ; (org-roam-capture-templates
'(("d" "default" plain "%?" ; '(("d" "default" plain "%?"
:target (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n") ; :target (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
:unnarrowed t) ; :unnarrowed t)
("m" "màquina" plain (file "~/org-roam/templates/maquina.org") ; ("m" "màquina" plain (file "~/org-roam/templates/maquina.org")
:target (file "%<%Y%m%d%H%M%S>-${slug}.org") ; :target (file "%<%Y%m%d%H%M%S>-${slug}.org")
:unnarrowed t) ; :unnarrowed t)
("s" "software" plain (file "~/org-roam/templates/software.org") ; ("s" "software" plain (file "~/org-roam/templates/software.org")
:target (file "%<%Y%m%d%H%M%S>-${slug}.org") ; :target (file "%<%Y%m%d%H%M%S>-${slug}.org")
:unnarrowed t))) ; :unnarrowed t)))
:config ; :config
(org-roam-setup)) ; (org-roam-setup))
;
(use-package! websocket ; (use-package! websocket
:after org-roam) ; :after org-roam)
;
(use-package! org-roam-ui ; (use-package! org-roam-ui
:after org-roam ;; or :after org ; :after org-roam ;; or :after org
;; normally we'd recommend hooking orui after org-roam, but since org-roam does not have ; ;; 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 ; ;; a hookable mode anymore, you're advised to pick something yourself
;; if you don't care about startup time, use ; ;; if you don't care about startup time, use
;; :hook (after-init . org-roam-ui-mode) ; ;; :hook (after-init . org-roam-ui-mode)
:config ; :config
(setq org-roam-ui-sync-theme t ; (setq org-roam-ui-sync-theme t
org-roam-ui-follow t ; org-roam-ui-follow t
org-roam-ui-update-on-save t ; org-roam-ui-update-on-save t
org-roam-ui-open-on-start nil)) ; org-roam-ui-open-on-start nil))
;; -----------------------------------------------------------------------------
;; Lilypond
;; -----------------------------------------------------------------------------
(load-library "lilypond-mode")
(add-to-list 'auto-mode-alist '("\\.ly$" . LilyPond-mode))
;; ----------------------------------------------------------------------------- ;; -----------------------------------------------------------------------------
;; Appearance - Prettify ;; Appearance - Prettify

View File

@@ -31,7 +31,7 @@
doom-dashboard ; a nifty splash screen for Emacs doom-dashboard ; a nifty splash screen for Emacs
;; doom-quit ; DOOM quit-message prompts when you quit Emacs ;; doom-quit ; DOOM quit-message prompts when you quit Emacs
;;(emoji +unicode) ; 🙂 ;;(emoji +unicode) ; 🙂
fill-column ; a `fill-column' indicator ;; fill-column ; a `fill-column' indicator
hl-todo ; highlight TODO/FIXME/NOTE/DEPRECATED/HACK/REVIEW hl-todo ; highlight TODO/FIXME/NOTE/DEPRECATED/HACK/REVIEW
;;hydra ;;hydra
;;indent-guides ; highlighted indent columns ;;indent-guides ; highlighted indent columns
@@ -149,7 +149,6 @@
;;ocaml ; an objective camel ;;ocaml ; an objective camel
(org (org
+journal +journal
+roam2
+pretty) ; organize your plain life in plain text +pretty) ; organize your plain life in plain text
php ; perl's insecure younger brother php ; perl's insecure younger brother
;;plantuml ; diagrams for confusing people more ;;plantuml ; diagrams for confusing people more

View File

@@ -60,6 +60,6 @@
;; Org ;; Org
;; Org-Roam UI ;; Org-Roam UI
(unpin! org-roam) ; (unpin! org-roam)
(package! websocket) ; (package! websocket)
(package! org-roam-ui :recipe (:host github :repo "org-roam/org-roam-ui" :files ("*.el" "out"))) ; (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": { "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": { "emacs-overlay": {
"inputs": { "inputs": {
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
@@ -103,7 +87,6 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"doom-emacs": "doom-emacs",
"emacs-overlay": "emacs-overlay", "emacs-overlay": "emacs-overlay",
"home-manager": "home-manager", "home-manager": "home-manager",
"nixpkgs": "nixpkgs_2" "nixpkgs": "nixpkgs_2"

View File

@@ -20,35 +20,11 @@
config.allowUnfree = true; config.allowUnfree = true;
overlays = import ./overlays; overlays = import ./overlays;
}; };
lib = nixpkgs.lib; lib = nixpkgs.lib.extend
(self: super: { my = import ./lib { inherit pkgs inputs; lib = self; }; });
in { in {
nixosConfigurations = { 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 ----------------------------
reykjavik = lib.nixosSystem { reykjavik = lib.nixosSystem {
inherit system; 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; [ environment.systemPackages = with pkgs; [
## Emacs itself ## Emacs itself
binutils binutils
emacs ((emacsPackagesFor emacsNativeComp).emacsWithPackages
(epkgs: [ epkgs.vterm ]))
# emacsPgtkGcc # emacsPgtkGcc
## Doom dependencies ## Doom dependencies
@@ -47,7 +48,13 @@ in {
pinentry_emacs pinentry_emacs
zstd zstd
# ## Modules deps ## Modules deps
# :tools vterm
gcc
gnumake
libtool
cmake
# # :lang cc # # :lang cc
# ccls # ccls
# cmake # cmake
@@ -74,10 +81,6 @@ in {
# sqlite # sqlite
# # :tools direnv # # :tools direnv
# direnv # direnv
# # :tools vterm
# gcc
# gnumake
# libtool
# Fonts # Fonts
emacs-all-the-icons-fonts emacs-all-the-icons-fonts