From 820ac199d8e3832acaf2d2d9776055cc27d74b31 Mon Sep 17 00:00:00 2001 From: pegasust Date: Sat, 14 Jan 2023 06:50:50 -0700 Subject: [PATCH 1/5] add flake-compat for out-of-tree bc maintainer seems ded --- flake.lock | 41 +++--- flake.nix | 2 +- out-of-tree/flake-compat/COPYING | 20 +++ out-of-tree/flake-compat/README.md | 29 ++++ out-of-tree/flake-compat/default.nix | 204 +++++++++++++++++++++++++++ 5 files changed, 273 insertions(+), 23 deletions(-) create mode 100644 out-of-tree/flake-compat/COPYING create mode 100644 out-of-tree/flake-compat/README.md create mode 100644 out-of-tree/flake-compat/default.nix diff --git a/flake.lock b/flake.lock index 5dde60d..2a3ea53 100644 --- a/flake.lock +++ b/flake.lock @@ -23,17 +23,14 @@ "flake-compat": { "flake": false, "locked": { - "lastModified": 1668681692, - "narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "009399224d5e398d03b22badca40a37ac85412a1", - "type": "github" + "lastModified": 1, + "narHash": "sha256-d6CilJXP+UPv3nF00zBBRhMgRklTCjSCMrjbYtYDuOI=", + "path": "out-of-tree/flake-compat", + "type": "path" }, "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" + "path": "out-of-tree/flake-compat", + "type": "path" } }, "flake-compat_2": { @@ -159,11 +156,11 @@ }, "locked": { "dir": "contrib", - "lastModified": 1673504032, - "narHash": "sha256-x4nv7g8+bQXg5PfkFw3vCcr3pYI0Hco0VoSbAy60xek=", + "lastModified": 1673683108, + "narHash": "sha256-zg1W14wyrOCKiTkXU+nGHf/EfqX6wtcUWcMo4O/Q6nY=", "owner": "neovim", "repo": "neovim", - "rev": "143d3f1f3224bca02bfef7df0932b9d7524a3ff2", + "rev": "e89c39d6f016a4140293755250e968e839009617", "type": "github" }, "original": { @@ -180,11 +177,11 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1673511313, - "narHash": "sha256-QGUT3w1bHclVRqX958EPOd3OxR/R10MoV97N5jx/qbw=", + "lastModified": 1673684013, + "narHash": "sha256-ljfG17g9K5sl7DGounCwOIfQLOGzXF0ffuDGxo3UN1E=", "owner": "nix-community", "repo": "neovim-nightly-overlay", - "rev": "5af6fe31f9906e70a1e8985dbbdcc4ae66c7f82d", + "rev": "85b0900729bffa5e0d1817bbc6f024916dc1f38e", "type": "github" }, "original": { @@ -220,7 +217,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-KP+2qdZlhmRkrafuuEofg7YnNdVmGV95ipvpuqmJneI=", + "narHash": "sha256-RkO+8E7MahERHw1C5DNObDjq4xeI+FqaWH9+M7Fv2UE=", "path": "out-of-tree/nixGL", "type": "path" }, @@ -262,11 +259,11 @@ }, "nixpkgs_3": { "locked": { - "lastModified": 1673450908, - "narHash": "sha256-b8em+kwrNtnB7gR8SyVf6WuTyQ+6tHS6dzt9D9wgKF0=", + "lastModified": 1673540789, + "narHash": "sha256-xqnxBOK3qctIeUVxecydrEDbEXjsvHCPGPbvsl63M/U=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "6c8644fc37b6e141cbfa6c7dc8d98846c4ff0c2e", + "rev": "0f213d0fee84280d8c3a97f7469b988d6fe5fcdf", "type": "github" }, "original": { @@ -311,11 +308,11 @@ "nixpkgs": "nixpkgs_4" }, "locked": { - "lastModified": 1673490397, - "narHash": "sha256-VCSmIYJy/ZzTvEGjdfITmTYfybXBgZpMjyjDndbou+8=", + "lastModified": 1673662873, + "narHash": "sha256-/YOtiDKPUXKKpIhsAds11llfC42ScGW27bbHnNZebco=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "0833f4d063a2bb75aa31680f703ba594a384ffe6", + "rev": "90163bbbadce526f8b248a5fe545b06c59597108", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index d03e53f..43bcfae 100644 --- a/flake.nix +++ b/flake.nix @@ -15,7 +15,7 @@ rust-overlay.url = "github:oxalica/rust-overlay"; # Allows default.nix to call onto flake.nix. Useful for nix eval and automations flake-compat = { - url = "github:edolstra/flake-compat"; + url = "path:out-of-tree/flake-compat"; flake = false; }; kpcli-py = { diff --git a/out-of-tree/flake-compat/COPYING b/out-of-tree/flake-compat/COPYING new file mode 100644 index 0000000..694ce95 --- /dev/null +++ b/out-of-tree/flake-compat/COPYING @@ -0,0 +1,20 @@ +Copyright (c) 2020-2021 Eelco Dolstra and the flake-compat contributors + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/out-of-tree/flake-compat/README.md b/out-of-tree/flake-compat/README.md new file mode 100644 index 0000000..8added0 --- /dev/null +++ b/out-of-tree/flake-compat/README.md @@ -0,0 +1,29 @@ +# flake-compat + +## Usage + +To use, add the following to your `flake.nix`: + +```nix +inputs.flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; +}; +``` + +Afterwards, create a `default.nix` file containing the following: + +```nix +(import + ( + let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } + ) + { src = ./.; } +).defaultNix +``` + +If you would like a `shell.nix` file, create one containing the above, replacing `defaultNix` with `shellNix`. diff --git a/out-of-tree/flake-compat/default.nix b/out-of-tree/flake-compat/default.nix new file mode 100644 index 0000000..c966c6d --- /dev/null +++ b/out-of-tree/flake-compat/default.nix @@ -0,0 +1,204 @@ +# Compatibility function to allow flakes to be used by +# non-flake-enabled Nix versions. Given a source tree containing a +# 'flake.nix' and 'flake.lock' file, it fetches the flake inputs and +# calls the flake's 'outputs' function. It then returns an attrset +# containing 'defaultNix' (to be used in 'default.nix'), 'shellNix' +# (to be used in 'shell.nix'). + +{ src, system ? builtins.currentSystem or "unknown-system" }: + +let + + lockFilePath = src + "/flake.lock"; + + lockFile = builtins.fromJSON (builtins.readFile lockFilePath); + + fetchTree = + info: + if info.type == "github" then + { outPath = + fetchTarball + ({ url = "https://api.${info.host or "github.com"}/repos/${info.owner}/${info.repo}/tarball/${info.rev}"; } + // (if info ? narHash then { sha256 = info.narHash; } else {}) + ); + rev = info.rev; + shortRev = builtins.substring 0 7 info.rev; + lastModified = info.lastModified; + lastModifiedDate = formatSecondsSinceEpoch info.lastModified; + narHash = info.narHash; + } + else if info.type == "git" then + { outPath = + builtins.fetchGit + ({ url = info.url; } + // (if info ? rev then { inherit (info) rev; } else {}) + // (if info ? ref then { inherit (info) ref; } else {}) + // (if info ? submodules then { inherit (info) submodules; } else {}) + ); + lastModified = info.lastModified; + lastModifiedDate = formatSecondsSinceEpoch info.lastModified; + narHash = info.narHash; + } // (if info ? rev then { + rev = info.rev; + shortRev = builtins.substring 0 7 info.rev; + } else { + }) + else if info.type == "path" then + { outPath = builtins.path { + path = if builtins.substring 0 1 info.path != "/" + then src + ("/" + info.path) # make this absolute path by prepending ./ + else info.path; # it's already an absolute path + }; + narHash = info.narHash; + } + else if info.type == "tarball" then + { outPath = + fetchTarball + ({ inherit (info) url; } + // (if info ? narHash then { sha256 = info.narHash; } else {}) + ); + } + else if info.type == "gitlab" then + { inherit (info) rev narHash lastModified; + outPath = + fetchTarball + ({ url = "https://${info.host or "gitlab.com"}/api/v4/projects/${info.owner}%2F${info.repo}/repository/archive.tar.gz?sha=${info.rev}"; } + // (if info ? narHash then { sha256 = info.narHash; } else {}) + ); + shortRev = builtins.substring 0 7 info.rev; + } + else + # FIXME: add Mercurial, tarball inputs. + throw "flake input has unsupported input type '${info.type}'"; + + callFlake4 = flakeSrc: locks: + let + flake = import (flakeSrc + "/flake.nix"); + + inputs = builtins.mapAttrs (n: v: + if v.flake or true + then callFlake4 (fetchTree (v.locked // v.info)) v.inputs + else fetchTree (v.locked // v.info)) locks; + + outputs = flakeSrc // (flake.outputs (inputs // {self = outputs;})); + in + assert flake.edition == 201909; + outputs; + + callLocklessFlake = flakeSrc: + let + flake = import (flakeSrc + "/flake.nix"); + outputs = flakeSrc // (flake.outputs ({ self = outputs; })); + in outputs; + + rootSrc = let + # Try to clean the source tree by using fetchGit, if this source + # tree is a valid git repository. + tryFetchGit = src: + if isGit && !isShallow + then + let res = builtins.fetchGit src; + in if res.rev == "0000000000000000000000000000000000000000" then removeAttrs res ["rev" "shortRev"] else res + else { outPath = src; }; + # NB git worktrees have a file for .git, so we don't check the type of .git + isGit = builtins.pathExists (src + "/.git"); + isShallow = builtins.pathExists (src + "/.git/shallow"); + + in + { lastModified = 0; lastModifiedDate = formatSecondsSinceEpoch 0; } + // (if src ? outPath then src else tryFetchGit src); + + # Format number of seconds in the Unix epoch as %Y%m%d%H%M%S. + formatSecondsSinceEpoch = t: + let + rem = x: y: x - x / y * y; + days = t / 86400; + secondsInDay = rem t 86400; + hours = secondsInDay / 3600; + minutes = (rem secondsInDay 3600) / 60; + seconds = rem t 60; + + # Courtesy of https://stackoverflow.com/a/32158604. + z = days + 719468; + era = (if z >= 0 then z else z - 146096) / 146097; + doe = z - era * 146097; + yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365; + y = yoe + era * 400; + doy = doe - (365 * yoe + yoe / 4 - yoe / 100); + mp = (5 * doy + 2) / 153; + d = doy - (153 * mp + 2) / 5 + 1; + m = mp + (if mp < 10 then 3 else -9); + y' = y + (if m <= 2 then 1 else 0); + + pad = s: if builtins.stringLength s < 2 then "0" + s else s; + in "${toString y'}${pad (toString m)}${pad (toString d)}${pad (toString hours)}${pad (toString minutes)}${pad (toString seconds)}"; + + allNodes = + builtins.mapAttrs + (key: node: + let + sourceInfo = + if key == lockFile.root + then rootSrc + else fetchTree (node.info or {} // removeAttrs node.locked ["dir"]); + + subdir = if key == lockFile.root then "" else node.locked.dir or ""; + + flake = import (sourceInfo + (if subdir != "" then "/" else "") + subdir + "/flake.nix"); + + inputs = builtins.mapAttrs + (inputName: inputSpec: allNodes.${resolveInput inputSpec}) + (node.inputs or {}); + + # Resolve a input spec into a node name. An input spec is + # either a node name, or a 'follows' path from the root + # node. + resolveInput = inputSpec: + if builtins.isList inputSpec + then getInputByPath lockFile.root inputSpec + else inputSpec; + + # Follow an input path (e.g. ["dwarffs" "nixpkgs"]) from the + # root node, returning the final node. + getInputByPath = nodeName: path: + if path == [] + then nodeName + else + getInputByPath + # Since this could be a 'follows' input, call resolveInput. + (resolveInput lockFile.nodes.${nodeName}.inputs.${builtins.head path}) + (builtins.tail path); + + outputs = flake.outputs (inputs // { self = result; }); + + result = outputs // sourceInfo // { inherit inputs; inherit outputs; inherit sourceInfo; }; + in + if node.flake or true then + assert builtins.isFunction flake.outputs; + result + else + sourceInfo + ) + lockFile.nodes; + + result = + if !(builtins.pathExists lockFilePath) + then callLocklessFlake rootSrc + else if lockFile.version == 4 + then callFlake4 rootSrc (lockFile.inputs) + else if lockFile.version >= 5 && lockFile.version <= 7 + then allNodes.${lockFile.root} + else throw "lock file '${lockFilePath}' has unsupported version ${toString lockFile.version}"; + +in + rec { + defaultNix = + (builtins.removeAttrs result ["__functor"]) + // (if result ? defaultPackage.${system} then { default = result.defaultPackage.${system}; } else {}) + // (if result ? packages.${system}.default then { default = result.packages.${system}.default; } else {}); + + shellNix = + defaultNix + // (if result ? devShell.${system} then { default = result.devShell.${system}; } else {}) + // (if result ? devShells.${system}.default then { default = result.devShells.${system}.default; } else {}); + } -- 2.42.0 From ecfc6bf1fa36ad3f7b2dd740465cb9c1a08167e7 Mon Sep 17 00:00:00 2001 From: Pegasust Date: Sat, 14 Jan 2023 06:37:40 -0800 Subject: [PATCH 2/5] onboard htran --- native_configs/alacritty/alacritty.yml | 2 +- nix-conf/home-manager/base/alacritty.nix | 9 +++++++++ nix-conf/home-manager/base/git.nix | 1 + nix-conf/home-manager/flake.lock | 8 ++++---- nix-conf/home-manager/flake.nix | 13 ++++++++----- scripts/hm-switch.sh | 2 +- 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/native_configs/alacritty/alacritty.yml b/native_configs/alacritty/alacritty.yml index 4fd1b01..773f376 100755 --- a/native_configs/alacritty/alacritty.yml +++ b/native_configs/alacritty/alacritty.yml @@ -866,7 +866,7 @@ key_bindings: #- { key: Q, mods: Command, action: Quit } #- { key: W, mods: Command, action: Quit } #- { key: N, mods: Command, action: SpawnNewInstance } - #- { key: F, mods: Command|Control, action: ToggleFullscreen } + - { key: Return, mods: Command, action: ToggleFullscreen } #- { key: F, mods: Command, mode: ~Search, action: SearchForward } #- { key: B, mods: Command, mode: ~Search, action: SearchBackward } diff --git a/nix-conf/home-manager/base/alacritty.nix b/nix-conf/home-manager/base/alacritty.nix index 8677649..5f08776 100644 --- a/nix-conf/home-manager/base/alacritty.nix +++ b/nix-conf/home-manager/base/alacritty.nix @@ -19,6 +19,14 @@ in ''; example = "DroidSansMono NF"; }; + font.size = myLib.mkOption { + type = myLib.types.number; + default = actualConfig.font.size; + description = '' + The default font size for Alacritty. This is probably measured in px. + ''; + example = 7.0; + }; enable = myLib.mkOption { type = myLib.types.bool; default = true; @@ -45,6 +53,7 @@ in enable = cfg.enable; settings = myLib.recursiveUpdate actualConfig { font.normal.family = cfg.font.family; + font.size = cfg.font.size; }; }; } diff --git a/nix-conf/home-manager/base/git.nix b/nix-conf/home-manager/base/git.nix index c9eec86..cd57aa7 100644 --- a/nix-conf/home-manager/base/git.nix +++ b/nix-conf/home-manager/base/git.nix @@ -44,6 +44,7 @@ in default = [ ".vscode" # vscode settings ".direnv" # .envrc cached outputs + ".DS_Store" # MacOS users, amrite ]; description = '' .gitignore patterns that are applied in every repository. diff --git a/nix-conf/home-manager/flake.lock b/nix-conf/home-manager/flake.lock index f3543ff..5a63f17 100644 --- a/nix-conf/home-manager/flake.lock +++ b/nix-conf/home-manager/flake.lock @@ -180,7 +180,7 @@ }, "locked": { "lastModified": 1, - "narHash": "sha256-GgIXbuHvwReBHZUyfSKS6DET3CfD6EEKABj6ndpcqHQ=", + "narHash": "sha256-RkO+8E7MahERHw1C5DNObDjq4xeI+FqaWH9+M7Fv2UE=", "path": "./../../out-of-tree/nixGL", "type": "path" }, @@ -270,11 +270,11 @@ "nixpkgs": "nixpkgs_4" }, "locked": { - "lastModified": 1673490397, - "narHash": "sha256-VCSmIYJy/ZzTvEGjdfITmTYfybXBgZpMjyjDndbou+8=", + "lastModified": 1673576998, + "narHash": "sha256-I6vYVejEWTao+Ze/F6VFSTFxu6/X2OPT3Eu4AM/zzec=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "0833f4d063a2bb75aa31680f703ba594a384ffe6", + "rev": "ca474ccdd5f81ed742328e15dae38bb57a1006e3", "type": "github" }, "original": { diff --git a/nix-conf/home-manager/flake.nix b/nix-conf/home-manager/flake.nix index 6950948..50b196f 100644 --- a/nix-conf/home-manager/flake.nix +++ b/nix-conf/home-manager/flake.nix @@ -62,7 +62,7 @@ base = import ./base; inherit (base) mkModuleArgs; - kde_module = { config, pkgs, ... }: { + nerd_font_module = { config, pkgs, ... }: { fonts.fontconfig.enable = true; home.packages = [ (pkgs.nerdfonts.override { fonts = [ "DroidSansMono" ]; }) @@ -105,7 +105,7 @@ inherit pkgs; modules = base.modules ++ [ ./home.nix - kde_module + nerd_font_module ./base/productive_desktop.nix { # since home.nix forces us to use keepass, and base.keepass.path @@ -129,14 +129,17 @@ }; "htran" = home-manager.lib.homeManagerConfiguration { inherit pkgs; - modules = [ + modules = base.modules ++ [ ./home.nix { base.graphics.enable = false; - base.graphics.useNixGL.defaultPackage = null; - base.keepass.path = "/Users/htran/keepass.kdbx"; # don't want to deal with GL stuffs on mac yet :/ + base.graphics.useNixGL.defaultPackage = null; + # NOTE: this actually does not exist + base.keepass.path = "/Users/htran/keepass.kdbx"; + base.alacritty.font.size = 11.0; } + nerd_font_module ]; extraSpecialArgs = mkModuleArgs { inherit pkgs; diff --git a/scripts/hm-switch.sh b/scripts/hm-switch.sh index e88df6e..2c41ad5 100755 --- a/scripts/hm-switch.sh +++ b/scripts/hm-switch.sh @@ -24,7 +24,7 @@ rm -rf ~/.local/share/nvim/mason # test if we have home-manager, if not, attempt to use nix to put home-manager to # our environment -if [ $(home-manager help >/dev/null 2>&1) ]; then +if ! command -v home-manager ; then nix-shell -p home-manager --run "home-manager switch --flake $HOME_MANAGER_DIR $@" else home-manager switch -b backup --flake "$HOME_MANAGER_DIR" $@ -- 2.42.0 From 8734707ab673a93ac8b4942cc5f397fa8d9890ba Mon Sep 17 00:00:00 2001 From: Pegasust Date: Sun, 15 Jan 2023 00:45:51 -0800 Subject: [PATCH 3/5] hungtran: another darwin that's more open to hardware mods --- flake.lock | 12 +++--- nix-conf/home-manager/flake.lock | 66 ++++++++++++++++++++------------ nix-conf/home-manager/flake.nix | 24 +++++++++++- 3 files changed, 71 insertions(+), 31 deletions(-) diff --git a/flake.lock b/flake.lock index 2a3ea53..277ba5c 100644 --- a/flake.lock +++ b/flake.lock @@ -117,11 +117,11 @@ "utils": "utils" }, "locked": { - "lastModified": 1673343300, - "narHash": "sha256-5Xdj6kpXYMie0MlnGwqK5FaMdsedxvyuakWtyKB3zaQ=", + "lastModified": 1673737886, + "narHash": "sha256-hNTqD0uIgpbtTI2Nuj/Q1lEFOOdZqqXpxoc8rMno2F0=", "owner": "nix-community", "repo": "home-manager", - "rev": "176e455371a8371586e8a3ff0d56ee9f3ca2324e", + "rev": "2827b5306462d91edec16a3d069b2d6e54c3079f", "type": "github" }, "original": { @@ -259,11 +259,11 @@ }, "nixpkgs_3": { "locked": { - "lastModified": 1673540789, - "narHash": "sha256-xqnxBOK3qctIeUVxecydrEDbEXjsvHCPGPbvsl63M/U=", + "lastModified": 1673631141, + "narHash": "sha256-AprpYQ5JvLS4wQG/ghm2UriZ9QZXvAwh1HlgA/6ZEVQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "0f213d0fee84280d8c3a97f7469b988d6fe5fcdf", + "rev": "befc83905c965adfd33e5cae49acb0351f6e0404", "type": "github" }, "original": { diff --git a/nix-conf/home-manager/flake.lock b/nix-conf/home-manager/flake.lock index 5a63f17..9f1aa9f 100644 --- a/nix-conf/home-manager/flake.lock +++ b/nix-conf/home-manager/flake.lock @@ -3,17 +3,14 @@ "flake-compat": { "flake": false, "locked": { - "lastModified": 1668681692, - "narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "009399224d5e398d03b22badca40a37ac85412a1", - "type": "github" + "lastModified": 1, + "narHash": "sha256-d6CilJXP+UPv3nF00zBBRhMgRklTCjSCMrjbYtYDuOI=", + "path": "../../out-of-tree/flake-compat", + "type": "path" }, "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" + "path": "../../out-of-tree/flake-compat", + "type": "path" } }, "flake-compat_2": { @@ -100,11 +97,11 @@ "utils": "utils" }, "locked": { - "lastModified": 1673343300, - "narHash": "sha256-5Xdj6kpXYMie0MlnGwqK5FaMdsedxvyuakWtyKB3zaQ=", + "lastModified": 1673737886, + "narHash": "sha256-hNTqD0uIgpbtTI2Nuj/Q1lEFOOdZqqXpxoc8rMno2F0=", "owner": "nix-community", "repo": "home-manager", - "rev": "176e455371a8371586e8a3ff0d56ee9f3ca2324e", + "rev": "2827b5306462d91edec16a3d069b2d6e54c3079f", "type": "github" }, "original": { @@ -139,11 +136,11 @@ }, "locked": { "dir": "contrib", - "lastModified": 1673504032, - "narHash": "sha256-x4nv7g8+bQXg5PfkFw3vCcr3pYI0Hco0VoSbAy60xek=", + "lastModified": 1673683108, + "narHash": "sha256-zg1W14wyrOCKiTkXU+nGHf/EfqX6wtcUWcMo4O/Q6nY=", "owner": "neovim", "repo": "neovim", - "rev": "143d3f1f3224bca02bfef7df0932b9d7524a3ff2", + "rev": "e89c39d6f016a4140293755250e968e839009617", "type": "github" }, "original": { @@ -160,11 +157,11 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1673511313, - "narHash": "sha256-QGUT3w1bHclVRqX958EPOd3OxR/R10MoV97N5jx/qbw=", + "lastModified": 1673684013, + "narHash": "sha256-ljfG17g9K5sl7DGounCwOIfQLOGzXF0ffuDGxo3UN1E=", "owner": "nix-community", "repo": "neovim-nightly-overlay", - "rev": "5af6fe31f9906e70a1e8985dbbdcc4ae66c7f82d", + "rev": "85b0900729bffa5e0d1817bbc6f024916dc1f38e", "type": "github" }, "original": { @@ -173,6 +170,26 @@ "type": "github" } }, + "nix-index-database": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1673365945, + "narHash": "sha256-/duo8kCEbo62D5gn46m//jfvRtT56KS5dy+j6+Rl+4Y=", + "owner": "mic92", + "repo": "nix-index-database", + "rev": "0e51ff44d6bef0b6b2bbf9e34fdc029fc24820fc", + "type": "github" + }, + "original": { + "owner": "mic92", + "repo": "nix-index-database", + "type": "github" + } + }, "nixgl": { "inputs": { "flake-utils": "flake-utils_3", @@ -222,11 +239,11 @@ }, "nixpkgs_3": { "locked": { - "lastModified": 1673450908, - "narHash": "sha256-b8em+kwrNtnB7gR8SyVf6WuTyQ+6tHS6dzt9D9wgKF0=", + "lastModified": 1673631141, + "narHash": "sha256-AprpYQ5JvLS4wQG/ghm2UriZ9QZXvAwh1HlgA/6ZEVQ=", "owner": "nixos", "repo": "nixpkgs", - "rev": "6c8644fc37b6e141cbfa6c7dc8d98846c4ff0c2e", + "rev": "befc83905c965adfd33e5cae49acb0351f6e0404", "type": "github" }, "original": { @@ -259,6 +276,7 @@ "home-manager": "home-manager", "kpcli-py": "kpcli-py", "neovim-nightly-overlay": "neovim-nightly-overlay", + "nix-index-database": "nix-index-database", "nixgl": "nixgl", "nixpkgs": "nixpkgs_3", "rust-overlay": "rust-overlay" @@ -270,11 +288,11 @@ "nixpkgs": "nixpkgs_4" }, "locked": { - "lastModified": 1673576998, - "narHash": "sha256-I6vYVejEWTao+Ze/F6VFSTFxu6/X2OPT3Eu4AM/zzec=", + "lastModified": 1673662873, + "narHash": "sha256-/YOtiDKPUXKKpIhsAds11llfC42ScGW27bbHnNZebco=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "ca474ccdd5f81ed742328e15dae38bb57a1006e3", + "rev": "90163bbbadce526f8b248a5fe545b06c59597108", "type": "github" }, "original": { diff --git a/nix-conf/home-manager/flake.nix b/nix-conf/home-manager/flake.nix index 50b196f..e461ad6 100644 --- a/nix-conf/home-manager/flake.nix +++ b/nix-conf/home-manager/flake.nix @@ -11,7 +11,7 @@ rust-overlay.url = "github:oxalica/rust-overlay"; # Allows default.nix to call onto flake.nix. Useful for nix eval and automations flake-compat = { - url = "github:edolstra/flake-compat"; + url = "path:../../out-of-tree/flake-compat"; flake = false; }; kpcli-py = { @@ -127,6 +127,28 @@ }; }; }; + "hungtran" = home-manager.lib.homeManagerConfiguration { + inherit pkgs; + modules = base.modules ++ [ + ./home.nix + { + base.graphics.enable = false; + # don't want to deal with GL stuffs on mac yet :/ + base.graphics.useNixGL.defaultPackage = null; + # NOTE: this actually does not exist + base.keepass.path = "/Users/htran/keepass.kdbx"; + base.alacritty.font.size = 11.0; + } + nerd_font_module + ]; + extraSpecialArgs = mkModuleArgs { + inherit pkgs; + myHome = { + username = "hungtran"; + homeDirectory = "/Users/hungtran"; + }; + }; + }; "htran" = home-manager.lib.homeManagerConfiguration { inherit pkgs; modules = base.modules ++ [ -- 2.42.0 From a0dae5b3a0ba1ce0b4e5e7861bcc439e6d923635 Mon Sep 17 00:00:00 2001 From: Pegasust Date: Sun, 15 Jan 2023 01:54:40 -0800 Subject: [PATCH 4/5] add nix-index-database --- c_.nix | 100 +++++++++++++++++++++++++ default.nix | 10 +-- flake.lock | 24 +++--- flake.nix | 3 + nix-conf/home-manager/base/default.nix | 5 +- nix-conf/home-manager/flake.nix | 6 +- scripts/hm-switch.sh | 2 +- shell.nix | 8 +- 8 files changed, 133 insertions(+), 25 deletions(-) create mode 100644 c_.nix diff --git a/c_.nix b/c_.nix new file mode 100644 index 0000000..8e787e9 --- /dev/null +++ b/c_.nix @@ -0,0 +1,100 @@ +# a small helper that only builds on top of builtins functions +{src}@inputs: +builtins // (let +formatSecondsSinceEpoch = t: +let +rem = x: y: x - x / y * y; +days = t / 86400; +secondsInDay = rem t 86400; +hours = secondsInDay / 3600; +minutes = (rem secondsInDay 3600) / 60; +seconds = rem t 60; + +# Courtesy of https://stackoverflow.com/a/32158604. +z = days + 719468; +era = (if z >= 0 then z else z - 146096) / 146097; +doe = z - era * 146097; +yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365; +y = yoe + era * 400; +doy = doe - (365 * yoe + yoe / 4 - yoe / 100); +mp = (5 * doy + 2) / 153; +d = doy - (153 * mp + 2) / 5 + 1; +m = mp + (if mp < 10 then 3 else -9); +y' = y + (if m <= 2 then 1 else 0); + +pad = s: if builtins.stringLength s < 2 then "0" + s else s; +in "${toString y'}${pad (toString m)}${pad (toString d)}${pad (toString hours)}" ++ "${pad (toString minutes)}${pad (toString seconds)}"; + +fetchTree = +# this is the value of flake.lock#lock.nodes.${input_name}.locked +{type +, host? "" +, owner? "" +, repo? "" +, rev? "" +, submodules? "" +, path? "" +, narHash? null +, lastModified? 0 +}@info: +if info.type == "github" then +{ outPath = + fetchTarball + ({ url = "https://api.${info.host or "github.com"}/repos/" + + "${info.owner}/${info.repo}/tarball/${info.rev}"; } + // (if info ? narHash then { sha256 = info.narHash; } else {}) + ); + rev = info.rev; + shortRev = builtins.substring 0 7 info.rev; + lastModified = info.lastModified; + lastModifiedDate = formatSecondsSinceEpoch info.lastModified; + narHash = info.narHash; +} +else if info.type == "git" then +{ outPath = + builtins.fetchGit + ({ url = info.url; } + // (if info ? rev then { inherit (info) rev; } else {}) + // (if info ? ref then { inherit (info) ref; } else {}) + // (if info ? submodules then { inherit (info) submodules; } else {}) + ); + lastModified = info.lastModified; + lastModifiedDate = formatSecondsSinceEpoch info.lastModified; + narHash = info.narHash; +} // (if info ? rev then { +rev = info.rev; +shortRev = builtins.substring 0 7 info.rev; +} else { +}) +else if info.type == "path" then +{ outPath = builtins.path { + path = if builtins.substring 0 1 info.path != "/" + then src + ("/" + info.path) # make this absolute path by prepending ./ + else info.path; # it's already an absolute path + }; +narHash = info.narHash; +} +else if info.type == "tarball" then +{ outPath = + fetchTarball + ({ inherit (info) url; } + // (if info ? narHash then { sha256 = info.narHash; } else {}) + ); +} +else if info.type == "gitlab" then +{ inherit (info) rev narHash lastModified; + outPath = + fetchTarball + ({ url = "https://${info.host or "gitlab.com"}/api/v4/projects/${info.owner}%2F${info.repo}/repository/archive.tar.gz?sha=${info.rev}"; } + // (if info ? narHash then { sha256 = info.narHash; } else {}) + ); + shortRev = builtins.substring 0 7 info.rev; +} +else +# FIXME: add Mercurial, tarball inputs. +throw "flake input has unsupported input type '${info.type}'"; +in { + inherit fetchTree; +}) + diff --git a/default.nix b/default.nix index 3fa0b39..9004ce7 100644 --- a/default.nix +++ b/default.nix @@ -1,11 +1,11 @@ # We use top-level nix-flake, so default.nix is basically just a wrapper around ./flake.nix (import ( - let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in - fetchTarball { - url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; - sha256 = lock.nodes.flake-compat.locked.narHash; - } + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + c_ = import ./c_.nix {src = ./.;}; + in + c_.fetchTree lock.nodes.flake-compat.locked ) { src = ./.; } ).defaultNix diff --git a/flake.lock b/flake.lock index 277ba5c..112842d 100644 --- a/flake.lock +++ b/flake.lock @@ -156,11 +156,11 @@ }, "locked": { "dir": "contrib", - "lastModified": 1673683108, - "narHash": "sha256-zg1W14wyrOCKiTkXU+nGHf/EfqX6wtcUWcMo4O/Q6nY=", + "lastModified": 1673746461, + "narHash": "sha256-Y21pbVNlPWPokXFbngSahnxeCff0LX+LKdDktEBIVm4=", "owner": "neovim", "repo": "neovim", - "rev": "e89c39d6f016a4140293755250e968e839009617", + "rev": "6134c1e8a39a5e61d0593613343a5923a86e3545", "type": "github" }, "original": { @@ -177,11 +177,11 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1673684013, - "narHash": "sha256-ljfG17g9K5sl7DGounCwOIfQLOGzXF0ffuDGxo3UN1E=", + "lastModified": 1673770422, + "narHash": "sha256-hYVEUzvqobxAM2FZfWTrTLKKNfkOSfsm0uGqNoSiIvw=", "owner": "nix-community", "repo": "neovim-nightly-overlay", - "rev": "85b0900729bffa5e0d1817bbc6f024916dc1f38e", + "rev": "fd8e5953cfeada345d7daeedce6ab0919f1284d4", "type": "github" }, "original": { @@ -197,11 +197,11 @@ ] }, "locked": { - "lastModified": 1673365945, - "narHash": "sha256-/duo8kCEbo62D5gn46m//jfvRtT56KS5dy+j6+Rl+4Y=", + "lastModified": 1673752441, + "narHash": "sha256-/g4ImZWV05CrXRWTSJsda6ztIp7LAPxs2L6RCrbQ66U=", "owner": "mic92", "repo": "nix-index-database", - "rev": "0e51ff44d6bef0b6b2bbf9e34fdc029fc24820fc", + "rev": "391180f77505c1c8cdd45fe1a59dc89d3e40300a", "type": "github" }, "original": { @@ -308,11 +308,11 @@ "nixpkgs": "nixpkgs_4" }, "locked": { - "lastModified": 1673662873, - "narHash": "sha256-/YOtiDKPUXKKpIhsAds11llfC42ScGW27bbHnNZebco=", + "lastModified": 1673749717, + "narHash": "sha256-hgrw8w/AThRWfVafx3EO3/TQlGcUou4nui8X47cVhXo=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "90163bbbadce526f8b248a5fe545b06c59597108", + "rev": "aab6eb2dfc7a1e42d94b6f24ef13639ff8544af4", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 43bcfae..19ce7a9 100644 --- a/flake.nix +++ b/flake.nix @@ -1,4 +1,7 @@ { + nixConfig = { + + }; description = "My personal configuration in Nix (and some native configurations)"; inputs = { nixpkgs.url = "nixpkgs/nixos-unstable"; diff --git a/nix-conf/home-manager/base/default.nix b/nix-conf/home-manager/base/default.nix index a64a7a1..d3a0d50 100644 --- a/nix-conf/home-manager/base/default.nix +++ b/nix-conf/home-manager/base/default.nix @@ -1,4 +1,6 @@ -{ +{nix-index-database +,... +}@inputs:{ mkModuleArgs = import ./mkModuleArgs.nix; modules = [ ./alacritty.nix @@ -8,5 +10,6 @@ { config.programs.home-manager.enable = true; } + nix-index-database.hmModules.nix-index ]; } diff --git a/nix-conf/home-manager/flake.nix b/nix-conf/home-manager/flake.nix index e461ad6..3bc3e2d 100644 --- a/nix-conf/home-manager/flake.nix +++ b/nix-conf/home-manager/flake.nix @@ -1,4 +1,8 @@ { + nixConfig = { + accept-flake-config = true; + experimental-features = "nix-command flakes"; + }; description = "simple home-manager config"; inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; @@ -59,7 +63,7 @@ config = { allowUnfree = true; }; }; # lib = (import ../lib { inherit pkgs; lib = pkgs.lib; }); - base = import ./base; + base = import ./base flake_inputs; inherit (base) mkModuleArgs; nerd_font_module = { config, pkgs, ... }: { diff --git a/scripts/hm-switch.sh b/scripts/hm-switch.sh index 2c41ad5..b99a7ac 100755 --- a/scripts/hm-switch.sh +++ b/scripts/hm-switch.sh @@ -2,7 +2,7 @@ # NOTE: Untested on case of no home-manager set -xv # Where this script located -SCRIPT_DIR=$(realpath $(dirname $0)) +SCRIPT_DIR=$(readlink -f $(dirname $0)) echo "SCRIPT_DIR: ${SCRIPT_DIR}" HOME_MANAGER_DIR="${SCRIPT_DIR}/../nix-conf/home-manager" diff --git a/shell.nix b/shell.nix index 7409f9a..0995f35 100644 --- a/shell.nix +++ b/shell.nix @@ -3,11 +3,9 @@ # This architecture is because we use top-level flake.nix (import ( - let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in - fetchTarball { - url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; - sha256 = lock.nodes.flake-compat.locked.narHash; - } + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + in (import ./c_.nix {src = ./.;}).fetchTree lock.nodes.flake-compat.locked ) { src = ./.; } ).shellNix -- 2.42.0 From 97fd1543df71edb981f5347283e02b5e27bf066a Mon Sep 17 00:00:00 2001 From: Pegasust Date: Sun, 15 Jan 2023 04:48:11 -0800 Subject: [PATCH 5/5] nixops ok now --- native_configs/neovim/init.lua | 80 +++++++++++++++++++------------- nix-conf/home-manager/flake.lock | 24 +++++----- nix-conf/home-manager/home.nix | 2 +- 3 files changed, 60 insertions(+), 46 deletions(-) diff --git a/native_configs/neovim/init.lua b/native_configs/neovim/init.lua index b29fbdd..b64314e 100644 --- a/native_configs/neovim/init.lua +++ b/native_configs/neovim/init.lua @@ -10,7 +10,6 @@ -- - zk @ https://github.com/mickael-menu/zk -- - prettierd @ npm install -g @fsouza/prettierd -local data_dir = vim.fn.stdpath('data') vim.cmd([[ let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim' let plug_path = data_dir . '/autoload/plug.vim' @@ -24,11 +23,6 @@ local function truthy(v) return v ~= nil end local function cfg(cfg_var, do_fn) if truthy(cfg_var) then do_fn() end end -local function cfg_render(do_fn) - local should_render = not truthy(os.getenv("NVIM_HEADLESS")) - cfg(should_render, do_fn) -end - -- vim-plug local Plug = vim.fn['plug#'] @@ -87,15 +81,13 @@ Plug('kylechui/nvim-surround') -- surrounds with tags/parenthesis Plug('simrat39/rust-tools.nvim') -- config rust-analyzer and nvim integration -- UI & colorscheme -cfg_render(function() - Plug('simrat39/inlay-hints.nvim') -- type-hints with pseudo-virtual texts - Plug('gruvbox-community/gruvbox') -- theme provider - Plug('nvim-lualine/lualine.nvim') -- fancy status line - Plug('lukas-reineke/indent-blankline.nvim') -- identation lines on blank lines - Plug('kyazdani42/nvim-web-devicons') -- icons for folder and filetypes - Plug('m-demare/hlargs.nvim') -- highlights arguments; great for func prog - Plug('folke/todo-comments.nvim') -- Highlights TODO -end) +Plug('simrat39/inlay-hints.nvim') -- type-hints with pseudo-virtual texts +Plug('gruvbox-community/gruvbox') -- theme provider +Plug('nvim-lualine/lualine.nvim') -- fancy status line +Plug('lukas-reineke/indent-blankline.nvim') -- identation lines on blank lines +Plug('kyazdani42/nvim-web-devicons') -- icons for folder and filetypes +Plug('m-demare/hlargs.nvim') -- highlights arguments; great for func prog +Plug('folke/todo-comments.nvim') -- Highlights TODO -- other utilities Plug('nvim-treesitter/nvim-treesitter', { run = ':TSUpdate' }) @@ -139,30 +131,52 @@ vim.api.nvim_create_autocmd({ "VimEnter" }, { }) -vim.cmd([[ -set ignorecase -set smartcase -set incsearch -set number relativenumber -set tabstop=4 softtabstop=4 -set autoindent -set smartindent -set expandtab -set shiftwidth=4 -set exrc -set incsearch -set scrolloff=30 -set signcolumn=yes -set colorcolumn=80 -set background=light -]]) +vim.g.gruvbox_contrast_dark="soft"; +vim.g.gruvbox_contrast_light="soft"; +vim.opt.ignorecase = true; +vim.opt.smartcase = true; +vim.opt.incsearch = true; +vim.opt.number = true; +vim.opt.relativenumber = true; +vim.opt.autoindent = true; +vim.opt.smartindent = true; +vim.opt.expandtab = true; +vim.opt.exrc = true; + +vim.opt.tabstop = 4; +vim.opt.softtabstop = 4; +vim.opt.shiftwidth = 4; +vim.opt.scrolloff = 30; +vim.opt.signcolumn = "yes"; +vim.opt.colorcolumn = "80"; + +vim.opt.background = "light"; + +vim.api.nvim_create_user_command('Dark', function(opts) + -- opts: {name, args: str, fargs: Splited, range, ...} + ---@type string + local contrast = (opts.args and string.len(opts.args) > 0) and opts.args or vim.g.gruvbox_contrast_dark; + vim.g.gruvbox_contrast_dark = contrast; + vim.opt.background = "dark"; +end, + {nargs = "?";}) + +vim.api.nvim_create_user_command('Light', function(opts) + -- opts: {name, args: str, fargs: Splited, range, ...} + ---@type string + local contrast = (opts.args and string.len(opts.args) > 0) and opts.args or vim.g.gruvbox_contrast_dark; + vim.g.gruvbox_contrast_light = contrast; + vim.opt.background = "light"; +end, + {nargs = "?";}) + vim.opt.lazyredraw = true vim.opt.termguicolors = true vim.opt.cursorline = true -- some plugins misbehave when we do swap files vim.opt.swapfile = false vim.opt.backup = false -vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir" +vim.opt.undodir = vim.fn.stdpath('state')..'/.vim/undodir' vim.opt.undofile = true vim.opt.completeopt = 'menuone,noselect' -- vim.opt.clipboard = "unnamedplus" diff --git a/nix-conf/home-manager/flake.lock b/nix-conf/home-manager/flake.lock index 9f1aa9f..141ce3e 100644 --- a/nix-conf/home-manager/flake.lock +++ b/nix-conf/home-manager/flake.lock @@ -136,11 +136,11 @@ }, "locked": { "dir": "contrib", - "lastModified": 1673683108, - "narHash": "sha256-zg1W14wyrOCKiTkXU+nGHf/EfqX6wtcUWcMo4O/Q6nY=", + "lastModified": 1673746461, + "narHash": "sha256-Y21pbVNlPWPokXFbngSahnxeCff0LX+LKdDktEBIVm4=", "owner": "neovim", "repo": "neovim", - "rev": "e89c39d6f016a4140293755250e968e839009617", + "rev": "6134c1e8a39a5e61d0593613343a5923a86e3545", "type": "github" }, "original": { @@ -157,11 +157,11 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1673684013, - "narHash": "sha256-ljfG17g9K5sl7DGounCwOIfQLOGzXF0ffuDGxo3UN1E=", + "lastModified": 1673770422, + "narHash": "sha256-hYVEUzvqobxAM2FZfWTrTLKKNfkOSfsm0uGqNoSiIvw=", "owner": "nix-community", "repo": "neovim-nightly-overlay", - "rev": "85b0900729bffa5e0d1817bbc6f024916dc1f38e", + "rev": "fd8e5953cfeada345d7daeedce6ab0919f1284d4", "type": "github" }, "original": { @@ -177,11 +177,11 @@ ] }, "locked": { - "lastModified": 1673365945, - "narHash": "sha256-/duo8kCEbo62D5gn46m//jfvRtT56KS5dy+j6+Rl+4Y=", + "lastModified": 1673752441, + "narHash": "sha256-/g4ImZWV05CrXRWTSJsda6ztIp7LAPxs2L6RCrbQ66U=", "owner": "mic92", "repo": "nix-index-database", - "rev": "0e51ff44d6bef0b6b2bbf9e34fdc029fc24820fc", + "rev": "391180f77505c1c8cdd45fe1a59dc89d3e40300a", "type": "github" }, "original": { @@ -288,11 +288,11 @@ "nixpkgs": "nixpkgs_4" }, "locked": { - "lastModified": 1673662873, - "narHash": "sha256-/YOtiDKPUXKKpIhsAds11llfC42ScGW27bbHnNZebco=", + "lastModified": 1673749717, + "narHash": "sha256-hgrw8w/AThRWfVafx3EO3/TQlGcUou4nui8X47cVhXo=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "90163bbbadce526f8b248a5fe545b06c59597108", + "rev": "aab6eb2dfc7a1e42d94b6f24ef13639ff8544af4", "type": "github" }, "original": { diff --git a/nix-conf/home-manager/home.nix b/nix-conf/home-manager/home.nix index 6fc5db7..b338fcc 100644 --- a/nix-conf/home-manager/home.nix +++ b/nix-conf/home-manager/home.nix @@ -37,7 +37,7 @@ in # pkgs.xorg.xclock # TODO: only include if have gui # For testing GL installation # pkgs.logseq # TODO: only include if have GL # Obsidian alt pkgs.mosh # Parsec for SSH - # pkgs.nixops_unstable # nixops v2 # insecure for now + pkgs.nixops_unstable # nixops v2 # insecure for now pkgs.lynx # Web browser at your local terminal pkgs.zk -- 2.42.0