nix flake

This commit is contained in:
Michael Zhang 2021-08-03 16:57:42 -05:00
parent ca1cdc8179
commit 35f4faecd1
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
8 changed files with 7940 additions and 28 deletions

2
.gitignore vendored
View file

@ -1 +1,3 @@
/target /target
/result
/result-lib

7889
Cargo.nix Normal file

File diff suppressed because it is too large Load diff

3
crate-hashes.json Normal file
View file

@ -0,0 +1,3 @@
{
"typed-html 0.2.2 (git+https://github.com/bodil/typed-html?rev=d95ce1a2930f2385d4f3765d061dbeff3503107f#d95ce1a2930f2385d4f3765d061dbeff3503107f)": "0z1zprngz92yscv07vyqd0kkd8kkpr20fs7ks9c7yg9ygn8ns882"
}

View file

@ -1,12 +1,3 @@
(import { pkgs }:
(let let workspace = import ./Cargo.nix { inherit pkgs; };
lock = builtins.fromJSON (builtins.readFile ./flake.lock); in workspace.rootCrate.build.override { runTests = true; }
in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{
src = ./.;
}).defaultNix

View file

@ -3,11 +3,11 @@
"crate2nix": { "crate2nix": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1627923438, "lastModified": 1627987096,
"narHash": "sha256-/O/FDJynVXOdFhSXQGU2uH/FQF3MS93WMyeY+9fcRaU=", "narHash": "sha256-4UZmV651pao101MKoUVh3fHX8OqyoQss5mumOxbrBGk=",
"owner": "kolloch", "owner": "kolloch",
"repo": "crate2nix", "repo": "crate2nix",
"rev": "29460b5c411defa5e8e0851fe7ecbca0f0fa41d3", "rev": "0ec72d0147d51b26943d622088a13ca273d25469",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -49,11 +49,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1627978428, "lastModified": 1628027051,
"narHash": "sha256-813SF+K9wEwHVTOhgVpaC3CSZWcjap7Pv3bWppV0U44=", "narHash": "sha256-ZbtoEzVT2NV2J2tFmto2PcgdZmsdSyV3rVZBweXkbWk=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "b3ca5f904aa0f3341413f14e3bd8303a6acd39de", "rev": "1ab9b0e31da0a6de40867d457b0244c2c895b1dc",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -25,13 +25,16 @@
}) })
]; ];
}; };
inherit (import "${crate2nix}/tools.nix" { inherit pkgs; }) generatedCargoNix; project = import ./Cargo.nix { inherit pkgs; };
project = pkgs.callPackage static = pkgs.callPackage ./static.nix {};
(generatedCargoNix { inherit name; src = ./.; })
{ defaultCrateOverrides = pkgs.defaultCrateOverrides; };
buildInputs = with pkgs; [];
in rec { in rec {
packages.${name} = project.rootCrate.build; packages.${name} = pkgs.symlinkJoin {
inherit name;
paths = [
project.rootCrate.build
static
];
};
defaultPackage = packages.${name}; defaultPackage = packages.${name};
apps.${name} = utils.lib.mkApp { apps.${name} = utils.lib.mkApp {
inherit name; inherit name;

View file

@ -1,6 +1,3 @@
#![doc = include_str!("../README.md")]
#![recursion_limit = "512"]
#[macro_use] #[macro_use]
extern crate serde; extern crate serde;
#[macro_use] #[macro_use]
@ -18,6 +15,8 @@ mod render;
mod routes; mod routes;
mod views; mod views;
use std::path::PathBuf;
use clap::Clap; use clap::Clap;
use rocket::fs::{FileServer, relative}; use rocket::fs::{FileServer, relative};
@ -27,6 +26,9 @@ use crate::api::Api;
struct Opt { struct Opt {
#[clap(short = 'v', long = "verbose", parse(from_occurrences))] #[clap(short = 'v', long = "verbose", parse(from_occurrences))]
verbose: usize, verbose: usize,
#[clap(short = 'f', long = "static")]
static_file_path: Option<PathBuf>,
} }
#[get("/favicon.ico")] #[get("/favicon.ico")]
@ -41,10 +43,15 @@ fn rocket() -> _ {
// .init() // .init()
// .unwrap(); // .unwrap();
let static_file_path = match opt.static_file_path {
Some(path) => path,
None => PathBuf::from(relative!("/static")),
};
use routes::timeline; use routes::timeline;
let api = Api::new().unwrap(); let api = Api::new().unwrap();
rocket::build() rocket::build()
.mount("/static", FileServer::from(relative!("/static"))) .mount("/static", FileServer::from(static_file_path))
.mount( .mount(
"/", "/",
routes![ routes![

17
static.nix Normal file
View file

@ -0,0 +1,17 @@
{ stdenv, sassc }:
stdenv.mkDerivation {
name = "shitter-static";
buildInputs = [ sassc ];
src = ./.;
buildPhase = ''
pwd
ls -l
ls -l sass
${sassc}/bin/sassc -Isass/include sass/index.scss static/css/style.css
'';
installPhase = ''
mkdir -p $out
cp -r static $out
'';
}