treewide: nixfmt

This commit is contained in:
Gavin John 2024-11-22 10:50:48 -08:00 committed by mergify[bot]
parent 4f4dec9f65
commit 4021fa3c83
6 changed files with 143 additions and 87 deletions

View file

@ -4,9 +4,14 @@
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }:
outputs =
{
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (system: {
packages.nur = nixpkgs.legacyPackages.${system}.python3.pkgs.callPackage ./nur.nix {};
packages.nur = nixpkgs.legacyPackages.${system}.python3.pkgs.callPackage ./nur.nix { };
defaultPackage = self.packages.${system}.nur;
});
}

View file

@ -1,4 +1,11 @@
{ buildPythonApplication, lib, nix-prefetch-git, git, nix, glibcLocales }:
{
buildPythonApplication,
lib,
nix-prefetch-git,
git,
nix,
glibcLocales,
}:
buildPythonApplication {
name = "nur";
@ -7,7 +14,16 @@ buildPythonApplication {
doCheck = false;
makeWrapperArgs = [
"--prefix" "PATH" ":" "${lib.makeBinPath [ nix-prefetch-git git nix ]}"
"--set" "LOCALE_ARCHIVE" "${glibcLocales}/lib/locale/locale-archive"
"--prefix"
"PATH"
":"
"${lib.makeBinPath [
nix-prefetch-git
git
nix
]}"
"--set"
"LOCALE_ARCHIVE"
"${glibcLocales}/lib/locale/locale-archive"
];
}

View file

