aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ci.nix1
-rw-r--r--examples/hello_world.nix3
-rw-r--r--examples/simple.nix11
-rw-r--r--flake.lock42
-rw-r--r--flake.nix28
-rw-r--r--lib/default.nix3
-rw-r--r--pkgs/default.nix55
7 files changed, 104 insertions, 39 deletions
diff --git a/ci.nix b/ci.nix
index 902d43c..266e176 100644
--- a/ci.nix
+++ b/ci.nix
@@ -20,7 +20,6 @@ in
haskell = writeTest "Rolf" simples.haskell;
js = writeTest "function add(n,d){return n+d}" simples.js;
perl = writeTest "Howdy!" simples.perl;
- python2 = writeTest "['some', 'random', 'variables']" simples.python2;
python3 = writeTest "['some', 'random', 'variables']" simples.python3;
sed = writeTest "hello world" simples.sed;
}
diff --git a/examples/hello_world.nix b/examples/hello_world.nix
index 4f9330a..f71804f 100644
--- a/examples/hello_world.nix
+++ b/examples/hello_world.nix
@@ -24,9 +24,6 @@ in {
perl = pkgs.writePerl "hello-world" {} ''
print "hello world\n";
'';
- python2 = pkgs.writePython2 "hello-world" {} ''
- print "hello world"
- '';
python3 = pkgs.writePython3 "hello-world" {} ''
print("hello world")
'';
diff --git a/examples/simple.nix b/examples/simple.nix
index 55ccedc..8f252e3 100644
--- a/examples/simple.nix
+++ b/examples/simple.nix
@@ -24,15 +24,6 @@ in {
use boolean;
print "Howdy!\n" if true;
'';
- python2 = pkgs.writePython2 "simple.py" { deps = [ pkgs.python2Packages.pyyaml ]; } ''
- import yaml
-
- print yaml.load("""
- - some
- - random
- - variables
- """)
- '';
python3 = pkgs.writePython3 "simple.py" { deps = [ pkgs.python3Packages.pyyaml ]; } ''
import yaml
@@ -40,7 +31,7 @@ in {
- some
- random
- variables
- """))
+ """, Loader=yaml.Loader))
'';
sed = pkgs.writeDash "sed-example" ''
echo hello | ${pkgs.writeSed "hello-world" "s/hello/& world/"}
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 0000000..353d3b9
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,42 @@
+{
+ "nodes": {
+ "flake-utils": {
+ "locked": {
+ "lastModified": 1676283394,
+ "narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=",
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073",
+ "type": "github"
+ },
+ "original": {
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "type": "github"
+ }
+ },
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1677608380,
+ "narHash": "sha256-k82O23qBAK+43X0KSBjsMYXG2x4kWWXeAmpPTc2KRGY=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "4aba90e89f6d4ac6138939961f62842bd94ec929",
+ "type": "github"
+ },
+ "original": {
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "flake-utils": "flake-utils",
+ "nixpkgs": "nixpkgs"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..265ce00
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,28 @@
+{
+ description = "nix library extension, containing sophisticated script and code generator functions";
+
+ inputs = {
+ flake-utils.url = "github:numtide/flake-utils";
+ nixpkgs.url = "github:NixOS/nixpkgs";
+ };
+
+ outputs = inputs @ {
+ self,
+ nixpkgs,
+ flake-utils,
+ }: let
+ nix-writersOverlay = import ./pkgs;
+ in
+ {
+ overlays = {
+ nix-writers = nix-writersOverlay;
+ default = nix-writersOverlay;
+ };
+ }
+ // flake-utils.lib.eachDefaultSystem (system: let
+ pkgs = import nixpkgs {inherit system;};
+ nix-writers = nix-writersOverlay pkgs pkgs;
+ in {
+ legacyPackages = nix-writers;
+ });
+}
diff --git a/lib/default.nix b/lib/default.nix
index 01d43f7..bf634b6 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -1,3 +1,4 @@
+{ nixpkgs }:
let {
body = lib;
@@ -19,6 +20,4 @@ let {
testString = re: x: match re x != null;
types = nixpkgs.lib.types // import ./types.nix { lib = body; };
});
-
- nixpkgs.lib = import <nixpkgs/lib>;
}
diff --git a/pkgs/default.nix b/pkgs/default.nix
index 21b837c..1c616bb 100644
--- a/pkgs/default.nix
+++ b/pkgs/default.nix
@@ -17,9 +17,9 @@
# nix-build hello_world.nix.
#
-with import ../lib;
-
-pkgs: oldpkgs: {
+pkgs: oldpkgs:
+with import ../lib { nixpkgs = pkgs; };
+{
exec = name: { filename, argv ? null, envp ? null, destination ? "" }:
pkgs.writeC name { inherit destination; } /* c */ ''
#include <unistd.h>
@@ -194,18 +194,18 @@ pkgs: oldpkgs: {
libraries ? {}
}: text: pkgs.runCommand name {
inherit text;
- buildInputs = [ pkgs.pkgconfig ] ++ attrValues libraries;
+ buildInputs = [ pkgs.pkg-config ] ++ attrValues libraries;
passAsFile = [ "text" ];
} /* sh */ ''
PATH=${makeBinPath [
pkgs.binutils-unwrapped
pkgs.coreutils
- pkgs.gcc
- pkgs.pkgconfig
+ pkgs.pkg-config
+ pkgs.stdenv.cc
]}
exe=$out${destination}
mkdir -p "$(dirname "$exe")"
- gcc \
+ cc \
${optionalString (libraries != [])
/* sh */ "$(pkg-config --cflags --libs ${
concatMapStringsSep " " escapeShellArg (attrNames libraries)
@@ -216,7 +216,9 @@ pkgs: oldpkgs: {
-Wall \
-x c \
"$textPath"
- strip --strip-unneeded "$exe"
+ ${optionalString (!pkgs.stdenv.hostPlatform.isDarwin) /* sh */ ''
+ strip --strip-unneeded "$exe"
+ ''}
'';
# Like writeScript but the first line is a shebang to dash
@@ -233,6 +235,20 @@ pkgs: oldpkgs: {
assert types.filename.check name;
pkgs.writeDash "/bin/${name}";
+ writeDeno = name: text: let
+ script = pkgs.writeTextFile { name = "${name}.deno"; inherit text; };
+ in
+ pkgs.writeDash name ''
+ exec ${pkgs.deno}/bin/deno run \
+ --allow-all \
+ --quiet \
+ ${script} "$@"
+ '';
+
+ writeDenoBin = name:
+ assert types.filename.check name;
+ pkgs.writeDeno "/bin/${name}";
+
writeEximConfig = name: text: pkgs.runCommand name {
inherit text;
passAsFile = [ "text" ];
@@ -243,6 +259,13 @@ pkgs: oldpkgs: {
mv "$textPath" $out
'';
+ writeGawk = pkgs.makeScriptWriter {
+ interpreter = "${pkgs.gawk}/bin/awk -f";
+ };
+
+ writeGawkBin = name:
+ pkgs.writeGawk "/bin/${name}";
+
writeHaskell = name: extra-depends: text:
pkgs.stdenv.mkDerivation {
inherit name;
@@ -401,6 +424,7 @@ pkgs: oldpkgs: {
} /* sh */ ''
cp "$textPath" $out
${pkgs.nginx-config-formatter}/bin/nginxfmt $out
+ ${pkgs.gnused}/bin/sed -i '/^$/d' $out
${pkgs.gixy}/bin/gixy $out
'';
@@ -430,21 +454,6 @@ pkgs: oldpkgs: {
writePerlBin = name:
pkgs.writePerl "/bin/${name}";
- writePython2 = name: { deps ? [], flakeIgnore ? [] }:
- let
- py = pkgs.python2.withPackages (ps: deps);
- ignoreAttribute = optionalString (flakeIgnore != []) "--ignore ${concatMapStringsSep "," escapeShellArg flakeIgnore}";
- in
- pkgs.makeScriptWriter {
- interpreter = "${py}/bin/python";
- check = pkgs.writeDash "python2check.sh" ''
- exec ${pkgs.python2Packages.flake8}/bin/flake8 --show-source ${ignoreAttribute} "$1"
- '';
- } name;
-
- writePython2Bin = name:
- pkgs.writePython2 "/bin/${name}";
-
writePython3 = name: { deps ? [], flakeIgnore ? [] }:
let
py = pkgs.python3.withPackages (ps: deps);