Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions pkgs/tools/nix/nixos-option/default.nix
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
{ lib
, stdenv
, boost
, cmake
, pkg-config
, installShellFiles
, nix
{
lib,
stdenv,
boost,
meson,
ninja,
pkg-config,
installShellFiles,
nix,
}:

stdenv.mkDerivation {
name = "nixos-option";

src = ./src;
src = ./.;

postInstall = ''
installManPage ${./nixos-option.8}
installManPage ../nixos-option.8
'';

strictDeps = true;

nativeBuildInputs = [
cmake
meson
ninja
pkg-config
installShellFiles
];
buildInputs = [
boost
nix
];
cmakeFlags = [
"-DNIX_DEV_INCLUDEPATH=${nix.dev}/include/nix"
];

meta = with lib; {
license = licenses.lgpl2Plus;
Expand Down
15 changes: 15 additions & 0 deletions pkgs/tools/nix/nixos-option/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
project('nixos-option', 'cpp',
version : '0.1.6',
license : 'GPL-3.0',
)

nix_main_dep = dependency('nix-main', required: true)
nix_store_dep = dependency('nix-store', required: true)
nix_expr_dep = dependency('nix-expr', required: true)
nix_cmd_dep = dependency('nix-cmd', required: true)
nix_flake_dep = dependency('nix-flake', required: true)
threads_dep = dependency('threads', required: true)
nlohmann_json_dep = dependency('nlohmann_json', required: true)
boost_dep = dependency('boost', required: true)

subdir('src')
11 changes: 0 additions & 11 deletions pkgs/tools/nix/nixos-option/src/CMakeLists.txt

This file was deleted.

76 changes: 9 additions & 67 deletions pkgs/tools/nix/nixos-option/src/libnix-copy-paste.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,79 +2,21 @@
// Since they are not, copy/paste them here.
// TODO: Delete these and use the ones in the library as they become available.

#include <nix/config.h> // for nix/globals.hh's reference to SYSTEM

#include "libnix-copy-paste.hh"
#include <boost/format/alt_sstream.hpp> // for basic_altstringbuf...
#include <boost/format/alt_sstream_impl.hpp> // for basic_altstringbuf...
#include <boost/optional/optional.hpp> // for get_pointer
#include <iostream> // for operator<<, basic_...
#include <nix/types.hh> // for Strings
#include <nix/error.hh> // for Error
#include <string> // for string, basic_string

using nix::Error;
using nix::Strings;
using std::string;

// From nix/src/libexpr/attr-path.cc
Strings parseAttrPath(const string & s)
{
Strings res;
string cur;
string::const_iterator i = s.begin();
while (i != s.end()) {
if (*i == '.') {
res.push_back(cur);
cur.clear();
} else if (*i == '"') {
++i;
while (1) {
if (i == s.end())
throw Error("missing closing quote in selection path '%1%'", s);
if (*i == '"')
break;
cur.push_back(*i++);
}
} else
cur.push_back(*i);
++i;
}
if (!cur.empty())
res.push_back(cur);
return res;
}
#include <nix/print.hh> // for Strings

// From nix/src/nix/repl.cc
bool isVarName(const string & s)
bool isVarName(const std::string_view & s)
{
if (s.size() == 0)
return false;
if (s.size() == 0) return false;
if (nix::isReservedKeyword(s)) return false;
char c = s[0];
if ((c >= '0' && c <= '9') || c == '-' || c == '\'')
return false;
if ((c >= '0' && c <= '9') || c == '-' || c == '\'') return false;
for (auto & i : s)
if (!((i >= 'a' && i <= 'z') || (i >= 'A' && i <= 'Z') || (i >= '0' && i <= '9') || i == '_' || i == '-' ||
i == '\''))
if (!((i >= 'a' && i <= 'z') ||
(i >= 'A' && i <= 'Z') ||
(i >= '0' && i <= '9') ||
i == '_' || i == '-' || i == '\''))
return false;
return true;
}

// From nix/src/nix/repl.cc
std::ostream & printStringValue(std::ostream & str, const char * string)
{
str << "\"";
for (const char * i = string; *i; i++)
if (*i == '\"' || *i == '\\')
str << "\\" << *i;
else if (*i == '\n')
str << "\\n";
else if (*i == '\r')
str << "\\r";
else if (*i == '\t')
str << "\\t";
else
str << *i;
str << "\"";
return str;
}
6 changes: 1 addition & 5 deletions pkgs/tools/nix/nixos-option/src/libnix-copy-paste.hh
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#pragma once

#include <iostream>
#include <nix/types.hh>
#include <string>

nix::Strings parseAttrPath(const std::string & s);
bool isVarName(const std::string & s);
std::ostream & printStringValue(std::ostream & str, const char * string);
bool isVarName(const std::string_view & s);
20 changes: 20 additions & 0 deletions pkgs/tools/nix/nixos-option/src/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
src = [
'nixos-option.cc',
'libnix-copy-paste.cc',
]

cc = meson.get_compiler('cpp')

executable('nixos-option', src,
dependencies : [
nix_main_dep,
nix_store_dep,
nix_expr_dep,
nix_cmd_dep,
nix_flake_dep,
boost_dep,
nlohmann_json_dep,
threads_dep
],
install: true,
cpp_args: ['-std=c++2a', '--include', 'nix/config.h'])
Loading