@ -1,7 +1,8 @@
{ nurpkgs ? import <nixpkgs> {} # For nixpkgs dependencies used by NUR itself
{
nurpkgs ? import <nixpkgs> { }, # For nixpkgs dependencies used by NUR itself
# Dependencies to call NUR repos with
, pkgs ? null
, repoOverrides ? { }
pkgs ? null,
repoOverrides ? { },
}:
let
@ -10,18 +11,29 @@ let
inherit (nurpkgs) lib;
repoSource = name: attr: import ./lib/repoSource.nix {
inherit name attr manifest lockedRevisions lib;
inherit (nurpkgs) fetchgit fetchzip;
};
repoSource =
name: attr:
import ./lib/repoSource.nix {
inherit
name
attr
manifest
lockedRevisions
lib
;
inherit (nurpkgs) fetchgit fetchzip;
};
createRepo = name: attr: import ./lib/evalRepo.nix {
inherit name pkgs lib;
inherit (attr) url;
src = repoSource name attr + ("/" + (attr.file or ""));
};
createRepo =
name: attr:
import ./lib/evalRepo.nix {
inherit name pkgs lib;
inherit (attr) url;
src = repoSource name attr + ("/" + (attr.file or ""));
};
in {
repos = (lib.mapAttrs createRepo manifest) // repoOverrides;
in
{
repos = (lib.mapAttrs createRepo manifest) // repoOverrides;
repo-sources = lib.mapAttrs repoSource manifest;
}

View file

@ -1,27 +1,31 @@
{
description = "Nix User Repository";
outputs = { self }: {
overlay = final: prev: {
nur = import ./default.nix {
nurpkgs = prev;
pkgs = prev;
};
};
nixosModules.nur = { lib, pkgs, ... }: {
options.nur = lib.mkOption {
type = lib.mkOptionType {
name = "nur";
description = "An instance of the Nix User repository";
check = builtins.isAttrs;
};
description = "Use this option to import packages from NUR";
default = import self {
nurpkgs = pkgs;
pkgs = pkgs;
outputs =
{ self }:
{
overlay = final: prev: {
nur = import ./default.nix {
nurpkgs = prev;
pkgs = prev;
};
};
nixosModules.nur =
{ lib, pkgs, ... }:
{
options.nur = lib.mkOption {
type = lib.mkOptionType {
name = "nur";
description = "An instance of the Nix User repository";
check = builtins.isAttrs;
};
description = "Use this option to import packages from NUR";
default = import self {
nurpkgs = pkgs;
pkgs = pkgs;
};
};
};
hmModules.nur = self.nixosModules.nur;
};
hmModules.nur = self.nixosModules.nur;
};
}

View file

@ -1,8 +1,9 @@
{ name
, url
, src
, pkgs # Do not use this for anything other than passing it along as an argument to the repository
, lib
{
name,
url,
src,
pkgs, # Do not use this for anything other than passing it along as an argument to the repository
lib,
}:
let
@ -10,24 +11,33 @@ let
# Arguments passed to each repositories default.nix
passedArgs = {
pkgs = if pkgs != null then pkgs else throw ''
NUR import call didn't receive a pkgs argument, but the evaluation of NUR's ${prettyName} repository requires it.
pkgs =
if pkgs != null then
pkgs
else
throw ''
NUR import call didn't receive a pkgs argument, but the evaluation of NUR's ${prettyName} repository requires it.
This is either because
- You're trying to use a package from that repository, but didn't pass a `pkgs` argument to the NUR import.
In that case, refer to the installation instructions at https://github.com/nix-community/nur#installation on how to properly import NUR
This is either because
- You're trying to use a package from that repository, but didn't pass a `pkgs` argument to the NUR import.
In that case, refer to the installation instructions at https://github.com/nix-community/nur#installation on how to properly import NUR
- You're trying to use a module/overlay from that repository, but it didn't properly declare their module.
In that case, inform the maintainer of the repository: ${url}
'';
- You're trying to use a module/overlay from that repository, but it didn't properly declare their module.
In that case, inform the maintainer of the repository: ${url}
'';
};
expr = import src;
args = builtins.functionArgs expr;
# True if not all arguments are either passed by default (e.g. pkgs) or defaulted (e.g. foo ? 10)
usesCallPackage = ! lib.all (arg: lib.elem arg (lib.attrNames passedArgs) || args.${arg}) (lib.attrNames args);
usesCallPackage =
!lib.all (arg: lib.elem arg (lib.attrNames passedArgs) || args.${arg}) (lib.attrNames args);
in if usesCallPackage then throw ''
in
if usesCallPackage then
throw ''
NUR repository ${prettyName} is using the deprecated callPackage syntax which
might result in infinite recursion when used with NixOS modules.
'' else expr (builtins.intersectAttrs args passedArgs)
''
else
expr (builtins.intersectAttrs args passedArgs)

View file

@ -1,18 +1,26 @@
{
name, attr,
fetchgit, fetchzip, lib,
manifest, lockedRevisions
name,
attr,
fetchgit,
fetchzip,
lib,
manifest,
lockedRevisions,
}:
let
parseGitlabUrl = url: with builtins; let
parts = lib.splitString "/" url;
len = length parts;
in {
domain = elemAt parts 2;
# Allow for deeper hierarchies than owner/repo (GL has groups and subgroups)
path = lib.drop 3 parts;
};
parseGitlabUrl =
url:
with builtins;
let
parts = lib.splitString "/" url;
len = length parts;
in
{
domain = elemAt parts 2;
# Allow for deeper hierarchies than owner/repo (GL has groups and subgroups)
path = lib.drop 3 parts;
};
revision = lockedRevisions.${name};
submodules = attr.submodules or false;
@ -20,24 +28,25 @@ let
localPath = ../repos + "/${name}";
in
if lib.pathExists localPath then
localPath
else if lib.hasPrefix "https://github.com" attr.url && !submodules then
fetchzip {
url = "${attr.url}/archive/${revision.rev}.zip";
inherit (revision) sha256;
}
else if (lib.hasPrefix "https://gitlab.com" attr.url || type == "gitlab") && !submodules then
let
gitlab = parseGitlabUrl attr.url;
escapedPath = builtins.concatStringsSep "%2F" gitlab.path;
in fetchzip {
url = "https://${gitlab.domain}/api/v4/projects/${escapedPath}/repository/archive.tar.gz?sha=${revision.rev}";
inherit (revision) sha256;
}
else
fetchgit {
inherit (attr) url;
inherit (revision) rev sha256;
fetchSubmodules = submodules;
}
if lib.pathExists localPath then
localPath
else if lib.hasPrefix "https://github.com" attr.url && !submodules then
fetchzip {
url = "${attr.url}/archive/${revision.rev}.zip";
inherit (revision) sha256;
}
else if (lib.hasPrefix "https://gitlab.com" attr.url || type == "gitlab") && !submodules then
let
gitlab = parseGitlabUrl attr.url;
escapedPath = builtins.concatStringsSep "%2F" gitlab.path;
in
fetchzip {
url = "https://${gitlab.domain}/api/v4/projects/${escapedPath}/repository/archive.tar.gz?sha=${revision.rev}";
inherit (revision) sha256;
}
else
fetchgit {
inherit (attr) url;
inherit (revision) rev sha256;
fetchSubmodules = submodules;
}