srid / neuron

Future-proof note-taking and publishing based on Zettelkasten (superseded by Emanote: https://github.com/srid/emanote)
https://neuron.zettel.page
GNU Affero General Public License v3.0
1.52k stars 150 forks source link

flake.nix: add basic support #594

Closed TheKK closed 3 years ago

TheKK commented 3 years ago

This should solve #485.

With this flake.nix, we can do...

I also add result-data to .gitignore since it was created after running nix build. This make you to run nix-build to build same derivation after nix build.

If there's anything I can improve, please let me know!

TheKK commented 3 years ago

Do you think that I should modify github workflow in this PR? Just notice that.

srid commented 3 years ago

@TheKK I took a quick look and added some comments, thanks for your PR! Yes, CI should be updated.

Note that I think we should probably migrate entirely to flakes, and then use edolstra/flake-compat to provide a default.nix and shell.nix that uses flake.nix (see here for how I do it). Although it would be good to do that in this PR, it is fine if that happens outside of it - as "stage 2". At minimum, however, we should normalize the nixpkgs pinning in one place, as it is easy to forget updating it in both locations.

TheKK commented 3 years ago

Should we create a directory like dep and put dependencies from inputs of flake.nix into it?

I found that I have to repeat

    let lock = builtins.fromJSON (builtins.readFile ./flake.lock);
    in fetchTarball {
        url = "https://github.com/nixos/nixpkgs/archive/${lock.nodes.nixpkgs.locked.rev}.tar.gz";
        sha256 = lock.nodes.nixpkgs.locked.narHash;
      };

for all

import ./dep/nixpkgs {...}

which appears too many times. Or is there other preferential way to prevent these repetitions?

srid commented 3 years ago

You should be able to pass the inputs from flake.nix to project.nix, no?

TheKK commented 3 years ago

For default.nix and shell.nix, yes we can. But there are other users of dep/nixpkgs like ci.nix and static.nix, which can not (easily) derive from flake.nix.

The restriction here is that flake-compat only exposes defaultPackage and devShell from flake.nix.

srid commented 3 years ago

Don't worry about static.nix; that's already broken.

ci.nix should work, but it only requires pkg (for recurseIntoAttrs), so you can pass that easily? Don't worry about repetition; if we can get something working first, it can be refactored near the end.

TheKK commented 3 years ago

Please let me know if there's anything I can improve :)

TheKK commented 3 years ago

Thanks for your advice!

I've merged fixes you mentioned in the comment and rebase this PR onto 602c3de9d61ed9f1277bc2fc0ec01ca912f395df. Please take a look.