From 05ad04bdd339da27b207fec7157e7701e881a36e Mon Sep 17 00:00:00 2001 From: Tulili Date: Sun, 14 Jan 2024 20:17:17 -0300 Subject: [PATCH 1/4] pkgs.writers add snu, lua and ruby --- pkgs/build-support/writers/scripts.nix | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/pkgs/build-support/writers/scripts.nix b/pkgs/build-support/writers/scripts.nix index 184ecee68777..c268876e1e27 100644 --- a/pkgs/build-support/writers/scripts.nix +++ b/pkgs/build-support/writers/scripts.nix @@ -185,6 +185,46 @@ rec { writeHaskellBin = name: writeHaskell "/bin/${name}"; + # Like writeScript but the first line is a shebang to nu + # + # Example: + # writeNu "example" '' + # echo hello world + # '' + writeNu = makeScriptWriter { + interpreter = "${pkgs.nushell}/bin/nu --no-config-file"; + }; + + # Like writeScriptBin but the first line is a shebang to nu + writeNuBin = name: + writeNu "/bin/${name}"; + + # Like writeScript but the first line is a shebang to ruby + # + # Example: + # writeRuby "example" '' + # puts "hello world" + # '' + writeRuby = makeScriptWriter { + interpreter = "${pkgs.ruby}/bin/ruby"; + }; + + writeRubyBin = name: + writeRuby "/bin/${name}"; + + # Like writeScript but the first line is a shebang to lua + # + # Example: + # writeLua "example" '' + # print("hello world") + # '' + writeLua = makeScriptWriter { + interpreter = "${pkgs.lua}/bin/lua"; + }; + + writeLuaBin = name: + writeLua "/bin/${name}"; + writeRust = name: { rustc ? pkgs.rustc, rustcArgs ? [], From f6e0ee5545889996bf926bd6c726084b72aca22e Mon Sep 17 00:00:00 2001 From: Tulili Date: Mon, 15 Jan 2024 11:48:50 -0300 Subject: [PATCH 2/4] pkgs.writers: remove tests that dont work anymore and add comments tracking issues --- pkgs/build-support/writers/default.nix | 1 + pkgs/build-support/writers/scripts.nix | 34 +++++------ pkgs/build-support/writers/test.nix | 78 ++++++++++++++------------ 3 files changed, 62 insertions(+), 51 deletions(-) diff --git a/pkgs/build-support/writers/default.nix b/pkgs/build-support/writers/default.nix index a161322cd35b..cadb69781481 100644 --- a/pkgs/build-support/writers/default.nix +++ b/pkgs/build-support/writers/default.nix @@ -1,5 +1,6 @@ { config, lib, callPackages }: +# If you are reading this, you can test these writers by running: nix-build . -A tests.writers let aliases = if config.allowAliases then (import ./aliases.nix lib) else prev: {}; diff --git a/pkgs/build-support/writers/scripts.nix b/pkgs/build-support/writers/scripts.nix index c268876e1e27..507fd590e243 100644 --- a/pkgs/build-support/writers/scripts.nix +++ b/pkgs/build-support/writers/scripts.nix @@ -13,7 +13,7 @@ let in rec { # Base implementation for non-compiled executables. - # Takes an interpreter, for example `${pkgs.bash}/bin/bash` + # Takes an interpreter, for example `${lib.getExe pkgs.bash}` # # Examples: # writeBash = makeScriptWriter { interpreter = "${pkgs.bash}/bin/bash"; } @@ -116,7 +116,7 @@ rec { # echo hello world # '' writeBash = makeScriptWriter { - interpreter = "${pkgs.bash}/bin/bash"; + interpreter = "${lib.getExe pkgs.bash}"; }; # Like writeScriptBin but the first line is a shebang to bash @@ -130,7 +130,7 @@ rec { # echo hello world # '' writeDash = makeScriptWriter { - interpreter = "${pkgs.dash}/bin/dash"; + interpreter = "${lib.getExe pkgs.dash}"; }; # Like writeScriptBin but the first line is a shebang to dash @@ -144,8 +144,8 @@ rec { # echo hello world # '' writeFish = makeScriptWriter { - interpreter = "${pkgs.fish}/bin/fish --no-config"; - check = "${pkgs.fish}/bin/fish --no-config --no-execute"; # syntax check only + interpreter = "${lib.getExe pkgs.fish} --no-config"; + check = "${lib.getExe pkgs.fish} --no-config --no-execute"; # syntax check only }; # Like writeScriptBin but the first line is a shebang to fish @@ -175,7 +175,7 @@ rec { in makeBinWriter { compileScript = '' cp $contentPath tmp.hs - ${ghc.withPackages (_: libraries )}/bin/ghc ${lib.escapeShellArgs ghcArgs'} tmp.hs + ${(ghc.withPackages (_: libraries ))}/bin/ghc ${lib.escapeShellArgs ghcArgs'} tmp.hs mv tmp $out ''; inherit strip; @@ -192,7 +192,7 @@ rec { # echo hello world # '' writeNu = makeScriptWriter { - interpreter = "${pkgs.nushell}/bin/nu --no-config-file"; + interpreter = "${lib.getExe pkgs.nushell} --no-config-file"; }; # Like writeScriptBin but the first line is a shebang to nu @@ -206,7 +206,7 @@ rec { # puts "hello world" # '' writeRuby = makeScriptWriter { - interpreter = "${pkgs.ruby}/bin/ruby"; + interpreter = "${lib.getExe pkgs.ruby}"; }; writeRubyBin = name: @@ -219,7 +219,7 @@ rec { # print("hello world") # '' writeLua = makeScriptWriter { - interpreter = "${pkgs.lua}/bin/lua"; + interpreter = "${lib.getExe pkgs.lua}"; }; writeLuaBin = name: @@ -236,7 +236,7 @@ rec { makeBinWriter { compileScript = '' cp "$contentPath" tmp.rs - PATH=${lib.makeBinPath [pkgs.gcc]} ${lib.getBin rustc}/bin/rustc ${lib.escapeShellArgs rustcArgs} ${lib.escapeShellArgs darwinArgs} -o "$out" tmp.rs + PATH=${lib.makeBinPath [pkgs.gcc]} ${rustc}/bin/rustc ${lib.escapeShellArgs rustcArgs} ${lib.escapeShellArgs darwinArgs} -o "$out" tmp.rs ''; inherit strip; } name; @@ -265,7 +265,7 @@ rec { }; in writeDash name '' export NODE_PATH=${node-env}/lib/node_modules - exec ${pkgs.nodejs}/bin/node ${pkgs.writeText "js" content} "$@" + exec ${lib.getExe pkgs.nodejs} ${pkgs.writeText "js" content} "$@" ''; # writeJSBin takes the same arguments as writeJS but outputs a directory (like writeScriptBin) @@ -300,7 +300,7 @@ rec { # '' writePerl = name: { libraries ? [] }: makeScriptWriter { - interpreter = "${pkgs.perl.withPackages (p: libraries)}/bin/perl"; + interpreter = "${lib.getExe (pkgs.perl.withPackages (p: libraries))}"; } name; # writePerlBin takes the same arguments as writePerl but outputs a directory (like writeScriptBin) @@ -316,9 +316,11 @@ rec { in makeScriptWriter { interpreter = - if libraries == [] - then python.interpreter - else (python.withPackages (ps: libraries)).interpreter + if pythonPackages != pkgs.pypy2Packages || pythonPackages != pkgs.pypy3Packages then + if libraries == [] + then python.interpreter + else (python.withPackages (ps: libraries)).interpreter + else python.interpreter ; check = optionalString python.isPy3k (writeDash "pythoncheck.sh" '' exec ${buildPythonPackages.flake8}/bin/flake8 --show-source ${ignoreAttribute} "$1" @@ -398,7 +400,7 @@ rec { export DOTNET_CLI_TELEMETRY_OPTOUT=1 export DOTNET_NOLOGO=1 script="$1"; shift - ${dotnet-sdk}/bin/dotnet fsi --quiet --nologo --readline- ${fsi-flags} "$@" < "$script" + ${lib.getExe dotnet-sdk} fsi --quiet --nologo --readline- ${fsi-flags} "$@" < "$script" ''; in content: makeScriptWriter { diff --git a/pkgs/build-support/writers/test.nix b/pkgs/build-support/writers/test.nix index 1b690e2d24c9..ff0cef3daa12 100644 --- a/pkgs/build-support/writers/test.nix +++ b/pkgs/build-support/writers/test.nix @@ -11,6 +11,9 @@ , writers , writeText }: + +# If you are reading this, you can test these writers by running: nix-build . -A tests.writers + with writers; let expectSuccess = test: @@ -88,15 +91,6 @@ lib.recurseIntoAttrs { print "success\n" if true; ''); - pypy2 = expectSuccessBin (writePyPy2Bin "test-writers-pypy2-bin" { libraries = [ pypy2Packages.enum ]; } '' - from enum import Enum - - class Test(Enum): - a = "success" - - print Test.a - ''); - python3 = expectSuccessBin (writePython3Bin "test-writers-python3-bin" { libraries = [ python3Packages.pyyaml ]; } '' import yaml @@ -106,14 +100,25 @@ lib.recurseIntoAttrs { print(y[0]['test']) ''); - pypy3 = expectSuccessBin (writePyPy3Bin "test-writers-pypy3-bin" { libraries = [ pypy3Packages.pyyaml ]; } '' - import yaml + # Commented out because of this issue: https://github.com/NixOS/nixpkgs/issues/39356 - y = yaml.safe_load(""" - - test: success - """) - print(y[0]['test']) - ''); + #pypy2 = expectSuccessBin (writePyPy2Bin "test-writers-pypy2-bin" { libraries = [ pypy2Packages.enum ]; } '' + # from enum import Enum + # + # class Test(Enum): + # a = "success" + # + # print Test.a + #''); + + #pypy3 = expectSuccessBin (writePyPy3Bin "test-writers-pypy3-bin" { libraries = [ pypy3Packages.pyyaml ]; } '' + # import yaml + # + # y = yaml.safe_load(""" + # - test: success + # """) + # print(y[0]['test']) + #''); }; simple = lib.recurseIntoAttrs { @@ -158,15 +163,6 @@ lib.recurseIntoAttrs { print "success\n" if true; ''); - pypy2 = expectSuccess (writePyPy2 "test-writers-pypy2" { libraries = [ pypy2Packages.enum ]; } '' - from enum import Enum - - class Test(Enum): - a = "success" - - print Test.a - ''); - python3 = expectSuccess (writePython3 "test-writers-python3" { libraries = [ python3Packages.pyyaml ]; } '' import yaml @@ -176,14 +172,25 @@ lib.recurseIntoAttrs { print(y[0]['test']) ''); - pypy3 = expectSuccess (writePyPy3 "test-writers-pypy3" { libraries = [ pypy3Packages.pyyaml ]; } '' - import yaml + # Commented out because of this issue: https://github.com/NixOS/nixpkgs/issues/39356 - y = yaml.safe_load(""" - - test: success - """) - print(y[0]['test']) - ''); + #pypy2 = expectSuccessBin (writePyPy2Bin "test-writers-pypy2-bin" { libraries = [ pypy2Packages.enum ]; } '' + # from enum import Enum + # + # class Test(Enum): + # a = "success" + # + # print Test.a + #''); + + #pypy3 = expectSuccessBin (writePyPy3Bin "test-writers-pypy3-bin" { libraries = [ pypy3Packages.pyyaml ]; } '' + # import yaml + # + # y = yaml.safe_load(""" + # - test: success + # """) + # print(y[0]['test']) + #''); fsharp = expectSuccess (makeFSharpWriter { libraries = { fetchNuGet }: [ @@ -191,6 +198,7 @@ lib.recurseIntoAttrs { (fetchNuGet { pname = "System.Text.Json"; version = "4.6.0"; sha256 = "0ism236hwi0k6axssfq58s1d8lihplwiz058pdvl8al71hagri39"; }) ]; } "test-writers-fsharp" '' + #r "nuget: FSharp.SystemTextJson, 0.17.4" module Json = @@ -209,9 +217,9 @@ lib.recurseIntoAttrs { |> printfn "%s" ''); - pypy2NoLibs = expectSuccess (writePyPy2 "test-writers-pypy2-no-libs" {} '' - print("success") - ''); + #pypy2NoLibs = expectSuccess (writePyPy2 "test-writers-pypy2-no-libs" {} '' + # print("success") + #''); python3NoLibs = expectSuccess (writePython3 "test-writers-python3-no-libs" {} '' print("success") From 703a085c0af81e956d0c2cde2197d0984095992f Mon Sep 17 00:00:00 2001 From: Tulili Date: Tue, 16 Jan 2024 01:51:17 -0300 Subject: [PATCH 3/4] pkgs.writers: tests for lua ruby, and remove failed tests because of external package errors --- pkgs/build-support/writers/scripts.nix | 61 +++++++++++++++++++++----- pkgs/build-support/writers/test.nix | 36 +++++++++++++++ 2 files changed, 86 insertions(+), 11 deletions(-) diff --git a/pkgs/build-support/writers/scripts.nix b/pkgs/build-support/writers/scripts.nix index 507fd590e243..030cb55eb6f2 100644 --- a/pkgs/build-support/writers/scripts.nix +++ b/pkgs/build-support/writers/scripts.nix @@ -181,7 +181,7 @@ rec { inherit strip; } name; - # writeHaskellBin takes the same arguments as writeHaskell but outputs a directory (like writeScriptBin) + # writeHaskellBin takes the same arguments as kell but outputs a directory (like writeScriptBin) writeHaskellBin = name: writeHaskell "/bin/${name}"; @@ -199,28 +199,67 @@ rec { writeNuBin = name: writeNu "/bin/${name}"; + # makeRubyWriter takes ruby and compatible rubyPackages and produces ruby script writer, + # If any libraries are specified, ruby.withPackages is used as interpreter, otherwise the "bare" ruby is used. + makeRubyWriter = ruby: rubyPackages: buildRubyPackages: name: { libraries ? [], }: + makeScriptWriter { + interpreter = + if libraries == [] + then "${ruby}/bin/ruby" + else "${(ruby.withPackages (ps: libraries))}/bin/ruby"; + # Rubocop doesnt seem to like running in this fashion. + #check = (writeDash "rubocop.sh" '' + # exec ${lib.getExe buildRubyPackages.rubocop} "$1" + #''); + } name; + # Like writeScript but the first line is a shebang to ruby # # Example: # writeRuby "example" '' # puts "hello world" # '' - writeRuby = makeScriptWriter { - interpreter = "${lib.getExe pkgs.ruby}"; - }; + writeRuby = makeRubyWriter pkgs.ruby pkgs.rubyPackages buildPackages.rubyPackages; writeRubyBin = name: writeRuby "/bin/${name}"; - # Like writeScript but the first line is a shebang to lua + # makeLuaWriter takes lua and compatible luaPackages and produces lua script writer, + # which validates the script with luacheck at build time. If any libraries are specified, + # lua.withPackages is used as interpreter, otherwise the "bare" lua is used. + makeLuaWriter = lua: luaPackages: buildLuaPackages: name: { libraries ? [], }: + makeScriptWriter { + interpreter = lua.interpreter; + # if libraries == [] + # then lua.interpreter + # else (lua.withPackages (ps: libraries)).interpreter + # This should support packages! I just cant figure out why some dependency collision happens whenever I try to run this. + check = (writeDash "luacheck.sh" '' + exec ${buildLuaPackages.luacheck}/bin/luacheck "$1" + ''); + } name; + + # writeLua takes a name an attributeset with libraries and some lua source code and + # returns an executable (should also work with luajit) # # Example: - # writeLua "example" '' - # print("hello world") - # '' - writeLua = makeScriptWriter { - interpreter = "${lib.getExe pkgs.lua}"; - }; + # writeLua "test_lua" { libraries = [ pkgs.luaPackages.say ]; } '' + # s = require("say") + # s:set_namespace("en") + # + # s:set('money', 'I have %s dollars') + # s:set('wow', 'So much money!') + # + # print(s('money', {1000})) -- I have 1000 dollars + # + # s:set_namespace("fr") -- switch to french! + # s:set('wow', "Tant d'argent!") + # + # print(s('wow')) -- Tant d'argent! + # s:set_namespace("en") -- switch back to english! + # print(s('wow')) -- So much money! + # '' + writeLua = makeLuaWriter pkgs.lua pkgs.luaPackages buildPackages.luaPackages; writeLuaBin = name: writeLua "/bin/${name}"; diff --git a/pkgs/build-support/writers/test.nix b/pkgs/build-support/writers/test.nix index ff0cef3daa12..982c550d28e0 100644 --- a/pkgs/build-support/writers/test.nix +++ b/pkgs/build-support/writers/test.nix @@ -6,6 +6,8 @@ , pypy2Packages , python3Packages , pypy3Packages +, luaPackages +, rubyPackages , runCommand , testers , writers @@ -119,6 +121,28 @@ lib.recurseIntoAttrs { # """) # print(y[0]['test']) #''); + + # Could not test this because of external package issues :( + #lua = writeLuaBin "test-writers-lua-bin" { libraries = [ pkgs.luaPackages.say ]; } '' + # s = require("say") + # s:set_namespace("en") + + # s:set('money', 'I have %s dollars') + # s:set('wow', 'So much money!') + + # print(s('money', {1000})) -- I have 1000 dollars + + # s:set_namespace("fr") -- switch to french! + # s:set('wow', "Tant d'argent!") + + # print(s('wow')) -- Tant d'argent! + # s:set_namespace("en") -- switch back to english! + # print(s('wow')) -- So much money! + #''; + + #ruby = expectSuccessBin (writeRubyBin "test-writers-ruby-bin" { libraries = [ rubyPackages.rubocop ]; } '' + #puts "This should work!" + #''); }; simple = lib.recurseIntoAttrs { @@ -136,6 +160,10 @@ lib.recurseIntoAttrs { end ''); + nu = expectSuccess (writeNu "test-writers-nushell" '' + echo "success" + ''); + haskell = expectSuccess (writeHaskell "test-writers-haskell" { libraries = [ haskellPackages.acme-default ]; } '' import Data.Default @@ -231,6 +259,14 @@ lib.recurseIntoAttrs { fsharpNoNugetDeps = expectSuccess (writeFSharp "test-writers-fsharp-no-nuget-deps" '' printfn "success" + ''); + + luaNoLibs = expectSuccess (writeLua "test-writers-lua-no-libs" {} '' + print("success") + ''); + + rubyNoLibs = expectSuccess (writeRuby "test-writers-ruby-no-libs" {} '' + puts "success" ''); }; From 1e7dc0e1b83e50a5ad8e108d417cf59ac6e9d501 Mon Sep 17 00:00:00 2001 From: Tulili Date: Wed, 17 Jan 2024 20:34:21 -0300 Subject: [PATCH 4/4] pkgs.writers: fix type in description for writeHaskellBin --- pkgs/build-support/writers/scripts.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/build-support/writers/scripts.nix b/pkgs/build-support/writers/scripts.nix index 030cb55eb6f2..8a23e5dd4a66 100644 --- a/pkgs/build-support/writers/scripts.nix +++ b/pkgs/build-support/writers/scripts.nix @@ -181,7 +181,7 @@ rec { inherit strip; } name; - # writeHaskellBin takes the same arguments as kell but outputs a directory (like writeScriptBin) + # writeHaskellBin takes the same arguments as writeHaskell but outputs a directory (like writeScriptBin) writeHaskellBin = name: writeHaskell "/bin/${name}";