Merge pull request 'Automatic flake update - 2024-07-08T00:00+00:00' (#1715) from flake-update-2024-07-08 into main

This commit is contained in:
clan-bot
2024-07-08 14:35:02 +00:00
19 changed files with 333 additions and 580 deletions

3
.envrc
View File

@@ -1,3 +1,4 @@
# shellcheck shell=bash
if ! has nix_direnv_version || ! nix_direnv_version 3.0.4; then if ! has nix_direnv_version || ! nix_direnv_version 3.0.4; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.4/direnvrc" "sha256-DzlYZ33mWF/Gs8DDeyjr8mnVmQGx7ASYqA5WlxwvBG4=" source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.4/direnvrc" "sha256-DzlYZ33mWF/Gs8DDeyjr8mnVmQGx7ASYqA5WlxwvBG4="
fi fi
@@ -5,7 +6,7 @@ fi
watch_file .direnv/selected-shell watch_file .direnv/selected-shell
if [ -e .direnv/selected-shell ]; then if [ -e .direnv/selected-shell ]; then
use flake .#$(cat .direnv/selected-shell) use flake ".#$(cat .direnv/selected-shell)"
else else
use flake use flake
fi fi

View File

@@ -1,100 +0,0 @@
From bc199a27f23b0fcf175b116f7cf606c0d22b422a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= <joerg@thalheim.io>
Date: Tue, 11 Jun 2024 11:40:47 +0200
Subject: [PATCH 1/2] register_new_matrix_user: add password-file flag
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
getpass in python expects stdin to be a tty, hence we cannot just pipe
into register_new_matrix_user. --password-file instead works better and
it would also allow the use of stdin if /dev/stdin is passed.
Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
Signed-off-by: Jörg Thalheim <joerg@thalheim.io>
---
changelog.d/17294.feature | 2 ++
debian/register_new_matrix_user.ronn | 9 +++++++--
synapse/_scripts/register_new_matrix_user.py | 20 +++++++++++++++-----
3 files changed, 24 insertions(+), 7 deletions(-)
create mode 100644 changelog.d/17294.feature
diff --git a/changelog.d/17294.feature b/changelog.d/17294.feature
new file mode 100644
index 000000000..33aac7b0b
--- /dev/null
+++ b/changelog.d/17294.feature
@@ -0,0 +1,2 @@
+`register_new_matrix_user` now supports a --password-file flag, which
+is useful for scripting.
diff --git a/debian/register_new_matrix_user.ronn b/debian/register_new_matrix_user.ronn
index 0410b1f4c..d99e9215a 100644
--- a/debian/register_new_matrix_user.ronn
+++ b/debian/register_new_matrix_user.ronn
@@ -31,8 +31,13 @@ A sample YAML file accepted by `register_new_matrix_user` is described below:
Local part of the new user. Will prompt if omitted.
* `-p`, `--password`:
- New password for user. Will prompt if omitted. Supplying the password
- on the command line is not recommended. Use the STDIN instead.
+ New password for user. Will prompt if this option and `--password-file` are omitted.
+ Supplying the password on the command line is not recommended.
+ Use `--password-file` if possible.
+
+ * `--password-file`:
+ File containing the new password for user. If set, overrides `--password`.
+ This is a more secure alternative to specifying the password on the command line.
* `-a`, `--admin`:
Register new user as an admin. Will prompt if omitted.
diff --git a/synapse/_scripts/register_new_matrix_user.py b/synapse/_scripts/register_new_matrix_user.py
index 77a7129ee..972b35e2d 100644
--- a/synapse/_scripts/register_new_matrix_user.py
+++ b/synapse/_scripts/register_new_matrix_user.py
@@ -173,11 +173,18 @@ def main() -> None:
default=None,
help="Local part of the new user. Will prompt if omitted.",
)
- parser.add_argument(
+ password_group = parser.add_mutually_exclusive_group()
+ password_group.add_argument(
"-p",
"--password",
default=None,
- help="New password for user. Will prompt if omitted.",
+ help="New password for user. Will prompt for a password if "
+ "this flag and `--password-file` are both omitted.",
+ )
+ password_group.add_argument(
+ "--password-file",
+ default=None,
+ help="File containing the new password for user. If set, will override `--password`.",
)
parser.add_argument(
"-t",
@@ -247,6 +254,11 @@ def main() -> None:
print(_NO_SHARED_SECRET_OPTS_ERROR, file=sys.stderr)
sys.exit(1)
+ if args.password_file:
+ password = _read_file(args.password_file, "password-file").strip()
+ else:
+ password = args.password
+
if args.server_url:
server_url = args.server_url
elif config is not None:
@@ -269,9 +281,7 @@ def main() -> None:
if args.admin or args.no_admin:
admin = args.admin
- register_new_user(
- args.user, args.password, server_url, secret, admin, args.user_type
- )
+ register_new_user(args.user, password, server_url, secret, admin, args.user_type)
def _read_file(file_path: Any, config_path: str) -> str:
--
2.44.1

View File

@@ -1,94 +0,0 @@
From 1789416df425d22693b0055a6688d8686e0ee4a1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= <joerg@thalheim.io>
Date: Thu, 13 Jun 2024 14:38:19 +0200
Subject: [PATCH 2/2] register-new-matrix-user: add a flag to ignore already
existing users
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This allows to register users in a more declarative and stateless way.
Signed-off-by: Jörg Thalheim <joerg@thalheim.io>
---
synapse/_scripts/register_new_matrix_user.py | 22 ++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/synapse/_scripts/register_new_matrix_user.py b/synapse/_scripts/register_new_matrix_user.py
index 972b35e2d..233e7267d 100644
--- a/synapse/_scripts/register_new_matrix_user.py
+++ b/synapse/_scripts/register_new_matrix_user.py
@@ -52,6 +52,7 @@ def request_registration(
user_type: Optional[str] = None,
_print: Callable[[str], None] = print,
exit: Callable[[int], None] = sys.exit,
+ exists_ok: bool = False,
) -> None:
url = "%s/_synapse/admin/v1/register" % (server_location.rstrip("/"),)
@@ -97,6 +98,10 @@ def request_registration(
r = requests.post(url, json=data)
if r.status_code != 200:
+ response = r.json()
+ if exists_ok and response["errcode"] == "M_USER_IN_USE":
+ _print("User already exists. Skipping.")
+ return
_print("ERROR! Received %d %s" % (r.status_code, r.reason))
if 400 <= r.status_code < 500:
try:
@@ -115,6 +120,7 @@ def register_new_user(
shared_secret: str,
admin: Optional[bool],
user_type: Optional[str],
+ exists_ok: bool = False,
) -> None:
if not user:
try:
@@ -154,7 +160,13 @@ def register_new_user(
admin = False
request_registration(
- user, password, server_location, shared_secret, bool(admin), user_type
+ user,
+ password,
+ server_location,
+ shared_secret,
+ bool(admin),
+ user_type,
+ exists_ok=exists_ok,
)
@@ -173,6 +185,11 @@ def main() -> None:
default=None,
help="Local part of the new user. Will prompt if omitted.",
)
+ parser.add_argument(
+ "--exists-ok",
+ action="store_true",
+ help="Do not fail if user already exists.",
+ )
password_group = parser.add_mutually_exclusive_group()
password_group.add_argument(
"-p",
@@ -192,6 +209,7 @@ def main() -> None:
default=None,
help="User type as specified in synapse.api.constants.UserTypes",
)
+
admin_group = parser.add_mutually_exclusive_group()
admin_group.add_argument(
"-a",
@@ -281,7 +299,7 @@ def main() -> None:
if args.admin or args.no_admin:
admin = args.admin
- register_new_user(args.user, password, server_url, secret, admin, args.user_type)
+ register_new_user(args.user, password, server_url, secret, admin, args.user_type, exists_ok=args.exists_ok)
def _read_file(file_path: Any, config_path: str) -> str:
--
2.44.1

View File

@@ -17,19 +17,8 @@ let
ln -s $out/config.json $out/config.${nginx-vhost}.json ln -s $out/config.json $out/config.${nginx-vhost}.json
''; '';
# FIXME: This was taken from upstream. Drop this when our patch is upstream
synapseCfg = config.services.matrix-synapse;
wantedExtras =
synapseCfg.extras
++ lib.optional (synapseCfg.settings ? oidc_providers) "oidc"
++ lib.optional (synapseCfg.settings ? jwt_config) "jwt"
++ lib.optional (synapseCfg.settings ? saml2_config) "saml2"
++ lib.optional (synapseCfg.settings ? redis) "redis"
++ lib.optional (synapseCfg.settings ? sentry) "sentry"
++ lib.optional (synapseCfg.settings ? user_directory) "user-search"
++ lib.optional (synapseCfg.settings.url_preview_enabled) "url-preview"
++ lib.optional (synapseCfg.settings.database.name == "psycopg2") "postgres";
in in
# FIXME: This was taken from upstream. Drop this when our patch is upstream
{ {
options.services.matrix-synapse.package = lib.mkOption { readOnly = false; }; options.services.matrix-synapse.package = lib.mkOption { readOnly = false; };
options.clan.matrix-synapse = { options.clan.matrix-synapse = {
@@ -78,21 +67,6 @@ in
]; ];
config = { config = {
services.matrix-synapse = { services.matrix-synapse = {
package = lib.mkForce (
pkgs.matrix-synapse.override {
matrix-synapse-unwrapped = pkgs.matrix-synapse.unwrapped.overrideAttrs (_old: {
doInstallCheck = false; # too slow, nixpkgs maintainer already run this.
patches = [
# see: https://github.com/element-hq/synapse/pull/17304
./0001-register_new_matrix_user-add-password-file-flag.patch
./0002-register-new-matrix-user-add-a-flag-to-ignore-alread.patch
];
});
extras = wantedExtras;
plugins = synapseCfg.plugins;
}
);
enable = true; enable = true;
settings = { settings = {
server_name = cfg.domain; server_name = cfg.domain;

View File

@@ -1,6 +1,8 @@
# shellcheck shell=bash
source_up source_up
watch_file $(find ./nix -name "*.nix" -printf '%p ') mapfile -d '' -t nix_files < <(find ./nix -name "*.nix" -print0)
watch_file "${nix_files[@]}"
# Because we depend on nixpkgs sources, uploading to builders takes a long time # Because we depend on nixpkgs sources, uploading to builders takes a long time
use flake .#docs --builders '' use flake .#docs --builders ''

View File

@@ -26,6 +26,7 @@ pkgs.stdenv.mkDerivation {
mkdocs-material mkdocs-material
mkdocs-rss-plugin mkdocs-rss-plugin
mkdocs-macros mkdocs-macros
filelock # FIXME: this should be already provided by mkdocs-rss-plugin
]); ]);
configurePhase = '' configurePhase = ''
mkdir -p ./site/reference/cli mkdir -p ./site/reference/cli

View File

@@ -38,7 +38,7 @@
patchShebangs --build $out patchShebangs --build $out
ruff format --check --diff $out ruff format --check --diff $out
ruff --line-length 88 $out ruff check --line-length 88 $out
mypy --strict $out mypy --strict $out
''; '';

60
flake.lock generated
View File

@@ -7,11 +7,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1718846788, "lastModified": 1720056646,
"narHash": "sha256-9dtXYtEkmXoUJV+PGLqscqF7qTn4AIhAKpFWRFU2NYs=", "narHash": "sha256-BymcV4HWtx2VFuabDCM4/nEJcfivCx0S02wUCz11mAY=",
"owner": "nix-community", "owner": "nix-community",
"repo": "disko", "repo": "disko",
"rev": "e1174d991944a01eaaa04bc59c6281edca4c0e6e", "rev": "64679cd7f318c9b6595902b47d4585b1d51d5f9e",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -27,11 +27,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1717285511, "lastModified": 1719994518,
"narHash": "sha256-iKzJcpdXih14qYVcZ9QC9XuZYnPc6T8YImb6dX166kw=", "narHash": "sha256-pQMhCCHyQGRzdfAkdJ4cIWiw+JNuWsTX7f0ZYSyz0VY=",
"owner": "hercules-ci", "owner": "hercules-ci",
"repo": "flake-parts", "repo": "flake-parts",
"rev": "2a55567fcf15b1b1c7ed712a2c6fadaec7412ea8", "rev": "9227223f6d922fee3c7b190b2cc238a99527bbb7",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -40,29 +40,6 @@
"type": "github" "type": "github"
} }
}, },
"nixos-generators": {
"inputs": {
"nixlib": [
"nixpkgs"
],
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1718025593,
"narHash": "sha256-WZ1gdKq/9u1Ns/oXuNsDm+W0salonVA0VY1amw8urJ4=",
"owner": "nix-community",
"repo": "nixos-generators",
"rev": "35c20ba421dfa5059e20e0ef2343c875372bdcf3",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixos-generators",
"type": "github"
}
},
"nixos-images": { "nixos-images": {
"inputs": { "inputs": {
"nixos-stable": [], "nixos-stable": [],
@@ -71,11 +48,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1718845599, "lastModified": 1720055024,
"narHash": "sha256-HbQ0iKohKJC5grC95HNjLxGPdgsc/BJgoENDYNbzkLo=", "narHash": "sha256-c5rsiI1R7tnCDpcgfsa7ouSdn6wpctbme9TUp53CFyU=",
"owner": "nix-community", "owner": "nix-community",
"repo": "nixos-images", "repo": "nixos-images",
"rev": "c1e6a5f7b08f1c9993de1cfc5f15f838bf783b88", "rev": "f8650460d37d9d1820a93ebb7f0db5b6c3621946",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -86,11 +63,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1719451888, "lastModified": 1720340162,
"narHash": "sha256-Ky0sgEEJMcBmNEJztY6KcVn+6bq74EKM7pd1CR1wnPQ=", "narHash": "sha256-iVLH0Ygtw/Iw9Q1cFFX7OhNnoPbc7/ZWW6J3c0zbiZw=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "3664857c48feacb35770c00abfdc671e55849be5", "rev": "60a94e515488e335bd5bce096431d490486915e3",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -104,7 +81,6 @@
"inputs": { "inputs": {
"disko": "disko", "disko": "disko",
"flake-parts": "flake-parts", "flake-parts": "flake-parts",
"nixos-generators": "nixos-generators",
"nixos-images": "nixos-images", "nixos-images": "nixos-images",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"sops-nix": "sops-nix", "sops-nix": "sops-nix",
@@ -119,11 +95,11 @@
"nixpkgs-stable": [] "nixpkgs-stable": []
}, },
"locked": { "locked": {
"lastModified": 1719111739, "lastModified": 1720321395,
"narHash": "sha256-kr2QzRrplzlCP87ddayCZQS+dhGW98kw2zy7+jUXtF4=", "narHash": "sha256-kcI8q9Nh8/CSj0ygfWq1DLckHl8IHhFarL8ie6g7OEk=",
"owner": "Mic92", "owner": "Mic92",
"repo": "sops-nix", "repo": "sops-nix",
"rev": "5e2e9421e9ed2b918be0a441c4535cfa45e04811", "rev": "c184aca4db5d71c3db0c8cbfcaaec337a5d065ea",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -139,11 +115,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1718522839, "lastModified": 1720436211,
"narHash": "sha256-ULzoKzEaBOiLRtjeY3YoGFJMwWSKRYOic6VNw2UyTls=", "narHash": "sha256-/cKXod0oGLl+vH4bKBZnTV3qxrw4jgOLnyQ8KXey5J8=",
"owner": "numtide", "owner": "numtide",
"repo": "treefmt-nix", "repo": "treefmt-nix",
"rev": "68eb1dc333ce82d0ab0c0357363ea17c31ea1f81", "rev": "6fc8bded78715cdd43a3278a14ded226eb3a239e",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@@ -13,9 +13,6 @@
sops-nix.url = "github:Mic92/sops-nix"; sops-nix.url = "github:Mic92/sops-nix";
sops-nix.inputs.nixpkgs.follows = "nixpkgs"; sops-nix.inputs.nixpkgs.follows = "nixpkgs";
sops-nix.inputs.nixpkgs-stable.follows = ""; sops-nix.inputs.nixpkgs-stable.follows = "";
nixos-generators.url = "github:nix-community/nixos-generators";
nixos-generators.inputs.nixpkgs.follows = "nixpkgs";
nixos-generators.inputs.nixlib.follows = "nixpkgs";
nixos-images.url = "github:nix-community/nixos-images"; nixos-images.url = "github:nix-community/nixos-images";
nixos-images.inputs.nixos-unstable.follows = "nixpkgs"; nixos-images.inputs.nixos-unstable.follows = "nixpkgs";
# unused input # unused input

View File

@@ -1,4 +1,4 @@
{ lib, inputs, ... }: { inputs, ... }:
{ {
imports = [ inputs.treefmt-nix.flakeModule ]; imports = [ inputs.treefmt-nix.flakeModule ];
perSystem = perSystem =
@@ -8,43 +8,19 @@
treefmt.programs.shellcheck.enable = true; treefmt.programs.shellcheck.enable = true;
treefmt.programs.mypy.enable = true; treefmt.programs.mypy.enable = true;
treefmt.programs.nixfmt.enable = true;
treefmt.programs.nixfmt.package = pkgs.nixfmt-rfc-style;
treefmt.programs.deadnix.enable = true;
treefmt.programs.mypy.directories = { treefmt.programs.mypy.directories = {
"pkgs/clan-cli".extraPythonPackages = self'.packages.clan-cli.testDependencies; "pkgs/clan-cli".extraPythonPackages = self'.packages.clan-cli.testDependencies;
"pkgs/clan-app".extraPythonPackages = "pkgs/clan-app".extraPythonPackages =
# clan-app currently only exists on linux # clan-app currently only exists on linux
(self'.packages.clan-app.externalTestDeps or [ ]) ++ self'.packages.clan-cli.testDependencies; (self'.packages.clan-app.externalTestDeps or [ ]) ++ self'.packages.clan-cli.testDependencies;
}; };
treefmt.programs.ruff.check = true;
treefmt.programs.ruff.format = true;
treefmt.settings.formatter.nix = {
command = "sh";
options = [
"-eucx"
''
# First deadnix
${lib.getExe pkgs.deadnix} --edit "$@"
# Then nixpkgs-fmt
${lib.getExe pkgs.nixfmt-rfc-style} "$@"
''
"--" # this argument is ignored by bash
];
includes = [ "*.nix" ];
excludes = [
# Was copied from nixpkgs. Keep diff minimal to simplify upstreaming.
"pkgs/builders/script-writers.nix"
];
};
treefmt.settings.formatter.python = {
command = "sh";
options = [
"-eucx"
''
${lib.getExe pkgs.ruff} check --fix "$@"
${lib.getExe pkgs.ruff} format "$@"
''
"--" # this argument is ignored by bash
];
includes = [ "*.py" ];
};
# FIXME: currently broken in CI # FIXME: currently broken in CI
#treefmt.settings.formatter.vale = #treefmt.settings.formatter.vale =
# let # let

View File

@@ -1,3 +1,4 @@
# shellcheck shell=bash
source_up source_up
watch_file flake-module.nix watch_file flake-module.nix

View File

@@ -27,107 +27,127 @@ rec {
# Examples: # Examples:
# writeBash = makeScriptWriter { interpreter = "${pkgs.bash}/bin/bash"; } # writeBash = makeScriptWriter { interpreter = "${pkgs.bash}/bin/bash"; }
# makeScriptWriter { interpreter = "${pkgs.dash}/bin/dash"; } "hello" "echo hello world" # makeScriptWriter { interpreter = "${pkgs.dash}/bin/dash"; } "hello" "echo hello world"
makeScriptWriter = { interpreter, check ? "", makeWrapperArgs ? [], }: nameOrPath: content: makeScriptWriter =
assert lib.or (types.path.check nameOrPath) (builtins.match "([0-9A-Za-z._])[0-9A-Za-z._-]*" nameOrPath != null); {
interpreter,
check ? "",
makeWrapperArgs ? [ ],
}:
nameOrPath: content:
assert lib.or (types.path.check nameOrPath) (
builtins.match "([0-9A-Za-z._])[0-9A-Za-z._-]*" nameOrPath != null
);
assert lib.or (types.path.check content) (types.str.check content); assert lib.or (types.path.check content) (types.str.check content);
let let
name = last (builtins.split "/" nameOrPath); name = last (builtins.split "/" nameOrPath);
in in
pkgs.runCommandLocal name ( pkgs.runCommandLocal name
{ (
inherit makeWrapperArgs; {
nativeBuildInputs = [ inherit makeWrapperArgs;
makeWrapper nativeBuildInputs = [ makeWrapper ];
];
}
// lib.optionalAttrs (nameOrPath == "/bin/${name}") {
meta.mainProgram = name;
}
// (
if (types.str.check content) then {
inherit content interpreter;
passAsFile = [ "content" ];
} else {
inherit interpreter;
contentPath = content;
} }
// lib.optionalAttrs (nameOrPath == "/bin/${name}") { meta.mainProgram = name; }
// (
if (types.str.check content) then
{
inherit content interpreter;
passAsFile = [ "content" ];
}
else
{
inherit interpreter;
contentPath = content;
}
)
) )
) ''
'' # On darwin a script cannot be used as an interpreter in a shebang but
# On darwin a script cannot be used as an interpreter in a shebang but # there doesn't seem to be a limit to the size of shebang and multiple
# there doesn't seem to be a limit to the size of shebang and multiple # arguments to the interpreter are allowed.
# arguments to the interpreter are allowed. if [[ -n "${toString pkgs.stdenvNoCC.isDarwin}" ]] && isScript $interpreter
if [[ -n "${toString pkgs.stdenvNoCC.isDarwin}" ]] && isScript $interpreter
then
wrapperInterpreterLine=$(head -1 "$interpreter" | tail -c+3)
# Get first word from the line (note: xargs echo remove leading spaces)
wrapperInterpreter=$(echo "$wrapperInterpreterLine" | xargs echo | cut -d " " -f1)
if isScript $wrapperInterpreter
then then
echo "error: passed interpreter ($interpreter) is a script which has another script ($wrapperInterpreter) as an interpreter, which is not supported." wrapperInterpreterLine=$(head -1 "$interpreter" | tail -c+3)
exit 1 # Get first word from the line (note: xargs echo remove leading spaces)
wrapperInterpreter=$(echo "$wrapperInterpreterLine" | xargs echo | cut -d " " -f1)
if isScript $wrapperInterpreter
then
echo "error: passed interpreter ($interpreter) is a script which has another script ($wrapperInterpreter) as an interpreter, which is not supported."
exit 1
fi
# This should work as long as wrapperInterpreter is a shell, which is
# the case for programs wrapped with makeWrapper, like
# python3.withPackages etc.
interpreterLine="$wrapperInterpreterLine $interpreter"
else
interpreterLine=$interpreter
fi fi
# This should work as long as wrapperInterpreter is a shell, which is echo "#! $interpreterLine" > $out
# the case for programs wrapped with makeWrapper, like cat "$contentPath" >> $out
# python3.withPackages etc. ${optionalString (check != "") ''
interpreterLine="$wrapperInterpreterLine $interpreter" ${check} $out
else ''}
interpreterLine=$interpreter chmod +x $out
fi
echo "#! $interpreterLine" > $out # Relocate executable if path was specified instead of name.
cat "$contentPath" >> $out # Only in this case wrapProgram is applied, as it wouldn't work with a
${optionalString (check != "") '' # single executable file under $out.
${check} $out ${optionalString (types.path.check nameOrPath) ''
''} mv $out tmp
chmod +x $out mkdir -p $out/$(dirname "${nameOrPath}")
mv tmp $out/${nameOrPath}
# Relocate executable if path was specified instead of name. wrapProgram $out/${nameOrPath} ''${makeWrapperArgs[@]}
# Only in this case wrapProgram is applied, as it wouldn't work with a ''}
# single executable file under $out. '';
${optionalString (types.path.check nameOrPath) ''
mv $out tmp
mkdir -p $out/$(dirname "${nameOrPath}")
mv tmp $out/${nameOrPath}
wrapProgram $out/${nameOrPath} ''${makeWrapperArgs[@]}
''}
'';
# Base implementation for compiled executables. # Base implementation for compiled executables.
# Takes a compile script, which in turn takes the name as an argument. # Takes a compile script, which in turn takes the name as an argument.
# #
# Examples: # Examples:
# writeSimpleC = makeBinWriter { compileScript = name: "gcc -o $out $contentPath"; } # writeSimpleC = makeBinWriter { compileScript = name: "gcc -o $out $contentPath"; }
makeBinWriter = { compileScript, strip ? true }: nameOrPath: content: makeBinWriter =
assert lib.or (types.path.check nameOrPath) (builtins.match "([0-9A-Za-z._])[0-9A-Za-z._-]*" nameOrPath != null); {
compileScript,
strip ? true,
}:
nameOrPath: content:
assert lib.or (types.path.check nameOrPath) (
builtins.match "([0-9A-Za-z._])[0-9A-Za-z._-]*" nameOrPath != null
);
assert lib.or (types.path.check content) (types.str.check content); assert lib.or (types.path.check content) (types.str.check content);
let let
name = last (builtins.split "/" nameOrPath); name = last (builtins.split "/" nameOrPath);
in in
pkgs.runCommand name ((if (types.str.check content) then { pkgs.runCommand name
inherit content; (
passAsFile = [ "content" ]; (
} else { if (types.str.check content) then
contentPath = content; {
}) // lib.optionalAttrs (nameOrPath == "/bin/${name}") { inherit content;
meta.mainProgram = name; passAsFile = [ "content" ];
}) '' }
${compileScript} else
${lib.optionalString strip { contentPath = content; }
"${lib.getBin buildPackages.bintools-unwrapped}/bin/${buildPackages.bintools-unwrapped.targetPrefix}strip -S $out"} )
# Sometimes binaries produced for darwin (e. g. by GHC) won't be valid // lib.optionalAttrs (nameOrPath == "/bin/${name}") { meta.mainProgram = name; }
# mach-o executables from the get-go, but need to be corrected somehow )
# which is done by fixupPhase. ''
${lib.optionalString pkgs.stdenvNoCC.hostPlatform.isDarwin "fixupPhase"} ${compileScript}
${optionalString (types.path.check nameOrPath) '' ${lib.optionalString strip "${lib.getBin buildPackages.bintools-unwrapped}/bin/${buildPackages.bintools-unwrapped.targetPrefix}strip -S $out"}
mv $out tmp # Sometimes binaries produced for darwin (e. g. by GHC) won't be valid
mkdir -p $out/$(dirname "${nameOrPath}") # mach-o executables from the get-go, but need to be corrected somehow
mv tmp $out/${nameOrPath} # which is done by fixupPhase.
''} ${lib.optionalString pkgs.stdenvNoCC.hostPlatform.isDarwin "fixupPhase"}
''; ${optionalString (types.path.check nameOrPath) ''
mv $out tmp
mkdir -p $out/$(dirname "${nameOrPath}")
mv tmp $out/${nameOrPath}
''}
'';
# Like writeScript but the first line is a shebang to bash # Like writeScript but the first line is a shebang to bash
# #
@@ -135,13 +155,10 @@ rec {
# writeBash "example" '' # writeBash "example" ''
# echo hello world # echo hello world
# '' # ''
writeBash = makeScriptWriter { writeBash = makeScriptWriter { interpreter = "${lib.getExe pkgs.bash}"; };
interpreter = "${lib.getExe pkgs.bash}";
};
# Like writeScriptBin but the first line is a shebang to bash # Like writeScriptBin but the first line is a shebang to bash
writeBashBin = name: writeBashBin = name: writeBash "/bin/${name}";
writeBash "/bin/${name}";
# Like writeScript but the first line is a shebang to dash # Like writeScript but the first line is a shebang to dash
# #
@@ -149,13 +166,10 @@ rec {
# writeDash "example" '' # writeDash "example" ''
# echo hello world # echo hello world
# '' # ''
writeDash = makeScriptWriter { writeDash = makeScriptWriter { interpreter = "${lib.getExe pkgs.dash}"; };
interpreter = "${lib.getExe pkgs.dash}";
};
# Like writeScriptBin but the first line is a shebang to dash # Like writeScriptBin but the first line is a shebang to dash
writeDashBin = name: writeDashBin = name: writeDash "/bin/${name}";
writeDash "/bin/${name}";
# Like writeScript but the first line is a shebang to fish # Like writeScript but the first line is a shebang to fish
# #
@@ -165,12 +179,11 @@ rec {
# '' # ''
writeFish = makeScriptWriter { writeFish = makeScriptWriter {
interpreter = "${lib.getExe pkgs.fish} --no-config"; interpreter = "${lib.getExe pkgs.fish} --no-config";
check = "${lib.getExe pkgs.fish} --no-config --no-execute"; # syntax check only check = "${lib.getExe pkgs.fish} --no-config --no-execute"; # syntax check only
}; };
# Like writeScriptBin but the first line is a shebang to fish # Like writeScriptBin but the first line is a shebang to fish
writeFishBin = name: writeFishBin = name: writeFish "/bin/${name}";
writeFish "/bin/${name}";
# writeHaskell takes a name, an attrset with libraries and haskell version (both optional) # writeHaskell takes a name, an attrset with libraries and haskell version (both optional)
# and some haskell source code and returns an executable. # and some haskell source code and returns an executable.
@@ -181,29 +194,31 @@ rec {
# #
# main = launchMissiles # main = launchMissiles
# ''; # '';
writeHaskell = name: { writeHaskell =
libraries ? [], name:
ghc ? pkgs.ghc, {
ghcArgs ? [], libraries ? [ ],
threadedRuntime ? true, ghc ? pkgs.ghc,
strip ? true ghcArgs ? [ ],
}: threadedRuntime ? true,
strip ? true,
}:
let let
appendIfNotSet = el: list: if elem el list then list else list ++ [ el ]; appendIfNotSet = el: list: if elem el list then list else list ++ [ el ];
ghcArgs' = if threadedRuntime then appendIfNotSet "-threaded" ghcArgs else ghcArgs; ghcArgs' = if threadedRuntime then appendIfNotSet "-threaded" ghcArgs else ghcArgs;
in makeBinWriter { in
makeBinWriter {
compileScript = '' compileScript = ''
cp $contentPath tmp.hs 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 mv tmp $out
''; '';
inherit strip; inherit strip;
} name; } name;
# writeHaskellBin takes the same arguments as writeHaskell but outputs a directory (like writeScriptBin) # writeHaskellBin takes the same arguments as writeHaskell but outputs a directory (like writeScriptBin)
writeHaskellBin = name: writeHaskellBin = name: writeHaskell "/bin/${name}";
writeHaskell "/bin/${name}";
# Like writeScript but the first line is a shebang to nu # Like writeScript but the first line is a shebang to nu
# #
@@ -211,30 +226,30 @@ rec {
# writeNu "example" '' # writeNu "example" ''
# echo hello world # echo hello world
# '' # ''
writeNu = makeScriptWriter { writeNu = makeScriptWriter { interpreter = "${lib.getExe pkgs.nushell} --no-config-file"; };
interpreter = "${lib.getExe pkgs.nushell} --no-config-file";
};
# Like writeScriptBin but the first line is a shebang to nu # Like writeScriptBin but the first line is a shebang to nu
writeNuBin = name: writeNuBin = name: writeNu "/bin/${name}";
writeNu "/bin/${name}";
# makeRubyWriter takes ruby and compatible rubyPackages and produces ruby script writer, # 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. # If any libraries are specified, ruby.withPackages is used as interpreter, otherwise the "bare" ruby is used.
makeRubyWriter = ruby: rubyPackages: buildRubyPackages: name: { libraries ? [], ... } @ args: makeRubyWriter =
makeScriptWriter ( ruby: _rubyPackages: _buildRubyPackages: name:
(builtins.removeAttrs args ["libraries"]) {
// { libraries ? [ ],
interpreter = ...
if libraries == [] }@args:
then "${ruby}/bin/ruby" makeScriptWriter (
else "${(ruby.withPackages (ps: libraries))}/bin/ruby"; (builtins.removeAttrs args [ "libraries" ])
# Rubocop doesnt seem to like running in this fashion. // {
#check = (writeDash "rubocop.sh" '' interpreter =
# exec ${lib.getExe buildRubyPackages.rubocop} "$1" 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" ''
) name; # exec ${lib.getExe buildRubyPackages.rubocop} "$1"
#'');
}
) name;
# Like writeScript but the first line is a shebang to ruby # Like writeScript but the first line is a shebang to ruby
# #
@@ -244,26 +259,29 @@ rec {
# '' # ''
writeRuby = makeRubyWriter pkgs.ruby pkgs.rubyPackages buildPackages.rubyPackages; writeRuby = makeRubyWriter pkgs.ruby pkgs.rubyPackages buildPackages.rubyPackages;
writeRubyBin = name: writeRubyBin = name: writeRuby "/bin/${name}";
writeRuby "/bin/${name}";
# makeLuaWriter takes lua and compatible luaPackages and produces lua script writer, # 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, # 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. # lua.withPackages is used as interpreter, otherwise the "bare" lua is used.
makeLuaWriter = lua: luaPackages: buildLuaPackages: name: { libraries ? [], ... } @ args: makeLuaWriter =
makeScriptWriter ( lua: _luaPackages: buildLuaPackages: name:
(builtins.removeAttrs args ["libraries"]) { ... }@args:
// { makeScriptWriter (
interpreter = lua.interpreter; (builtins.removeAttrs args [ "libraries" ])
// {
interpreter = lua.interpreter;
# if libraries == [] # if libraries == []
# then lua.interpreter # then lua.interpreter
# else (lua.withPackages (ps: libraries)).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. # This should support packages! I just cant figure out why some dependency collision happens whenever I try to run this.
check = (writeDash "luacheck.sh" '' check = (
exec ${buildLuaPackages.luacheck}/bin/luacheck "$1" writeDash "luacheck.sh" ''
''); exec ${buildLuaPackages.luacheck}/bin/luacheck "$1"
} ''
) name; );
}
) name;
# writeLua takes a name an attributeset with libraries and some lua source code and # writeLua takes a name an attributeset with libraries and some lua source code and
# returns an executable (should also work with luajit) # returns an executable (should also work with luajit)
@@ -287,27 +305,27 @@ rec {
# '' # ''
writeLua = makeLuaWriter pkgs.lua pkgs.luaPackages buildPackages.luaPackages; writeLua = makeLuaWriter pkgs.lua pkgs.luaPackages buildPackages.luaPackages;
writeLuaBin = name: writeLuaBin = name: writeLua "/bin/${name}";
writeLua "/bin/${name}";
writeRust = name: { writeRust =
name:
{
rustc ? pkgs.rustc, rustc ? pkgs.rustc,
rustcArgs ? [], rustcArgs ? [ ],
strip ? true strip ? true,
}: }:
let let
darwinArgs = lib.optionals stdenv.isDarwin [ "-L${lib.getLib libiconv}/lib" ]; darwinArgs = lib.optionals stdenv.isDarwin [ "-L${lib.getLib libiconv}/lib" ];
in in
makeBinWriter { makeBinWriter {
compileScript = '' compileScript = ''
cp "$contentPath" tmp.rs cp "$contentPath" tmp.rs
PATH=${lib.makeBinPath [pkgs.gcc]} ${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; inherit strip;
} name; } name;
writeRustBin = name: writeRustBin = name: writeRust "/bin/${name}";
writeRust "/bin/${name}";
# writeJS takes a name an attributeset with libraries and some JavaScript sourcecode and # writeJS takes a name an attributeset with libraries and some JavaScript sourcecode and
# returns an executable # returns an executable
@@ -319,23 +337,26 @@ rec {
# var result = UglifyJS.minify(code); # var result = UglifyJS.minify(code);
# console.log(result.code); # console.log(result.code);
# '' # ''
writeJS = name: { libraries ? [] }: content: writeJS =
let name:
node-env = pkgs.buildEnv { {
name = "node"; libraries ? [ ],
paths = libraries; }:
pathsToLink = [ content:
"/lib/node_modules" let
]; node-env = pkgs.buildEnv {
}; name = "node";
in writeDash name '' paths = libraries;
export NODE_PATH=${node-env}/lib/node_modules pathsToLink = [ "/lib/node_modules" ];
exec ${lib.getExe pkgs.nodejs} ${pkgs.writeText "js" content} "$@" };
''; in
writeDash name ''
export NODE_PATH=${node-env}/lib/node_modules
exec ${lib.getExe pkgs.nodejs} ${pkgs.writeText "js" content} "$@"
'';
# writeJSBin takes the same arguments as writeJS but outputs a directory (like writeScriptBin) # writeJSBin takes the same arguments as writeJS but outputs a directory (like writeScriptBin)
writeJSBin = name: writeJSBin = name: writeJS "/bin/${name}";
writeJS "/bin/${name}";
awkFormatNginx = builtins.toFile "awkFormat-nginx.awk" '' awkFormatNginx = builtins.toFile "awkFormat-nginx.awk" ''
awk -f awk -f
@@ -343,18 +364,22 @@ rec {
/\{/{ctx++;idx=1} /\{/{ctx++;idx=1}
/\}/{ctx--} /\}/{ctx--}
{id="";for(i=idx;i<ctx;i++)id=sprintf("%s%s", id, "\t");printf "%s%s\n", id, $0} {id="";for(i=idx;i<ctx;i++)id=sprintf("%s%s", id, "\t");printf "%s%s\n", id, $0}
'';
writeNginxConfig = name: text: pkgs.runCommandLocal name {
inherit text;
passAsFile = [ "text" ];
nativeBuildInputs = [ gixy ];
} /* sh */ ''
# nginx-config-formatter has an error - https://github.com/1connect/nginx-config-formatter/issues/16
awk -f ${awkFormatNginx} "$textPath" | sed '/^\s*$/d' > $out
gixy $out
''; '';
writeNginxConfig =
name: text:
pkgs.runCommandLocal name
{
inherit text;
passAsFile = [ "text" ];
nativeBuildInputs = [ gixy ];
} # sh
''
# nginx-config-formatter has an error - https://github.com/1connect/nginx-config-formatter/issues/16
awk -f ${awkFormatNginx} "$textPath" | sed '/^\s*$/d' > $out
gixy $out
'';
# writePerl takes a name an attributeset with libraries and some perl sourcecode and # writePerl takes a name an attributeset with libraries and some perl sourcecode and
# returns an executable # returns an executable
# #
@@ -363,42 +388,55 @@ rec {
# use boolean; # use boolean;
# print "Howdy!\n" if true; # print "Howdy!\n" if true;
# '' # ''
writePerl = name: { libraries ? [], ... } @ args: writePerl =
name:
{
libraries ? [ ],
...
}@args:
makeScriptWriter ( makeScriptWriter (
(builtins.removeAttrs args ["libraries"]) (builtins.removeAttrs args [ "libraries" ])
// { // {
interpreter = "${lib.getExe (pkgs.perl.withPackages (p: libraries))}"; interpreter = "${lib.getExe (pkgs.perl.withPackages (_p: libraries))}";
} }
) name; ) name;
# writePerlBin takes the same arguments as writePerl but outputs a directory (like writeScriptBin) # writePerlBin takes the same arguments as writePerl but outputs a directory (like writeScriptBin)
writePerlBin = name: writePerlBin = name: writePerl "/bin/${name}";
writePerl "/bin/${name}";
# makePythonWriter takes python and compatible pythonPackages and produces python script writer, # makePythonWriter takes python and compatible pythonPackages and produces python script writer,
# which validates the script with flake8 at build time. If any libraries are specified, # which validates the script with flake8 at build time. If any libraries are specified,
# python.withPackages is used as interpreter, otherwise the "bare" python is used. # python.withPackages is used as interpreter, otherwise the "bare" python is used.
makePythonWriter = python: pythonPackages: buildPythonPackages: name: { libraries ? [], flakeIgnore ? [], ... } @ args: makePythonWriter =
let python: pythonPackages: buildPythonPackages: name:
ignoreAttribute = optionalString (flakeIgnore != []) "--ignore ${concatMapStringsSep "," escapeShellArg flakeIgnore}"; {
in libraries ? [ ],
makeScriptWriter flakeIgnore ? [ ],
( ...
(builtins.removeAttrs args ["libraries" "flakeIgnore"]) }@args:
let
ignoreAttribute =
optionalString (flakeIgnore != [ ])
"--ignore ${concatMapStringsSep "," escapeShellArg flakeIgnore}";
in
makeScriptWriter (
(builtins.removeAttrs args [
"libraries"
"flakeIgnore"
])
// { // {
interpreter = interpreter =
if pythonPackages != pkgs.pypy2Packages || pythonPackages != pkgs.pypy3Packages then if pythonPackages != pkgs.pypy2Packages || pythonPackages != pkgs.pypy3Packages then
if libraries == [] if libraries == [ ] then python.interpreter else (python.withPackages (_ps: libraries)).interpreter
then python.interpreter else
else (python.withPackages (ps: libraries)).interpreter python.interpreter;
else python.interpreter check = optionalString python.isPy3k (
; writeDash "pythoncheck.sh" ''
check = optionalString python.isPy3k (writeDash "pythoncheck.sh" '' exec ${buildPythonPackages.flake8}/bin/flake8 --show-source ${ignoreAttribute} "$1"
exec ${buildPythonPackages.flake8}/bin/flake8 --show-source ${ignoreAttribute} "$1" ''
''); );
} }
) ) name;
name;
# writePyPy2 takes a name an attributeset with libraries and some pypy2 sourcecode and # writePyPy2 takes a name an attributeset with libraries and some pypy2 sourcecode and
# returns an executable # returns an executable
@@ -415,8 +453,7 @@ rec {
writePyPy2 = makePythonWriter pkgs.pypy2 pkgs.pypy2Packages buildPackages.pypy2Packages; writePyPy2 = makePythonWriter pkgs.pypy2 pkgs.pypy2Packages buildPackages.pypy2Packages;
# writePyPy2Bin takes the same arguments as writePyPy2 but outputs a directory (like writeScriptBin) # writePyPy2Bin takes the same arguments as writePyPy2 but outputs a directory (like writeScriptBin)
writePyPy2Bin = name: writePyPy2Bin = name: writePyPy2 "/bin/${name}";
writePyPy2 "/bin/${name}";
# writePython3 takes a name an attributeset with libraries and some python3 sourcecode and # writePython3 takes a name an attributeset with libraries and some python3 sourcecode and
# returns an executable # returns an executable
@@ -433,8 +470,7 @@ rec {
writePython3 = makePythonWriter pkgs.python3 pkgs.python3Packages buildPackages.python3Packages; writePython3 = makePythonWriter pkgs.python3 pkgs.python3Packages buildPackages.python3Packages;
# writePython3Bin takes the same arguments as writePython3 but outputs a directory (like writeScriptBin) # writePython3Bin takes the same arguments as writePython3 but outputs a directory (like writeScriptBin)
writePython3Bin = name: writePython3Bin = name: writePython3 "/bin/${name}";
writePython3 "/bin/${name}";
# writePyPy3 takes a name an attributeset with libraries and some pypy3 sourcecode and # writePyPy3 takes a name an attributeset with libraries and some pypy3 sourcecode and
# returns an executable # returns an executable
@@ -451,47 +487,61 @@ rec {
writePyPy3 = makePythonWriter pkgs.pypy3 pkgs.pypy3Packages buildPackages.pypy3Packages; writePyPy3 = makePythonWriter pkgs.pypy3 pkgs.pypy3Packages buildPackages.pypy3Packages;
# writePyPy3Bin takes the same arguments as writePyPy3 but outputs a directory (like writeScriptBin) # writePyPy3Bin takes the same arguments as writePyPy3 but outputs a directory (like writeScriptBin)
writePyPy3Bin = name: writePyPy3Bin = name: writePyPy3 "/bin/${name}";
writePyPy3 "/bin/${name}";
makeFSharpWriter =
{
dotnet-sdk ? pkgs.dotnet-sdk,
fsi-flags ? "",
libraries ? _: [ ],
...
}@args:
nameOrPath:
let
fname = last (builtins.split "/" nameOrPath);
path = if strings.hasSuffix ".fsx" nameOrPath then nameOrPath else "${nameOrPath}.fsx";
_nugetDeps = mkNugetDeps {
name = "${fname}-nuget-deps";
nugetDeps = libraries;
};
makeFSharpWriter = { dotnet-sdk ? pkgs.dotnet-sdk, fsi-flags ? "", libraries ? _: [], ... } @ args: nameOrPath: nuget-source = mkNugetSource {
let name = "${fname}-nuget-source";
fname = last (builtins.split "/" nameOrPath); description = "A Nuget source with the dependencies for ${fname}";
path = if strings.hasSuffix ".fsx" nameOrPath then nameOrPath else "${nameOrPath}.fsx"; deps = [ _nugetDeps ];
_nugetDeps = mkNugetDeps { name = "${fname}-nuget-deps"; nugetDeps = libraries; }; };
nuget-source = mkNugetSource { fsi = writeBash "fsi" ''
name = "${fname}-nuget-source"; export HOME=$NIX_BUILD_TOP/.home
description = "A Nuget source with the dependencies for ${fname}"; export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
deps = [ _nugetDeps ]; export DOTNET_CLI_TELEMETRY_OPTOUT=1
}; export DOTNET_NOLOGO=1
script="$1"; shift
${lib.getExe dotnet-sdk} fsi --quiet --nologo --readline- ${fsi-flags} "$@" < "$script"
'';
fsi = writeBash "fsi" '' in
export HOME=$NIX_BUILD_TOP/.home content:
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 makeScriptWriter
export DOTNET_CLI_TELEMETRY_OPTOUT=1 (
export DOTNET_NOLOGO=1 (builtins.removeAttrs args [
script="$1"; shift "dotnet-sdk"
${lib.getExe dotnet-sdk} fsi --quiet --nologo --readline- ${fsi-flags} "$@" < "$script" "fsi-flags"
''; "libraries"
])
// {
interpreter = fsi;
}
)
path
''
#i "nuget: ${nuget-source}/lib"
${content}
exit 0
'';
in content: makeScriptWriter ( writeFSharp = makeFSharpWriter { };
(builtins.removeAttrs args ["dotnet-sdk" "fsi-flags" "libraries"])
// {
interpreter = fsi;
}
) path
''
#i "nuget: ${nuget-source}/lib"
${ content }
exit 0
'';
writeFSharp = writeFSharpBin = name: writeFSharp "/bin/${name}";
makeFSharpWriter {};
writeFSharpBin = name:
writeFSharp "/bin/${name}";
} }

View File

@@ -1,3 +1,4 @@
# shellcheck shell=bash
source_up source_up
watch_file flake-module.nix shell.nix default.nix watch_file flake-module.nix shell.nix default.nix

View File

@@ -6,7 +6,7 @@
pygobject3, pygobject3,
wrapGAppsHook, wrapGAppsHook,
gtk4, gtk4,
gnome, adwaita-icon-theme,
pygobject-stubs, pygobject-stubs,
gobject-introspection, gobject-introspection,
clan-cli, clan-cli,
@@ -39,7 +39,7 @@ let
gtk4 gtk4
libadwaita libadwaita
webkitgtk_6_0 webkitgtk_6_0
gnome.adwaita-icon-theme adwaita-icon-theme
]; ];
# Deps including python packages from the local project # Deps including python packages from the local project

View File

@@ -1,3 +1,4 @@
# shellcheck shell=bash
source_up source_up
watch_file flake-module.nix shell.nix default.nix watch_file flake-module.nix shell.nix default.nix

View File

@@ -81,11 +81,11 @@ def cast(value: Any, input_type: Any, opt_description: str) -> Any:
else: else:
raise ClanError(f"Invalid value {value} for boolean") raise ClanError(f"Invalid value {value} for boolean")
# handle lists # handle lists
elif get_origin(input_type) == list: elif get_origin(input_type) is list:
subtype = input_type.__args__[0] subtype = input_type.__args__[0]
return [cast([x], subtype, opt_description) for x in value] return [cast([x], subtype, opt_description) for x in value]
# handle dicts # handle dicts
elif get_origin(input_type) == dict: elif get_origin(input_type) is dict:
if not isinstance(value, dict): if not isinstance(value, dict):
raise ClanError( raise ClanError(
f"Cannot set {opt_description} directly. Specify a suboption like {opt_description}.<name>" f"Cannot set {opt_description} directly. Specify a suboption like {opt_description}.<name>"

View File

@@ -108,7 +108,7 @@ def test_type_from_schema_path_simple() -> None:
schema = dict( schema = dict(
type="boolean", type="boolean",
) )
assert parsing.type_from_schema_path(schema, []) == bool assert parsing.type_from_schema_path(schema, []) is bool
def test_type_from_schema_path_nested() -> None: def test_type_from_schema_path_nested() -> None:
@@ -125,8 +125,8 @@ def test_type_from_schema_path_nested() -> None:
age=dict(type="integer"), age=dict(type="integer"),
), ),
) )
assert parsing.type_from_schema_path(schema, ["age"]) == int assert parsing.type_from_schema_path(schema, ["age"]) is int
assert parsing.type_from_schema_path(schema, ["name", "first"]) == str assert parsing.type_from_schema_path(schema, ["name", "first"]) is str
def test_type_from_schema_path_dynamic_attrs() -> None: def test_type_from_schema_path_dynamic_attrs() -> None:
@@ -140,16 +140,16 @@ def test_type_from_schema_path_dynamic_attrs() -> None:
), ),
), ),
) )
assert parsing.type_from_schema_path(schema, ["age"]) == int assert parsing.type_from_schema_path(schema, ["age"]) is int
assert parsing.type_from_schema_path(schema, ["users", "foo"]) == str assert parsing.type_from_schema_path(schema, ["users", "foo"]) is str
def test_map_type() -> None: def test_map_type() -> None:
with pytest.raises(ClanError): with pytest.raises(ClanError):
config.map_type("foo") config.map_type("foo")
assert config.map_type("string") == str assert config.map_type("string") is str
assert config.map_type("integer") == int assert config.map_type("integer") is int
assert config.map_type("boolean") == bool assert config.map_type("boolean") is bool
assert config.map_type("attribute set of string") == dict[str, str] assert config.map_type("attribute set of string") == dict[str, str]
assert config.map_type("attribute set of integer") == dict[str, int] assert config.map_type("attribute set of integer") == dict[str, int]
assert config.map_type("null or string") == str | None assert config.map_type("null or string") == str | None

View File

@@ -19,29 +19,6 @@ let
}; };
}; };
}; };
installerModule =
{ config, modulesPath, ... }:
{
imports = [
wifiModule
self.nixosModules.installer
self.inputs.nixos-generators.nixosModules.all-formats
(modulesPath + "/installer/cd-dvd/iso-image.nix")
];
isoImage.squashfsCompression = "zstd";
system.stateVersion = config.system.nixos.version;
nixpkgs.pkgs = self.inputs.nixpkgs.legacyPackages.x86_64-linux;
};
installerSystem = lib.nixosSystem {
modules = [
self.inputs.disko.nixosModules.default
installerModule
{ disko.memSize = 4096; } # FIXME: otherwise the image builder goes OOM
];
};
flashInstallerModule = flashInstallerModule =
{ config, ... }: { config, ... }:
@@ -98,14 +75,6 @@ let
in in
{ {
clan = { clan = {
# To build a generic installer image (without ssh pubkeys),
# use the following command:
# $ nix build .#iso-installer
machines.iso-installer = {
imports = [ installerModule ];
fileSystems."/".device = lib.mkDefault "/dev/null";
};
# To directly flash the installer to a disk, use the following command: # To directly flash the installer to a disk, use the following command:
# $ clan flash flash-installer --disk main /dev/sdX --yes # $ clan flash flash-installer --disk main /dev/sdX --yes
# This will include your ssh public keys in the installer. # This will include your ssh public keys in the installer.
@@ -114,7 +83,4 @@ in
boot.loader.grub.enable = lib.mkDefault true; boot.loader.grub.enable = lib.mkDefault true;
}; };
}; };
flake.packages.x86_64-linux.iso-installer = installerSystem.config.formats.iso;
flake.apps.x86_64-linux.install-vm.program = installerSystem.config.formats.vm.outPath;
flake.apps.x86_64-linux.install-vm-nogui.program = installerSystem.config.formats.vm-nogui.outPath;
} }

View File

@@ -1,3 +1,4 @@
# shellcheck shell=bash
source_up source_up
watch_file flake-module.nix default.nix watch_file flake-module.nix default.nix