add user level version of crimes

This commit is contained in:
xenia 2024-12-21 15:52:58 -05:00
parent 97922bfd96
commit e06597d7db
4 changed files with 229 additions and 24 deletions

View File

@ -109,7 +109,12 @@
}; };
possiblyCommitCrimes = lib.mkOption { possiblyCommitCrimes = lib.mkOption {
description = "Globally enable usage of packages marked as FYPTL"; description = ''
Globally enable usage of packages marked as FYPTL. This installs a nix
plugin, which is widely considered to be a nix crime, and it also might
be an actual crime to use these packages depending on you jurisdiction. Use
at your own risk
'';
type = lib.types.bool; type = lib.types.bool;
default = false; default = false;
defaultText = lib.literalExpression "false"; defaultText = lib.literalExpression "false";
@ -134,32 +139,29 @@
self.meta.path-entry self.meta.path-entry
]; ];
# TODO: also enable this for user-level nix, somehow
config.nixpkgs.config = lib.mkIf config.dragnpkgs.possiblyCommitCrimes { config.nixpkgs.config = lib.mkIf config.dragnpkgs.possiblyCommitCrimes {
allowlistedLicenses = [ lib.licenses.fyptl ]; allowlistedLicenses = [ lib.licenses.fyptl ];
}; };
config.nix.registry.dragnpkgs-global-config.to = config.nix.settings.plugin-files =
let lib.optionals config.dragnpkgs.possiblyCommitCrimes [
possiblyCommitCrimes = "${pkgs.lix-plugins}/lib/liblix-plugins.so"
lib.boolToString config.dragnpkgs.possiblyCommitCrimes; ];
config-flake = pkgs.writeTextFile {
name = "source"; config.nix.settings.extra-builtins-file =
destination = "/flake.nix"; lib.mkIf config.dragnpkgs.possiblyCommitCrimes (
text = '' lib.mkForce "/etc/nix/extra-builtins.nix"
{ );
outputs = { self }: {
dragnpkgsConfig = { config.environment.etc."nix/extra-builtins.nix".source =
possiblyCommitCrimes = ${possiblyCommitCrimes}; lib.mkIf config.dragnpkgs.possiblyCommitCrimes
}; ''
}; { ... }: {
} dragnpkgs = {
''; possiblyCommitCrimes = ${possiblyCommitCrimes};
}; };
in { }
type = "path"; '';
path = "${config-flake}";
};
}) })
(import ./module.nix) (import ./module.nix)
@ -187,7 +189,32 @@
}); });
legacyPackages = forAllSystems (system: legacyPackages = forAllSystems (system:
nixpkgs.legacyPackages.${system}.appendOverlays overlays let
unsafeConf = if builtins.hasAttr "extraBuiltins" builtins then (
let conf = builtins.extraBuiltins; in
if builtins.isAttrs conf then conf else {}
) else {};
possiblyCommitCrimes =
if
builtins.hasAttr "dragnpkgs" unsafeConf &&
builtins.isAttrs unsafeConf.dragnpkgs &&
builtins.hasAttr "possiblyCommitCrimes" unsafeConf.dragnpkgs &&
builtins.isBool unsafeConf.dragnpkgs.possiblyCommitCrimes
then
unsafeConf.dragnpkgs.possiblyCommitCrimes
else
false;
in
nixpkgs.legacyPackages.${system}.appendOverlays (overlays ++
(final: prev: {
stdenv = prev.stdenv.override {
config = prev.config // {
allowlistedLicenses = final.lib.optionals
possiblyCommitCrimes
[ final.lib.licenses.fyptl ];
};
};
}))
); );
nixosModules = nixpkgs.nixosModules; nixosModules = nixpkgs.nixosModules;

View File

@ -45,4 +45,7 @@ final: prev: {
eta = prev.callPackage ./pkgs/cmdline/eta {}; eta = prev.callPackage ./pkgs/cmdline/eta {};
cado-nfs = prev.callPackage ./pkgs/crypto/cado-nfs {}; cado-nfs = prev.callPackage ./pkgs/crypto/cado-nfs {};
lix-plugins = prev.callPackage ./pkgs/lix/lix-plugins {};
nix-plugins = builtins.throw "nix-plugins is not supported. see pkgs.lix-plugins";
} }

View File

