From 0cbf2ce34305eae9afc0dc3a9e72c30b6623034e Mon Sep 17 00:00:00 2001 From: boyreau Date: Mon, 22 Jun 2026 22:11:24 +0200 Subject: [PATCH] Switched nix-cachyos-kernel to npins. Jail.nix overlay added. Linting and quality improvement --- .envrc | 1 + .gitignore | 1 + .gitmodules | 3 - configuration.nix | 26 ++++- hardware.nix | 4 +- kernel.nix | 6 +- nix-cachyos-kernel | 1 - npins/default.nix | 252 +++++++++++++++++++++++++++++++++++++++++++++ npins/sources.json | 35 +++++++ security.nix | 2 +- shell.nix | 12 +++ users.nix | 10 ++ 12 files changed, 342 insertions(+), 11 deletions(-) create mode 100644 .envrc create mode 100644 .gitignore delete mode 160000 nix-cachyos-kernel create mode 100644 npins/default.nix create mode 100644 npins/sources.json create mode 100644 shell.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..1d953f4 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9b42106 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.direnv/ diff --git a/.gitmodules b/.gitmodules index f1634a6..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "nix-cachyos-kernel"] - path = nix-cachyos-kernel - url = ./nix-cachyos-kernel/ diff --git a/configuration.nix b/configuration.nix index e648e42..c082ea3 100644 --- a/configuration.nix +++ b/configuration.nix @@ -1,9 +1,28 @@ { config, - pkgs, ... }: +let + sources = import ./npins/default.nix; + jail-nix = import sources."jail.nix" { }; + jailOverlay = + final: prev: + jail-nix.mkOverlay { + inherit final prev; + packages = + combinators: with combinators; { + firefox = [ + network + gui + gpu + ]; + }; + }; + pkgs = import sources.nixpkgs { + overlays = [ jailOverlay ]; + }; +in { imports = [ ./security.nix @@ -92,6 +111,11 @@ font-awesome ]; + nix.settings.substituters = [ "https://nix-community.cachix.org" ]; + nix.settings.trusted-public-keys = [ + "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" + ]; + system.copySystemConfiguration = true; system.stateVersion = "26.05"; # Not here to update, here for data models backward compatibility. Don't change. diff --git a/hardware.nix b/hardware.nix index 3ac1ce3..9e49454 100644 --- a/hardware.nix +++ b/hardware.nix @@ -28,9 +28,9 @@ ######### nVidia Quadro RTX 3000m ######### graphics.enable = true; nvidia = { - open = false; # Not compatible with current GPU (nvidia quadro 3000) + open = false; # Not compatible with current GPU modesetting.enable = false; - powerManagement.enable = true; # should be false cause GPU too old, but fixes hibernate/suspend issues + powerManagement.enable = true; # Should be false cause GPU too old, but fixes hibernate/suspend issues powerManagement.finegrained = false; # GPU too old nvidiaSettings = true; prime = { diff --git a/kernel.nix b/kernel.nix index 0a305e4..79ab665 100644 --- a/kernel.nix +++ b/kernel.nix @@ -1,8 +1,8 @@ -{ pkgs, system, ... }: let - cachy-source = import ./nix-cachyos-kernel; + sources = import ./npins/default.nix; + cachy-source = import sources.nix-cachyos-kernel; cachy-kernel = - cachy-source.outputs.legacyPackages.x86_64-linux.linuxPackages-cachyos-bore-lto-x86_64-v3; # .linux-cachyos-bore-lto-x86_64-v3; + cachy-source.outputs.legacyPackages.x86_64-linux.linuxPackages-cachyos-bore-lto-x86_64-v3; in { boot.kernelPackages = cachy-kernel; diff --git a/nix-cachyos-kernel b/nix-cachyos-kernel deleted file mode 160000 index 26da04e..0000000 --- a/nix-cachyos-kernel +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 26da04e24aef2993ea256917be42d18f83ce8e8b diff --git a/npins/default.nix b/npins/default.nix new file mode 100644 index 0000000..b7f402e --- /dev/null +++ b/npins/default.nix @@ -0,0 +1,252 @@ +/* + This file is provided under the MIT licence: + + 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. +*/ +# Generated by npins. Do not modify; will be overwritten regularly +let + # Backwards-compatibly make something that previously didn't take any arguments take some + # The function must return an attrset, and will unfortunately be eagerly evaluated + # Same thing, but it catches eval errors on the default argument so that one may still call it with other arguments + mkFunctor = + fn: + let + e = builtins.tryEval (fn { }); + in + (if e.success then e.value else { error = fn { }; }) // { __functor = _self: fn; }; + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 + range = + first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 + stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); + + # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 + stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); + concatStrings = builtins.concatStringsSep ""; + + # If the environment variable NPINS_OVERRIDE_${name} is set, then use + # the path directly as opposed to the fetched source. + # (Taken from Niv for compatibility) + mayOverride = + name: path: + let + envVarName = "NPINS_OVERRIDE_${saneName}"; + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; + ersatz = builtins.getEnv envVarName; + in + if ersatz == "" then + path + else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + builtins.trace "Overriding path of \"${name}\" with \"${ersatz}\" due to set \"${envVarName}\"" ( + if builtins.substring 0 1 ersatz == "/" then + /. + ersatz + else + /. + builtins.getEnv "PWD" + "/${ersatz}" + ); + + mkSource = + name: spec: + { + pkgs ? null, + }: + assert spec ? type; + let + # Unify across builtin and pkgs fetchers. + # `fetchGit` requires a wrapper because of slight API differences. + fetchers = + if pkgs == null then + { + inherit (builtins) fetchTarball fetchurl; + # Frustratingly, due to flakes and `fetchTree`, `fetchGit` + # has a different signature than the other builtin + # fetchers + fetchGit = args: (builtins.fetchGit args).outPath; + } + else + { + fetchTarball = + { + url, + sha256, + }: + pkgs.fetchzip { + inherit url sha256; + extension = "tar"; + }; + inherit (pkgs) fetchurl; + fetchGit = + { + url, + submodules, + rev, + name, + narHash, + }: + pkgs.fetchgit { + inherit url rev name; + fetchSubmodules = submodules; + hash = narHash; + }; + }; + + path = + if spec.type == "Git" then + mkGitSource fetchers spec + else if spec.type == "GitRelease" then + mkGitSource fetchers spec + else if spec.type == "PyPi" then + mkPyPiSource fetchers spec + else if spec.type == "Channel" then + mkChannelSource fetchers spec + else if spec.type == "Tarball" then + mkTarballSource fetchers spec + else if spec.type == "Container" then + mkContainerSource pkgs spec + else + builtins.throw "Unknown source type ${spec.type}"; + in + spec // { outPath = mayOverride name path; }; + + mkGitSource = + { + fetchTarball, + fetchGit, + ... + }: + { + repository, + revision, + url ? null, + submodules, + hash, + ... + }: + assert repository ? type; + # At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository + # In the latter case, there we will always be an url to the tarball + if url != null && !submodules then + fetchTarball { + inherit url; + sha256 = hash; + } + else + let + url = + if repository.type == "Git" then + repository.url + else if repository.type == "GitHub" then + "https://github.com/${repository.owner}/${repository.repo}.git" + else if repository.type == "GitLab" then + "${repository.server}/${repository.repo_path}.git" + else if repository.type == "Forgejo" then + "${repository.server}/${repository.owner}/${repository.repo}.git" + else + throw "Unrecognized repository type ${repository.type}"; + urlToName = + url: rev: + let + matched = builtins.match "^.*/([^/]*)(\\.git)?$" url; + + short = builtins.substring 0 7 rev; + + appendShort = if (builtins.match "[a-f0-9]*" rev) != null then "-${short}" else ""; + in + "${if matched == null then "source" else builtins.head matched}${appendShort}"; + name = urlToName url revision; + in + fetchGit { + rev = revision; + narHash = hash; + + inherit name submodules url; + }; + + mkPyPiSource = + { fetchurl, ... }: + { + url, + hash, + ... + }: + fetchurl { + inherit url; + sha256 = hash; + }; + + mkChannelSource = + { fetchTarball, ... }: + { + url, + hash, + ... + }: + fetchTarball { + inherit url; + sha256 = hash; + }; + + mkTarballSource = + { fetchTarball, ... }: + { + url, + locked_url ? url, + hash, + ... + }: + fetchTarball { + url = locked_url; + sha256 = hash; + }; + + mkContainerSource = + pkgs: + { + image_name, + image_tag, + image_digest, + hash, + ... + }: + if pkgs == null then + builtins.throw "container sources require passing in a Nixpkgs value: https://github.com/andir/npins/blob/master/README.md#using-the-nixpkgs-fetchers" + else + pkgs.dockerTools.pullImage { + imageName = image_name; + imageDigest = image_digest; + finalImageTag = image_tag; + hash = hash; + }; +in +mkFunctor ( + { + input ? ./sources.json, + }: + let + data = + if builtins.isPath input then + # while `readFile` will throw an error anyways if the path doesn't exist, + # we still need to check beforehand because *our* error can be caught but not the one from the builtin + # See: + if builtins.pathExists input then + builtins.fromJSON (builtins.readFile input) + else + throw "Input path ${toString input} does not exist" + else if builtins.isAttrs input then + input + else + throw "Unsupported input type ${builtins.typeOf input}, must be a path or an attrset"; + version = data.version; + in + if version == 7 then + builtins.mapAttrs (name: spec: mkFunctor (mkSource name spec)) data.pins + else + throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`" +) diff --git a/npins/sources.json b/npins/sources.json new file mode 100644 index 0000000..752a675 --- /dev/null +++ b/npins/sources.json @@ -0,0 +1,35 @@ +{ + "pins": { + "jail.nix": { + "type": "Git", + "repository": { + "type": "Git", + "url": "https://git.sr.ht/~alexdavid/jail.nix" + }, + "branch": "main", + "submodules": false, + "revision": "404e7da9da5ab9aa643666682b2ba1312fa5fbe8", + "url": null, + "hash": "sha256-YsEjjdOsGEzTeD+iT7ONh071BqWAOQWpzYVei3okAXE=" + }, + "nix-cachyos-kernel": { + "type": "Git", + "repository": { + "type": "GitHub", + "owner": "xddxdd", + "repo": "nix-cachyos-kernel" + }, + "branch": "release", + "submodules": false, + "revision": "756ed060ca6adcdf3e65371e3725b89c58a1354d", + "url": "https://github.com/xddxdd/nix-cachyos-kernel/archive/756ed060ca6adcdf3e65371e3725b89c58a1354d.tar.gz", + "hash": "sha256-Vujeg1QyOCnEMCNV1U7aFDllD0w2lEl8c0uJyKM+cOI=" + }, + "nixpkgs": { + "type": "Tarball", + "url": "https://releases.nixos.org/nixos/26.05/nixos-26.05.2462.e8210c649915/nixexprs.tar.xz", + "hash": "sha256-2khLdWQw7Z9psJUEORs8dKPwivbhLbiBTas81jEZtJs=" + } + }, + "version": 7 +} diff --git a/security.nix b/security.nix index 7243dcc..3b08f47 100644 --- a/security.nix +++ b/security.nix @@ -2,7 +2,7 @@ networking.nftables.enable = true; networking.firewall = { enable = true; - # Should go in LWK_CONNECT system module or flake + # Lwk connect ports allowedTCPPorts = [ 1716 ]; allowedUDPPorts = [ 1716 ]; }; diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..7a9d66c --- /dev/null +++ b/shell.nix @@ -0,0 +1,12 @@ +let + pkgs = import { }; +in +pkgs.mkShellNoCC { + packages = [ + pkgs.npins + ]; + + shellHook = '' + npins update + ''; +} diff --git a/users.nix b/users.nix index 6694120..98e0158 100644 --- a/users.nix +++ b/users.nix @@ -13,6 +13,16 @@ shell = pkgs.bash; }; + users.users.raphou406 = { + isNormalUser = true; + extraGroups = [ + "audio" + "video" + "network" + ]; + shell = pkgs.bash; + }; + users.users.flake = { isNormalUser = true; extraGroups = [