4 ms·
> 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 define
by eeh 6y ago
> 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.
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.
- xena 6y agoDo you have a more detailed example of this?
- elbear 6y agoI assume they're talking about the same process you can use to pin nixpkgs. Have a nixpkgs.json with contents like these { "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 nixpkgs
- eeh 6y agoAs an example, I have a program for regularly backing up directories to cloud storage (with deduplication, encryption, key management, etc. it's just a wrapper around Restic), which it does regularly via cron. I manage this in NixOS: different machines backup different directories, with different keys. 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, ...)
- carapace 6y agoGreat, but you're making the OP's point: > 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?
- eeh 6y agoI agree with OP's first point that Nix language being new may hurt its success. 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.