by IshKebab · 6y ago · 0 comments
Same for the script parameters. I have absolutely no idea what this does
{ pkgs ? import <nixpkgs> { } }:
Why not: function main(pkgs: Package = nixpkgs) {
}
Or something like that.My second issue is that the files clearly aren't machine-editable. There's no sensible way to make a GUI that can edit your hostname if the hostname is defined in some Turing complete functional program.
But it definitely beats the design of any other package manager.
As for not being machine-editable, the nix language has a module system and it's easy to format a file with something that's whatever shape you want and have that machine-editable. Or use any other format and fromJSON etc. functions.
For the times I need to do this, I define the values in a JSON file, which can be parsed by Nix's builtins.fromJSON into a Nix datatype.
> the Nix language is just so damn weird... Why didn't they use a [familiar] syntax ...
You wouldn't have to parse data from some other representation if Nix lang was less weird, eh?
I was replying to OP's second point about Nix language not being machine-editable.
Even if Nix was written in Python rather than Nix language, it still wouldn't be machine editable.
The solution in both cases is to use a simple format that is machine editable, e.g. JSON.
This program has a CLI mode for setting up keys and buckets, which I run locally, and it writes to backup-metadata.json .
So my workflow for adding a new directory to my system is:
1. Run CLI tool to create a new bucket, new API key with access to the bucket (with just the permissions it needs), and new encryption key. This writes to my backup-metadata.json file locally.
2. write some NixOS along the lines of:
let
metadata = (builtins.fromJSON "../backup-metadata.json").git;
in {
backup = {
git = {
path = "/var/lib/git-repositories";
frequency = "hourly";
bucket = metadata.bucket;
key = metadata.key;
apiKey = metadata.apiKey;
};
};
}
3. Hit deploy. This starts the backups, and some monitoring to check the cloud storage is being regularly written to.The implementation of "backup" is private, but reuses parts of upstream NixOS (systemd.timer, Prometheus, ...)
{
"url": "https://github.com/nixos/nixpkgs-channels.git",
"rev": "ea553d8c67c6a718448da50826ff5b6916dc9c59",
"date": "2020-02-02T15:39:15+01:00",
"sha256": "0g9smv36sk42rfyzi8wyq2wl11c5l0qaldij1zjdj60s57cl3wgj",
"fetchSubmodules": false
}
Then, in nixpkgs.nix have let
bootstrap = import <nixpkgs> { };
nixpkgs-pin = builtins.fromJSON (builtins.readFile ./nixpkgs.json);
nixpkgs = bootstrap.fetchFromGitHub {
owner = "NixOS";
repo = "nixpkgs";
inherit (nixpkgs-pin) rev sha256;
};
in
import nixpkgsIt's not really weird when you know a functional language like Haskell or OCaml. My experience was actually the opposite: being a functional language, Nix's syntax was so simple that it took me only a few minutes to grasp most of it.
But if you don't have some FP experience under your belt, both the syntax and commonly-used concepts are strange (e.g. fixed points).
For me the learning curve was knowing what extra functions/functionality is provided by nixpkgs, which lacks quite a lot of documentation and discoverability. I found out about a lot of handy functions and techniques while reading derivations.
I should have kept track of the issues while I was learning Nix/nixpkgs. But at that point I was still determining "do I want this?"
I don't disagree with the overall argument you are making however on this point alone, they aren't meant to be machine-editable. They are functions, they take arguments. So you can make your module or system configuration or whatever, have unassigned variables and then have your function take them as parameters. Your GUI can invoke this function with arguments from the user input.
But you also don't need to!
NixOS has a module system, with override/priority mechanics; so your GUI tool could just generate its own Nix file with its own settings, totally ignoring the system-wide settings, and then all you need to do is apply that generated configuration file in your imports; the module priority system does the rest.
It being so simple is why the whole system works.
function main(pkgs: Map String Package = (import(sys.path("nixpkgs"))({}))){ }
I'm not sure if it's better at this point...
https://github.com/NixOS/nixpkgs/blob/2cd8c35c1fdfdb773df7ec...
I am pretty sure that instantiating a derivation probably requires more attributes. But in the end they are just attribute sets (which is one of the types in Nix besides strings, lists, etc.).
What do you mean by this? Nix is a Turing-complete language.