@ -0,0 +1,142 @@
From 72257e171df999f878a250495a77247a9c5da68b Mon Sep 17 00:00:00 2001
From: xenia <xenia@awoo.systems>
Date: Sat, 21 Dec 2024 15:33:10 -0500
Subject: [PATCH] implement lix support
---
CMakeLists.txt | 27 ---------------------------
extra-builtins.cc | 27 +++------------------------
meson.build | 18 ++++++++++++++++++
nix-plugins-config.h.in | 3 ---
4 files changed, 21 insertions(+), 54 deletions(-)
delete mode 100644 CMakeLists.txt
create mode 100644 meson.build
delete mode 100644 nix-plugins-config.h.in
diff --git a/CMakeLists.txt b/CMakeLists.txt
deleted file mode 100644
index 9674fe8..0000000
--- a/CMakeLists.txt
+++ /dev/null
@@ -1,27 +0,0 @@
-cmake_minimum_required (VERSION 3.9)
-project (nix-plugins)
-set (nix-plugins_VERSION_MAJOR 15)
-set (nix-plugins_VERSION_MINOR 0)
-set (nix-plugins_VERSION_PATCH 0)
-
-find_package(PkgConfig)
-
-pkg_check_modules(NIX REQUIRED nix-expr>=2.24 nix-main>=2.24 nix-store>=2.24)
-
-find_path(BOOST_INCLUDE_DIR boost/format.hpp)
-if(BOOST_INCLUDE_DIR STREQUAL "BOOST_INCLUDE_DIR-NOTFOUND")
- message(FATAL_ERROR "Could not find Boost formatting library.")
-endif()
-include_directories(${BOOST_INCLUDE_DIR})
-
-if(APPLE)
- set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -flat_namespace -undefined suppress")
-endif()
-
-add_library(nix-extra-builtins MODULE extra-builtins.cc)
-configure_file(nix-plugins-config.h.in nix-plugins-config.h)
-target_include_directories(nix-extra-builtins PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
-target_include_directories(nix-extra-builtins PUBLIC ${NIX_INCLUDE_DIRS})
-target_compile_options(nix-extra-builtins PUBLIC ${NIX_CFLAGS_OTHER})
-
-install(TARGETS nix-extra-builtins DESTINATION lib/nix/plugins)
diff --git a/extra-builtins.cc b/extra-builtins.cc
index 3a0f90e..a96e7c7 100644
--- a/extra-builtins.cc
+++ b/extra-builtins.cc
@@ -1,12 +1,8 @@
#include <config.h>
#include <primops.hh>
#include <globals.hh>
-#include <config-global.hh>
#include <eval-settings.hh>
#include <common-eval-args.hh>
-#include <filtering-source-accessor.hh>
-
-#include "nix-plugins-config.h"
using namespace nix;
@@ -24,9 +20,8 @@ static GlobalConfig::Register rp(&extraBuiltinsSettings);
static void extraBuiltins(EvalState & state, const PosIdx pos,
Value ** _args, Value & v)
{
- static auto extraBuiltinsFile = state.rootPath(CanonPath(extraBuiltinsSettings.extraBuiltinsFile.to_string()));
- if (auto rootFS2 = state.rootFS.dynamic_pointer_cast<AllowListSourceAccessor>())
- rootFS2->allowPrefix(CanonPath(extraBuiltinsFile.path.abs()));
+ static auto extraBuiltinsFile = state.rootPath(
+ CanonPath(extraBuiltinsSettings.extraBuiltinsFile.to_string()));
try {
auto fun = state.allocValue();
@@ -56,7 +51,7 @@ static void extraBuiltins(EvalState & state, const PosIdx pos,
}
v.mkApp(fun, arg);
state.forceValue(v, pos);
- } catch (FileNotFound &) {
+ } catch (SysError &) {
v.mkNull();
}
}
@@ -66,19 +61,3 @@ static RegisterPrimOp rp1({
.arity = 0,
.fun = extraBuiltins,
});
-
-static void cflags(EvalState & state, const PosIdx _pos,
- Value ** _args, Value & v)
-{
- auto attrs = state.buildBindings(3);
- attrs.alloc("NIX_INCLUDE_DIRS").mkString(NIX_INCLUDE_DIRS);
- attrs.alloc("NIX_CFLAGS_OTHER").mkString(NIX_CFLAGS_OTHER);
- attrs.alloc("BOOST_INCLUDE_DIR").mkString(BOOST_INCLUDE_DIR);
- v.mkAttrs(attrs);
-}
-
-static RegisterPrimOp rp2({
- .name = "__nix-cflags",
- .arity = 0,
- .fun = cflags,
-});
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..0be6ce6
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,18 @@
+project('lix-plugins',
+ ['c', 'cpp'],
+ default_options: ['cpp_std=gnu++20'],
+ version: '15.0.0')
+
+cpp = meson.get_compiler('cpp')
+pkgconfig = import('pkgconfig')
+
+lix_expr = dependency('lix-expr', version: '>=2.91')
+lix_store = dependency('lix-store', version: '>=2.91')
+lix_cmd = dependency('lix-cmd', version: '>=2.91')
+lix_main = dependency('lix-main', version: '>=2.91')
+boost = dependency('boost')
+
+library('lix-plugins',
+ 'extra-builtins.cc',
+ dependencies: [lix_expr, lix_store, lix_cmd, lix_main, boost],
+ install: true)
diff --git a/nix-plugins-config.h.in b/nix-plugins-config.h.in
deleted file mode 100644
index 459fea8..0000000
--- a/nix-plugins-config.h.in
+++ /dev/null
@@ -1,3 +0,0 @@
-#define NIX_INCLUDE_DIRS "@NIX_INCLUDE_DIRS@"
-#define NIX_CFLAGS_OTHER "@NIX_CFLAGS_OTHER@"
-#define BOOST_INCLUDE_DIR "@BOOST_INCLUDE_DIR@"
--
2.47.0

View File

@ -0,0 +1,33 @@
{
fetchFromGitHub,
stdenv,
meson,
ninja,
pkg-config,
lix,
boost182,
}: stdenv.mkDerivation {
name = "lix-plugins";
src = fetchFromGitHub {
owner = "shlevy";
repo = "nix-plugins";
rev = "15.0.0";
hash = "sha256-C4VqKHi6nVAHuXVhqvTRRyn0Bb619ez4LzgUWPH1cbM=";
};
patches = [ ./0001-implement-lix-support.patch ];
mesonBuildType = "release";
nativeBuildInputs = [
meson
ninja
pkg-config
];
buildInputs = [
lix
boost182
];
}