From 5730f2c761474d83f8dbabd96c1f4949c1845487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20J=C3=B6rg?= Date: Mon, 22 Sep 2025 15:54:55 +0200 Subject: [PATCH] fix(nix): Cleanup --- .envrc | 2 +- lon.lock | 35 +++++++++++ lon.nix | 53 ++++++++++++++++ npins/default.nix | 146 --------------------------------------------- npins/sources.json | 37 ------------ shell.nix | 4 +- 6 files changed, 91 insertions(+), 186 deletions(-) create mode 100644 lon.lock create mode 100644 lon.nix delete mode 100644 npins/default.nix delete mode 100644 npins/sources.json diff --git a/.envrc b/.envrc index e72c864b..fc056953 100644 --- a/.envrc +++ b/.envrc @@ -1,6 +1,6 @@ #!/usr/bin/env bash # the shebang is ignored, but nice for editors -watch_file npins/sources.json +watch_file lon.lock # Load .env file if it exists dotenv_if_exists diff --git a/lon.lock b/lon.lock new file mode 100644 index 00000000..a53db4e0 --- /dev/null +++ b/lon.lock @@ -0,0 +1,35 @@ +{ + "version": "1", + "sources": { + "gomod2nix": { + "type": "GitHub", + "fetchType": "tarball", + "owner": "nix-community", + "repo": "gomod2nix", + "branch": "master", + "revision": "2cbd7fdd6eeab65c494cc426e18f4e4d2a5e35c0", + "url": "https://github.com/nix-community/gomod2nix/archive/2cbd7fdd6eeab65c494cc426e18f4e4d2a5e35c0.tar.gz", + "hash": "sha256-0YkWCS13jpoo3+sX/3kcgdxBNt1VZTmvF+FhZb4rFKI=" + }, + "helmfile-nix": { + "type": "GitHub", + "fetchType": "tarball", + "owner": "remarkable", + "repo": "helmfile-nix", + "branch": "main", + "revision": "03b3de30d44b6e90e9425bad10476dadd75bcba9", + "url": "https://github.com/remarkable/helmfile-nix/archive/03b3de30d44b6e90e9425bad10476dadd75bcba9.tar.gz", + "hash": "sha256-K6Y2/KSKROK8CYQjFsl6kq3m97XjzEYT36mQxUxWbYk=" + }, + "nixpkgs": { + "type": "GitHub", + "fetchType": "tarball", + "owner": "NixOS", + "repo": "nixpkgs", + "branch": "nixpkgs-unstable", + "revision": "b1bebd0fe266", + "url": "https://github.com/NixOS/nixpkgs/archive/b1bebd0fe266.tar.gz", + "hash": "sha256-MmJvj6mlWzeRwKGLcwmZpKaOPZ5nJb/6al5CXqJsgjo=" + } + } +} diff --git a/lon.nix b/lon.nix new file mode 100644 index 00000000..a88d448e --- /dev/null +++ b/lon.nix @@ -0,0 +1,53 @@ +# Generated by lon. Do not modify! +let + + lock = builtins.fromJSON (builtins.readFile ./lon.lock); + + # Override with a path defined in an environment variable. If no variable is + # set, the original path is used. + overrideFromEnv = + name: path: + let + replacement = builtins.getEnv "LON_OVERRIDE_${name}"; + in + if replacement == "" then + path + else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 replacement == "/" then + /. + replacement + else + /. + builtins.getEnv "PWD" + "/${replacement}"; + + fetchSource = + args@{ fetchType, ... }: + if fetchType == "git" then + builtins.fetchGit ( + { + url = args.url; + ref = args.branch; + rev = args.revision; + narHash = args.hash; + submodules = args.submodules; + } + // ( + if args ? lastModified then + { + inherit (args) lastModified; + shallow = true; + } + else + { } + ) + ) + else if fetchType == "tarball" then + builtins.fetchTarball { + url = args.url; + sha256 = args.hash; + } + else + builtins.throw "Unsupported source type ${fetchType}"; + +in +builtins.mapAttrs (name: args: overrideFromEnv name (fetchSource args)) lock.sources diff --git a/npins/default.nix b/npins/default.nix deleted file mode 100644 index 65924762..00000000 --- a/npins/default.nix +++ /dev/null @@ -1,146 +0,0 @@ -/* - 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 - data = builtins.fromJSON (builtins.readFile ./sources.json); - version = data.version; - - # 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)); - concatMapStrings = f: list: concatStrings (map f list); - 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: - assert spec ? type; - let - path = - if spec.type == "Git" then - mkGitSource spec - else if spec.type == "GitRelease" then - mkGitSource spec - else if spec.type == "PyPi" then - mkPyPiSource spec - else if spec.type == "Channel" then - mkChannelSource spec - else if spec.type == "Tarball" then - mkTarballSource spec - else - builtins.throw "Unknown source type ${spec.type}"; - in - spec // { outPath = mayOverride name path; }; - - mkGitSource = - { - repository, - revision, - url ? null, - submodules, - hash, - branch ? null, - ... - }: - 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 - builtins.fetchTarball { - inherit url; - sha256 = hash; # FIXME: check nix version & use SRI hashes - } - 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 - 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 - builtins.fetchGit { - rev = revision; - inherit name; - # hash = hash; - inherit url submodules; - }; - - mkPyPiSource = - { url, hash, ... }: - builtins.fetchurl { - inherit url; - sha256 = hash; - }; - - mkChannelSource = - { url, hash, ... }: - builtins.fetchTarball { - inherit url; - sha256 = hash; - }; - - mkTarballSource = - { - url, - locked_url ? url, - hash, - ... - }: - builtins.fetchTarball { - url = locked_url; - sha256 = hash; - }; -in -if version == 5 then - builtins.mapAttrs mkSource 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 deleted file mode 100644 index 6df53cc7..00000000 --- a/npins/sources.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "pins": { - "gomod2nix": { - "type": "Git", - "repository": { - "type": "GitHub", - "owner": "nix-community", - "repo": "gomod2nix" - }, - "branch": "master", - "submodules": false, - "revision": "2cbd7fdd6eeab65c494cc426e18f4e4d2a5e35c0", - "url": "https://github.com/nix-community/gomod2nix/archive/2cbd7fdd6eeab65c494cc426e18f4e4d2a5e35c0.tar.gz", - "hash": "18hl5fz6aqg12ypkjramvlv43p413iwzy5zbvwl9m3kp5l4id2fi" - }, - "helmfile-nix": { - "type": "Git", - "repository": { - "type": "GitHub", - "owner": "remarkable", - "repo": "helmfile-nix" - }, - "branch": "main", - "submodules": false, - "revision": "03b3de30d44b6e90e9425bad10476dadd75bcba9", - "url": "https://github.com/remarkable/helmfile-nix/archive/03b3de30d44b6e90e9425bad10476dadd75bcba9.tar.gz", - "hash": "12bdar6cb459vw9ldk73npvydbcjgb4ic8w416yf4i4alky3d9ib" - }, - "nixpkgs": { - "type": "Channel", - "name": "nixpkgs-unstable", - "url": "https://releases.nixos.org/nixpkgs/nixpkgs-25.05pre800239.b1bebd0fe266/nixexprs.tar.xz", - "hash": "0vnfj9d7kzk673i7s1vnkbx513a4gh5mfcd8fag2c7wi6hz471n6" - } - }, - "version": 5 -} diff --git a/shell.nix b/shell.nix index eba98df3..ebe8b5cf 100644 --- a/shell.nix +++ b/shell.nix @@ -1,5 +1,5 @@ let - sources = import ./npins; + sources = import ./lon.nix; system = builtins.currentSystem; pkgs = import sources.nixpkgs { inherit system; @@ -23,7 +23,7 @@ pkgs.mkShellNoCC { packages = with pkgs; [ # nix helpers just - npins + lon nix-converter # helm