introduce dev flake

Keep the number of exposed inputs from the top-level flake small by
splitting the development environment into its own flake.

The .envrc uses `--override-input srvos path:$PATH` so that the srvos
path always get re-calculated on reload, but not recorded. Since the
hash of srvos is stored inside of srvos, it would infinitely update
otherwise.
This commit is contained in:
zimbatm 2023-04-02 15:41:25 +02:00
parent 68d3acf104
commit e896b8f419
No known key found for this signature in database
GPG Key ID: 71BAF6D40C1D63D7
8 changed files with 143 additions and 14 deletions

1
.envrc Normal file
View File

@ -0,0 +1 @@
use flake ./dev --override-input srvos "path:$PWD"

View File

@ -35,4 +35,4 @@ jobs:
if: ${{ github.ref == 'refs/heads/main' }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: "${{ steps.build.outputs.result }}/"
publish_dir: "${{ steps.build.outputs.result }}/"

View File

@ -1,11 +1,14 @@
# This file provides backward compatibility to nix < 2.4 clients
{ system ? builtins.currentSystem }:
{ system ? builtins.currentSystem, src ? ./. }:
let
flake-compat = builtins.fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/35bb57c0c8d8b62bbfd284272c928ceb64ddbde9.tar.gz";
sha256 = "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=";
lock = builtins.fromJSON (builtins.readFile ./dev/flake.lock);
inherit (lock.nodes.flake-compat.locked) owner repo rev narHash;
flake-compat = fetchTarball {
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz";
sha256 = narHash;
};
flake = import flake-compat { src = ./.; inherit system; };
flake = import flake-compat { inherit src system; };
in
flake.defaultNix

83
dev/flake.lock Normal file
View File

@ -0,0 +1,83 @@
{
"nodes": {
"flake-compat": {
"locked": {
"lastModified": 1680466377,
"narHash": "sha256-0mh4l/e5kLCf2SL6TFzi5hDZfXlwRmiMcHnczeZNu28=",
"owner": "nix-community",
"repo": "flake-compat",
"rev": "f5aab912cd8069e882de9a5847650be52a6c28df",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "flake-compat",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1680024716,
"narHash": "sha256-f9824KWmxVBI4WLI7o6tDFfj+dW+qj6uQKo0ZRsbaZQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "49079a134fd3d3ac25d5ae1f5516f37770f19138",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable-small",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-compat": "flake-compat",
"nixpkgs": [
"srvos",
"nixpkgs"
],
"srvos": "srvos",
"treefmt-nix": "treefmt-nix"
}
},
"srvos": {
"inputs": {
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 0,
"narHash": "sha256-GysuOf3OrDRY5Sg2Y1KoRlTtWovFQkz8DNe1kcDDZ0E=",
"path": "../",
"type": "path"
},
"original": {
"path": "../",
"type": "path"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1680218481,
"narHash": "sha256-VhkSVeKXbZtdaT41Kn3QuFE7OnXHM4UbMlqBez+tRL0=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "a082287718105c284475df18b882a76312dea0d0",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

34
dev/flake.nix Normal file
View File

@ -0,0 +1,34 @@
{
description = "srvos dev flake";
inputs.srvos.url = "path:../";
inputs.nixpkgs.follows = "srvos/nixpkgs";
inputs.treefmt-nix.url = "github:numtide/treefmt-nix";
inputs.treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-compat.url = "github:nix-community/flake-compat";
outputs = { self, nixpkgs, treefmt-nix, srvos, ... }:
let
eachSystem = f:
nixpkgs.lib.genAttrs
srvos.lib.supportedSystems
(system: f nixpkgs.legacyPackages.${system});
treefmt = eachSystem (pkgs: treefmt-nix.lib.mkWrapper pkgs ./treefmt.nix);
in
{
formatter = eachSystem (pkgs: treefmt.${pkgs.system});
devShells = eachSystem (pkgs: {
default = pkgs.mkShellNoCC {
packages = [
pkgs.nixpkgs-fmt
treefmt.${pkgs.system}
];
};
});
};
}

4
dev/treefmt.nix Normal file
View File

@ -0,0 +1,4 @@
{
projectRootFile = ".git/config";
programs.nixpkgs-fmt.enable = true;
}

View File

@ -7,15 +7,17 @@
let
eachSystem = f:
nixpkgs.lib.genAttrs
[
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
]
self.lib.supportedSystems
(system: f { inherit self system; pkgs = nixpkgs.legacyPackages.${system}; });
in
{
lib.supportedSystems = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
];
packages = eachSystem ({ pkgs, ... }: {
docs = pkgs.callPackage ./docs { };
});

View File

@ -1,3 +1,5 @@
{ system ? builtins.currentSystem }:
(import ./default.nix { inherit system; }).devShells.${system}.default
or throw "dev-shell not defined. Cannot find flake attribute devShells.${system}.default"
let
d = import ./. { inherit system; src = ./dev; };
in
d.devShells.${system}.default