From f2dae2ee812ceb27abb2bb70788e8a558170bf17 Mon Sep 17 00:00:00 2001 From: "Lennart J. Kurzweg (Nx2)" Date: Tue, 13 Jan 2026 00:35:27 +0100 Subject: [PATCH] massive refactor --- configuration.nix | 8 +- flake-modules/allowed.nix | 70 +++++++-------- flake-modules/colors.json | 22 ++--- flake-modules/hyper.nix | 35 ++++++++ flake-modules/nvidia.nix | 4 - flake-modules/nxlib/ricelib.nix | 43 ++++++++++ flake-modules/pkgs.nix | 29 +++++++ flake-modules/rice.nix | 15 +--- flake.nix | 123 ++++++++------------------- home-modules/bar/caldav-event.nix | 2 + home-modules/gimp.nix | 8 +- home-modules/nx2site-backup.nix | 3 +- home-modules/wallpaper-to-colors.nix | 15 ++-- home.nix | 2 +- nxlib/ricelib.nix | 96 --------------------- shell-only.nix | 2 +- system-modules/nix.nix | 14 +++ 17 files changed, 223 insertions(+), 268 deletions(-) create mode 100644 flake-modules/hyper.nix delete mode 100644 flake-modules/nvidia.nix create mode 100644 flake-modules/nxlib/ricelib.nix create mode 100644 flake-modules/pkgs.nix delete mode 100644 nxlib/ricelib.nix create mode 100644 system-modules/nix.nix diff --git a/configuration.nix b/configuration.nix index 7615250..1b54472 100644 --- a/configuration.nix +++ b/configuration.nix @@ -23,6 +23,7 @@ ./system-modules/kodi.nix ./system-modules/networking.nix ./system-modules/nixd.nix + ./system-modules/nix.nix ./system-modules/nvidia.nix ./system-modules/obs.nix ./system-modules/ollama.nix @@ -57,12 +58,11 @@ ./system-modules/calendar/lec.nix ./system-modules/calendar/lr.nix ./system-modules/calendar/dicos.nix - ] else [ - ]); + ] else [ ]); environment.systemPackages = import ./system-modules/base-packages.nix pkgs; - system.stateVersion = hyper.pkgs-version; - nix.settings.experimental-features = [ "nix-command" "flakes" ]; + system.stateVersion = hyper.main-pkgs-version; + programs.bash.shellInit = '' if [[ "$USER" == "${hyper.user}" ]]; then source $HOME/.nix-profile/etc/profile.d/hm-session-vars.sh diff --git a/flake-modules/allowed.nix b/flake-modules/allowed.nix index f6bee5c..6762484 100644 --- a/flake-modules/allowed.nix +++ b/flake-modules/allowed.nix @@ -1,43 +1,31 @@ -{ - unfree = [ - "antigravity" - "cursor" - "discord" - "spotify" - "obsidian" - "steam" - "steam-unwrapped" - "zoom-us" - "zoom" +pkgs: rec { + predicate = pkg: ( + builtins.elem (pkgs.lib.getName pkg) unfree.packages || builtins.all ( + license: license.free || builtins.elem license.shortName unfree.licenses + ) (if builtins.isList pkg.meta.license then pkg.meta.license else [ pkg.meta.license ]) + ); + unfree = { + packages = [ + "antigravity" + "cursor" + "discord" + "obsidian" + "spotify" + "steam" + "steam-unwrapped" + "vscode-extension-mhutchie-git-graph" + "zoom" + "zoom-us" - "nvidia-x11" - "nvidia-settings" - "nvidia-persistenced" - "cudatoolkit" - "cuda-merged" - "cuda_cuobjdump" - "cuda_gdb" - "cuda_nvcc" - "cuda_nvdisasm" - "cuda_nvprune" - "cuda_cccl" - "cuda_cudart" - "cuda_cupti" - "cuda_cuxxfilt" - "cuda_nvml_dev" - "cuda_nvrtc" - "cuda_nvtx" - "cuda_profiler_api" - "cuda_sanitizer_api" - "libcublas" - "libcufft" - "libcurand" - "libcusolver" - "libnvjitlink" - "libcusparse" - "libnpp" - - "vscode-extension-mhutchie-git-graph" - ]; - insecure = [ ]; + "nvidia-x11" + "nvidia-settings" + ]; + licenses = [ + "CUDA EULA" + "cuDNN EULA" + "cuTENSOR EULA" + "NVidia OptiX EULA" + ]; + }; + # insecure = [ ]; } diff --git a/flake-modules/colors.json b/flake-modules/colors.json index fe04d93..84f79bf 100644 --- a/flake-modules/colors.json +++ b/flake-modules/colors.json @@ -1,13 +1,15 @@ { - "base": { - "foreground": "#eedce1", - "background": "#11080a" - }, - "to_alter": { - "accent": "#bb768a", - "secondary": "#b5ff32", - "tertiary": "#918ea3", - "special": "#76bba7", - "weird": "#b7bb76" + "NxXPS": { + "base": { + "foreground": "#fecccc", + "background": "#190000" + }, + "to_alter": { + "accent": "#ff3232", + "secondary": "#ff3232", + "tertiary": "#ff3232", + "special": "#31feff", + "weird": "#baff31" + } } } \ No newline at end of file diff --git a/flake-modules/hyper.nix b/flake-modules/hyper.nix new file mode 100644 index 0000000..90592ab --- /dev/null +++ b/flake-modules/hyper.nix @@ -0,0 +1,35 @@ +let hyper-base = rec { + host = "BaseHost"; + system = "x86_64-linux"; + user = "nx2"; + domain = "nx2.site"; + home = "/home/${user}"; + webroot = if isServer then "/var/lib/hugo/nx2site/public" else assert false "No webroot on non-servers"; ""; + main-pkgs-version = "25.11"; + isServer = false; + isMobile = false; + isNOD = false; + nvidia = { + enable = false; + prime = false; + }; +}; in host: if host == "NxNORTH" then hyper-base // { inherit host; + nvidia.enable = true; +} else if host == "NxXPS" then hyper-base // { inherit host; + nvidia = { + enable = true; + prime = true; + }; + isMobile = true; +} else if host == "NxACE" then hyper-base // { inherit host; + isServer = true; +} else if host == "NxDCS" then hyper-base // { inherit host; + isMobile = true; +} else if host == "NxS23U" then hyper-base // { inherit host; + isMobile = true; + isNOD = true; + main-pkgs-version = "24.05"; + system = "aarch64-linux"; + user = "nix-on-droid"; + home = "/data/data/com.termux.nix/files/home"; +} else assert false "unkown host"; {} \ No newline at end of file diff --git a/flake-modules/nvidia.nix b/flake-modules/nvidia.nix deleted file mode 100644 index b252a7f..0000000 --- a/flake-modules/nvidia.nix +++ /dev/null @@ -1,4 +0,0 @@ -{ - enable = false; - prime = false; -} diff --git a/flake-modules/nxlib/ricelib.nix b/flake-modules/nxlib/ricelib.nix new file mode 100644 index 0000000..5d3c65b --- /dev/null +++ b/flake-modules/nxlib/ricelib.nix @@ -0,0 +1,43 @@ +lib: let + # takes in "ff0044" (no hash!) and returns { r = "ff", g = "00", b = "44" } + slice-hex = hex: with builtins; { r = substring 0 2 hex; g = substring 2 2 hex; b = substring 4 2 hex; }; + + # takes in "44" and returns 64 + drune-to-255 = drune: with builtins; (rune-to-num (substring 0 1 drune)) * 16 + (rune-to-num (substring 1 1 drune)); + num-to-drune = num: "${num-to-rune (num / 16)}${num-to-rune (num - ((num / 16) * 16))}"; + + # takes in "D" and returns 13 + # inspiration from https://github.com/bertof/nix-rice + rune-to-num = rune: let + dict = { "0" = 0; "1" = 1; "2" = 2; "3" = 3; "4" = 4; "5" = 5; "6" = 6; "7" = 7; "8" = 8; "9" = 9; "A" = 10; "B" = 11; "C" = 12; "D" = 13; "E" = 14; "F" = 15; }; + in assert(builtins.hasAttr (lib.strings.toUpper rune) dict); builtins.getAttr (lib.strings.toUpper rune) dict; + + # takes in 15 and returns "F" + num-to-rune = num: let + num-string = builtins.toString num; + dict = { "0" = "0"; "1" = "1"; "2" = "2"; "3" = "3"; "4" = "4"; "5" = "5"; "6" = "6"; "7" = "7"; "8" = "8"; "9" = "9"; "10" = "A"; "11" = "B"; "12" = "C"; "13" = "D"; "14" = "E"; "15" = "F"; }; + in assert(builtins.hasAttr num-string dict); builtins.getAttr num-string dict; + + # Keeps num between 0 and 255 + # Make sure to pass in an int not a float + cap-255 = num: (if (num>255) then 255 else if (num<0) then 0 else num); + nohash = hex: with builtins; assert((stringLength hex) == 7); substring 1 6 hex; +in { + ## USEFUL FUNCTIONS + # takes in a string like "#ff0044" and returns "ff0044" symbol + inherit nohash; + + # This takes in something like "#ff0044" and returns "255,0,64" + hex-to-rgb-comma-string = hex: with (slice-hex (nohash hex)); with builtins; assert(isString hex); "${toString (drune-to-255 r)},${toString (drune-to-255 g)},${toString (drune-to-255 b)}"; + + # This is useful if you have a float (like a transparency value) and want a drune representation of it + # So 0.0 -> "00" and 1.0 -> "FF" + float-to-drune = f: with builtins; assert(isFloat f); "${num-to-rune (floor((255*f) / 16))}${num-to-rune (floor(255*f) - (floor((255*f) / 16) * 16))}"; + + # Takes in hex and a float. 0.5 is +50% brightness and (-0.5) is -50% brightness. + # So "#ff0044": 0.3 -> "#ff0055" + alter-luminace-hex = hex: amount: let + color-num = with (slice-hex (nohash hex)); { r = drune-to-255 r; g = drune-to-255 g; b = drune-to-255 b; }; + alter = num: (num-to-drune (cap-255 (builtins.floor ((125 * amount) + (num * (1+amount))) ))); + in with color-num; "#${alter r}${alter g}${alter b}"; +} diff --git a/flake-modules/pkgs.nix b/flake-modules/pkgs.nix new file mode 100644 index 0000000..16970b5 --- /dev/null +++ b/flake-modules/pkgs.nix @@ -0,0 +1,29 @@ +inputs: simple-pkgs: hyper: let + args = { + system = hyper.system; + config = { + allowUnfreePredicate = (import ./allowed.nix simple-pkgs).predicate; + cudaSupport = hyper.nvidia.enable; + cudaForwardCompat = hyper.nvidia.enable; + }; + }; + overlays = [(final: prev: { + unstable = import inputs.nixpkgs-unstable args; + latest = import inputs.nixpkgs-latest args; + pkgs-version = hyper.main-pkgs-version; + })] ++ (if hyper.isServer then [ + inputs.copyparty.overlays.default + ] else []); +in if !hyper.isNOD then + (import inputs.nixpkgs (args // { inherit overlays; })) +else ( + (import inputs.nixpkgs (args // { inherit overlays; })) // # normal as base + (import inputs.nixpkgs24 (args // { # overwrite with old versions + overlays = [(final: prev: { + pkgs-version = "24.05"; + })]; + })) +) + + + diff --git a/flake-modules/rice.nix b/flake-modules/rice.nix index e204622..9489eac 100644 --- a/flake-modules/rice.nix +++ b/flake-modules/rice.nix @@ -1,6 +1,6 @@ -pkgs: rec { +pkgs: hyper: rec { - lib = import ../nxlib/ricelib.nix pkgs.lib; + lib = import ./nxlib/ricelib.nix pkgs.lib; transparency = 0.8; rounding = 3; @@ -36,17 +36,12 @@ pkgs: rec { red = "#dd4444"; # "#dd1111" "#00aa00"; yellow = "#dddd44"; # "#dddd11" "#ffff00"; }; - facolor = builtins.mapAttrs alter-set (builtins.fromJSON (builtins.readFile ./colors.json)).to_alter; - fbcolor = (builtins.fromJSON (builtins.readFile ./colors.json)).base; + facolor = builtins.mapAttrs alter-set (builtins.fromJSON (builtins.readFile ./colors.json))."${hyper.host}".to_alter; + fbcolor = (builtins.fromJSON (builtins.readFile ./colors.json))."${hyper.host}".base; fcolor = facolor // fbcolor; xcolor = with ccolor; with fcolor; { # background = "#000000"; # foreground = "#dddddd"; - # accent = blue; - # secondary = cyan; - # tertiary = magenta; - # special = yellow; - # weird = green; subtle = { darker = "#111111"; dark = "#444444"; base = "#777777"; bright = "#999999"; brighter = "#cccccc"; }; positive = alter "#00dd00"; negative = alter "#dd0000"; @@ -61,8 +56,6 @@ pkgs: rec { regular-path = "${package}/share/fonts/truetype/NerdFonts/JetBrainsMonoNerdFont-Regular.ttf"; }; base = { - # name = "NewComputerModern08"; - # package = pkgs.newcomputermodern; name = "Atkinson Hyperlegible"; package = pkgs.atkinson-hyperlegible-next; }; diff --git a/flake.nix b/flake.nix index 7aa5691..89099ee 100644 --- a/flake.nix +++ b/flake.nix @@ -7,28 +7,17 @@ nixpkgs-latest.url = "github:nixos/nixpkgs?ref=master"; nixpkgs24.url = "github:NixOS/nixpkgs/nixos-24.05"; - home-manager = { - url = "github:nix-community/home-manager/release-25.11"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - home-manager24 ={ - url = "github:nix-community/home-manager/release-24.05"; - inputs.nixpkgs.follows = "nixpkgs24"; - }; + home-manager = { url = "github:nix-community/home-manager/release-25.11"; inputs.nixpkgs.follows = "nixpkgs"; }; + home-manager24 = { url = "github:nix-community/home-manager/release-24.05"; inputs.nixpkgs.follows = "nixpkgs24"; }; nix-on-droid = { url = "github:nix-community/nix-on-droid/release-24.05"; - inputs.nixpkgs.follows = "nixpkgs24"; - inputs.home-manager.follows = "home-manager24"; + inputs = { nixpkgs.follows = "nixpkgs24"; home-manager.follows = "home-manager24"; }; }; nixos-wsl.url = "github:nix-community/NixOS-WSL/main"; - sops-nix ={ - url = "github:Mic92/sops-nix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - + sops-nix = { url = "github:Mic92/sops-nix"; inputs.nixpkgs.follows = "nixpkgs"; }; lanzaboote.url = "github:nix-community/lanzaboote/v0.4.2"; hyprland.url = "git+https://github.com/hyprwm/Hyprland?submodules=1"; @@ -37,101 +26,63 @@ }; outputs = { ... }@inputs: with inputs; let - system = "x86_64-linux"; simple-pkgs = import nixpkgs { inherit system; }; - config = { allowUnfreePredicate = pkg: builtins.elem (simple-pkgs.lib.getName pkg) (import ./flake-modules/allowed.nix).unfree; }; - - hyper-base = rec { - system = "x86_64-linux"; - user = "nx2"; - domain = "nx2.site"; - home = "/home/${user}"; - webroot = "/var/lib/hugo/nx2site/public"; - pkgs-version = "25.11"; - }; - - get-pkgs = let s = system; in { host, system?s, nixpkgs?inputs.nixpkgs, version?"25.11" }: import nixpkgs { - inherit system config; - overlays = [(final: prev: { - unstable = import nixpkgs-unstable { inherit system config; }; - latest = import nixpkgs-latest { inherit system config; }; - pkgs-version = version; - })] ++ (if host == "NxACE" then [ - copyparty.overlays.default - ] else []); - }; - - nvidia-base = import ./flake-modules/nvidia.nix; - secrets = import ./git-crypt/secrets.nix; - rice = import ./flake-modules/rice.nix simple-pkgs; + get-pkgs = import ./flake-modules/pkgs.nix inputs simple-pkgs; + get-hyper = import ./flake-modules/hyper.nix; + secrets = import ./git-crypt/secrets.nix; + get-rice = import ./flake-modules/rice.nix simple-pkgs; in { nixosConfigurations = let - make-nixos-system = host: nvidia-settings: nixpkgs.lib.nixosSystem { - pkgs = get-pkgs { inherit host; }; + make-nixos-system = host: let + hyper = get-hyper host; + rice = get-rice hyeper; + in nixpkgs.lib.nixosSystem { + pkgs = get-pkgs hyper; modules = [ ./configuration.nix ]; - specialArgs = let - hyper = hyper-base // { inherit host; nvidia = (nvidia-base // nvidia-settings); }; - in { inherit inputs hyper rice secrets; }; + specialArgs = { inherit inputs hyper rice secrets; }; }; - make-nixos-wsl-system = host: nixpkgs.lib.nixosSystem { - pkgs = get-pkgs { inherit host; }; + make-nixos-wsl-system = host: let hyper = get-hyper host; in nixpkgs.lib.nixosSystem { + pkgs = get-pkgs hyper; modules = [ ./wsl.nix ]; - specialArgs = let - hyper = hyper-base // { inherit host; }; - rice = import ./flake-modules/rice.nix pkgs; - in { inherit inputs hyper rice; }; + specialArgs = { inherit inputs hyper rice; }; }; in { - NxXPS = make-nixos-system "NxXPS" { enable = true; prime = true; }; - NxNORTH = make-nixos-system "NxNORTH" { enable = true; prime = false; }; - NxACE = make-nixos-system "NxACE" { enable = false; }; - NxDCS = make-nixos-wsl-system "NxDCS"; + NxNORTH = make-nixos-system "NxNORTH"; + NxXPS = make-nixos-system "NxXPS"; + NxACE = make-nixos-system "NxACE"; + NxDCS = make-nixos-wsl-system "NxDCS"; }; nixOnDroidConfigurations = let makeNODConfiguration = host: nix-on-droid.lib.nixOnDroidConfiguration rec { - pkgs = let - options = { inherit host; system = "aarch64-linux"; }; - in (get-pkgs options) // - (get-pkgs (options // { version = "24.05"; nixpkgs = nixpkgs24; } ) - ); + hyper = get-hyper host; + pkgs = get-pkgs hyper; modules = [ ./nod.nix ]; home-manager-path = home-manager24.outPath; - extraSpecialArgs = let - hyper = hyper-base // { - inherit host; - system = "aarch64-linux"; - user = "nix-on-droid"; - home = "/data/data/com.termux.nix/files/home"; - pkgs-version = "24.05"; - }; - rice = import ./flake-modules/rice.nix pkgs; - in { inherit inputs hyper rice; }; + extraSpecialArgs = { inherit inputs hyper rice; }; }; in { NxS23U = makeNODConfiguration "NxS23U"; }; homeConfigurations = let - make-home-configuration = host: user: nvidia-settings: home-manager.lib.homeManagerConfiguration { - pkgs = get-pkgs { inherit host; }; + make-home-configuration = host: let + hyper = get-hyper host; + rice = get-rice hyper; + in home-manager.lib.homeManagerConfiguration { + pkgs = get-pkgs hyper; modules = [ ./home.nix ]; - extraSpecialArgs = let - hyper = hyper-base // { inherit host; nvidia = nvidia-base // nvidia-settings; }; - in { inherit inputs hyper rice secrets; }; + extraSpecialArgs = { inherit inputs hyper rice secrets; }; }; - make-shell-configuration = host: user: home-manager.lib.homeManagerConfiguration { - pkgs = get-pkgs { inherit host; }; + make-shell-configuration = host: let hyper = get-hyper host; in home-manager.lib.homeManagerConfiguration { + pkgs = get-pkgs hyper; modules = [ ./shell-only.nix ]; - extraSpecialArgs = let - hyper = hyper-base // { inherit host; }; - in { inherit inputs hyper rice secrets; }; + extraSpecialArgs = { inherit inputs hyper rice secrets; }; }; in { - "${hyper-base.user}@NxXPS" = make-home-configuration "NxXPS" hyper-base.user { enable = true; prime = true; }; - "${hyper-base.user}@NxNORTH" = make-home-configuration "NxNORTH" hyper-base.user { enable = true; prime = false; }; - "${hyper-base.user}@NxACE" = make-home-configuration "NxACE" hyper-base.user { enable = false; }; - - "${hyper-base.user}@NxDCS" = make-shell-configuration "NxDCS" hyper-base.user; + "nx2@NxXPS" = make-home-configuration "NxXPS"; + "nx2@NxNORTH" = make-home-configuration "NxNORTH"; + "nx2@NxACE" = make-home-configuration "NxACE"; + "nx2@NxDCS" = make-shell-configuration "NxDCS"; }; }; } diff --git a/home-modules/bar/caldav-event.nix b/home-modules/bar/caldav-event.nix index 8a7f9ef..e87592b 100644 --- a/home-modules/bar/caldav-event.nix +++ b/home-modules/bar/caldav-event.nix @@ -59,6 +59,8 @@ def get_ongoing_or_next_event(url, username, password): for calendar in calendars: for event in calendar.search(start=now): + if "VEVENT" not in event.data: + continue calendar_parsed = Calendar(event.data) for ics_event in calendar_parsed.events: event_dict = {} diff --git a/home-modules/gimp.nix b/home-modules/gimp.nix index 169ff34..c520a61 100644 --- a/home-modules/gimp.nix +++ b/home-modules/gimp.nix @@ -1,10 +1,6 @@ -{ pkgs, ... }@all: with all; -{ +{ pkgs, ... }@all: with all; { home.packages = with pkgs; [ - # (gimp-with-plugins.override { - # plugins = with gimpPlugins; [ bimp ]; - # }) - unstable.gimp + gimp ]; } diff --git a/home-modules/nx2site-backup.nix b/home-modules/nx2site-backup.nix index c12dc73..d3c23e5 100644 --- a/home-modules/nx2site-backup.nix +++ b/home-modules/nx2site-backup.nix @@ -1,5 +1,4 @@ -{ pkgs, ... }@all: with all; -{ +{ pkgs, ... }@all: with all; { home.packages = [ (pkgs.writeShellApplication { name = "nx_backup"; diff --git a/home-modules/wallpaper-to-colors.nix b/home-modules/wallpaper-to-colors.nix index 6f042b4..c4df971 100644 --- a/home-modules/wallpaper-to-colors.nix +++ b/home-modules/wallpaper-to-colors.nix @@ -1,8 +1,8 @@ { pkgs, ... }@all: with all; { - home.packages = with pkgs; [ - (writers.writePython3Bin "change_colors_json" { - libraries = with python3Packages; [ numpy pillow scikit-learn ]; + home.packages = [ + (pkgs.writers.writePython3Bin "change_colors_json" { + libraries = with pkgs.python3Packages; [ numpy pillow scikit-learn ]; flakeIgnore = [ "E302" "E305" "E226" "E501" ]; } /*python */ '' from colorsys import hls_to_rgb, rgb_to_hls @@ -141,7 +141,10 @@ foreground = alter_l(accent, 0.9) background = alter_l(accent, 0.05) - d = { + with open("${hyper.home}/nix-dots/flake-modules/colors.json", "r") as f: + full_d = json.load(f) + + full_d['${hyper.host}'] = { "base": { "foreground": list_to_hex(foreground), "background": list_to_hex(background) @@ -155,8 +158,8 @@ } } - with open("/home/nx2/nix-dots/flake-modules/colors.json", "w") as f: - f.write(json.dumps(d, indent=4)) + with open("${hyper.home}/nix-dots/flake-modules/colors.json", "w") as f: + f.write(json.dumps(full_d, indent=4)) '') ]; } diff --git a/home.nix b/home.nix index 9a5e009..d9dcebc 100644 --- a/home.nix +++ b/home.nix @@ -71,6 +71,6 @@ home.username = hyper.user; home.homeDirectory = hyper.home; # home.homeDirectory = "/home/${hyper.user}"; - home.stateVersion = hyper.pkgs-version; + home.stateVersion = hyper.main-pkgs-version; programs.home-manager.enable = true; } diff --git a/nxlib/ricelib.nix b/nxlib/ricelib.nix deleted file mode 100644 index 067a060..0000000 --- a/nxlib/ricelib.nix +++ /dev/null @@ -1,96 +0,0 @@ -lib: -let - # takes in "ff0044" (no hash!) and returns { r = "ff", g = "00", b = "44" } - slice-hex = hex: with builtins; { r = substring 0 2 hex; g = substring 2 2 hex; b = substring 4 2 hex; }; - - # takes in "44" and returns 64 - drune-to-255 = drune: with builtins; (rune-to-num (substring 0 1 drune)) * 16 + (rune-to-num (substring 1 1 drune)); - num-to-drune = num: "${num-to-rune (num / 16)}${num-to-rune (num - ((num / 16) * 16))}"; - - # takes in "D" and returns 13 - rune-to-num = rune: # inspiration from https://github.com/bertof/nix-rice - let - dict = { - "0" = 0; - "1" = 1; - "2" = 2; - "3" = 3; - "4" = 4; - "5" = 5; - "6" = 6; - "7" = 7; - "8" = 8; - "9" = 9; - "A" = 10; - "B" = 11; - "C" = 12; - "D" = 13; - "E" = 14; - "F" = 15; - }; - in - assert(builtins.hasAttr (lib.strings.toUpper rune) dict); - builtins.getAttr (lib.strings.toUpper rune) dict; - - # takes in 15 and returns "F" - num-to-rune = num: - let - num-string = builtins.toString num; - dict = { - "0" = "0"; - "1" = "1"; - "2" = "2"; - "3" = "3"; - "4" = "4"; - "5" = "5"; - "6" = "6"; - "7" = "7"; - "8" = "8"; - "9" = "9"; - "10" = "A"; - "11" = "B"; - "12" = "C"; - "13" = "D"; - "14" = "E"; - "15" = "F"; - }; - in - assert(builtins.hasAttr num-string dict); - builtins.getAttr num-string dict; - - # Keeps num between 0 and 255 - # Make sure to pass in an int not a float - cap-255 = num: (if (num>255) then 255 else if (num<0) then 0 else num); - - nohash = hex: with builtins; assert((stringLength hex) == 7); substring 1 6 hex; -in -{ - - ## USEFUL FUNCTIONS - # -------------------------------------------------------------------------------- - # takes in a string like "#ff0044" and returns "ff0044" symbol - inherit nohash; - - # -------------------------------------------------------------------------------- - # This takes in something like "#ff0044" and returns "255,0,64" - hex-to-rgb-comma-string = hex: - with (slice-hex (nohash hex)); - with builtins; - assert(isString hex); - "${toString (drune-to-255 r)},${toString (drune-to-255 g)},${toString (drune-to-255 b)}"; - - # -------------------------------------------------------------------------------- - # This is useful if you have a float (like a transparency value) and want a drune representation of it - # So 0.0 -> "00" and 1.0 -> "FF" - float-to-drune = f: with builtins; assert(isFloat f); "${num-to-rune (floor((255*f) / 16))}${num-to-rune (floor(255*f) - (floor((255*f) / 16) * 16))}"; - - # -------------------------------------------------------------------------------- - # Takes in hex and a float. 0.5 is +50% brightness and (-0.5) is -50% brightness. - # So "#ff0044": 0.3 -> "#ff0055" - alter-luminace-hex = hex: amount: - let - color-num = with (slice-hex (nohash hex)); { r = drune-to-255 r; g = drune-to-255 g; b = drune-to-255 b; }; - alter = num: (num-to-drune (cap-255 (builtins.floor ((125 * amount) + (num * (1+amount))) ))); - in - with color-num; "#${alter r}${alter g}${alter b}"; -} diff --git a/shell-only.nix b/shell-only.nix index 2d37815..b2970ed 100644 --- a/shell-only.nix +++ b/shell-only.nix @@ -30,7 +30,7 @@ home = { username = hyper.user; homeDirectory = hyper.home; - stateVersion = hyper.pkgs-version; + stateVersion = hyper.main-pkgs-version; }; xdg = { enable = true; diff --git a/system-modules/nix.nix b/system-modules/nix.nix new file mode 100644 index 0000000..651f9ac --- /dev/null +++ b/system-modules/nix.nix @@ -0,0 +1,14 @@ +{ ... }: { + nix.settings = { + experimental-features = [ "nix-command" "flakes" ]; + substituters = [ + "https://cache.nixos.org/" + "https://cache.nixos-cuda.org" + "https://nix-community.cachix.org" + ]; + trusted-public-keys = [ + "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" + "cache.nixos-cuda.org:74DUi4Ye579gUqzH4ziL9IyiJBlDpMRn9MBN8oNan9M=" + ]; + }; +}